diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 64f22a0874b..66bd18108f0 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include @@ -48,11 +47,11 @@ class TestPreprocessor : public TestFixture { TestPreprocessor() : TestFixture("TestPreprocessor") {} private: - std::string expandMacros(const char code[]) { - std::istringstream istr(code); + template + std::string expandMacros(const char (&code)[size]) { simplecpp::OutputList outputList; std::vector files; - const simplecpp::TokenList tokens1 = simplecpp::TokenList(istr, files, "file.cpp", &outputList); + const simplecpp::TokenList tokens1 = simplecpp::TokenList(code, size-1, files, "file.cpp", &outputList); const Settings settings; Preprocessor p(settings, *this); simplecpp::TokenList tokens2 = p.preprocess(tokens1, "", files, true); @@ -60,11 +59,11 @@ class TestPreprocessor : public TestFixture { return tokens2.stringify(); } - std::vector getRemarkComments(const char code[]) + template + std::vector getRemarkComments(const char (&code)[size]) { std::vector files{"test.cpp"}; - std::istringstream istr(code); - const simplecpp::TokenList tokens1(istr, files, files[0]); + const simplecpp::TokenList tokens1(code, size-1, files, files[0]); const Settings settings; @@ -274,7 +273,8 @@ class TestPreprocessor : public TestFixture { TEST_CASE(standard); } - std::string getConfigsStr(const char filedata[], const char *arg = nullptr) { + template + std::string getConfigsStr(const char (&code)[size], const char *arg = nullptr) { Settings settings; if (arg && std::strncmp(arg,"-D",2)==0) settings.userDefines = arg + 2; @@ -282,8 +282,7 @@ class TestPreprocessor : public TestFixture { settings.userUndefs.insert(arg+2); Preprocessor preprocessor(settings, *this); std::vector files; - std::istringstream istr(filedata); - simplecpp::TokenList tokens(istr,files); + simplecpp::TokenList tokens(code, size-1,files); tokens.removeComments(); const std::set configs = preprocessor.getConfigs(tokens); std::string ret; @@ -292,12 +291,12 @@ class TestPreprocessor : public TestFixture { return ret; } - std::size_t getHash(const char filedata[]) { + template + std::size_t getHash(const char (&code)[size]) { Settings settings; Preprocessor preprocessor(settings, *this); std::vector files; - std::istringstream istr(filedata); - simplecpp::TokenList tokens(istr,files); + simplecpp::TokenList tokens(code,size-1,files); tokens.removeComments(); return preprocessor.calculateHash(tokens, ""); } @@ -450,9 +449,8 @@ class TestPreprocessor : public TestFixture { "#else\n" "2\n" "#endif\n"; - std::istringstream istr(filedata); std::vector files; - simplecpp::TokenList tokens(istr, files, "test.c"); + simplecpp::TokenList tokens(filedata, sizeof(filedata), files, "test.c"); // preprocess code with unix32 platform.. { @@ -775,14 +773,14 @@ class TestPreprocessor : public TestFixture { } void if_macro_eq_macro() { - const char *code = "#define A B\n" - "#define B 1\n" - "#define C 1\n" - "#if A == C\n" - "Wilma\n" - "#else\n" - "Betty\n" - "#endif\n"; + const char code[] = "#define A B\n" + "#define B 1\n" + "#define C 1\n" + "#if A == C\n" + "Wilma\n" + "#else\n" + "Betty\n" + "#endif\n"; ASSERT_EQUALS("\n", getConfigsStr(code)); }