Skip to content

Commit 922432b

Browse files
committed
TestPreprocessor: removed usage of std::istringstream
1 parent 33d4de3 commit 922432b

1 file changed

Lines changed: 21 additions & 23 deletions

File tree

test/testpreprocessor.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include <list>
3636
#include <map>
3737
#include <set>
38-
#include <sstream>
3938
#include <string>
4039
#include <vector>
4140

@@ -48,23 +47,23 @@ class TestPreprocessor : public TestFixture {
4847
TestPreprocessor() : TestFixture("TestPreprocessor") {}
4948

5049
private:
51-
std::string expandMacros(const char code[]) {
52-
std::istringstream istr(code);
50+
template<size_t size>
51+
std::string expandMacros(const char (&code)[size]) {
5352
simplecpp::OutputList outputList;
5453
std::vector<std::string> files;
55-
const simplecpp::TokenList tokens1 = simplecpp::TokenList(istr, files, "file.cpp", &outputList);
54+
const simplecpp::TokenList tokens1 = simplecpp::TokenList(code, size-1, files, "file.cpp", &outputList);
5655
const Settings settings;
5756
Preprocessor p(settings, *this);
5857
simplecpp::TokenList tokens2 = p.preprocess(tokens1, "", files, true);
5958
p.reportOutput(outputList, true);
6059
return tokens2.stringify();
6160
}
6261

63-
std::vector<RemarkComment> getRemarkComments(const char code[])
62+
template<size_t size>
63+
std::vector<RemarkComment> getRemarkComments(const char (&code)[size])
6464
{
6565
std::vector<std::string> files{"test.cpp"};
66-
std::istringstream istr(code);
67-
const simplecpp::TokenList tokens1(istr, files, files[0]);
66+
const simplecpp::TokenList tokens1(code, size-1, files, files[0]);
6867

6968
const Settings settings;
7069

@@ -274,16 +273,16 @@ class TestPreprocessor : public TestFixture {
274273
TEST_CASE(standard);
275274
}
276275

277-
std::string getConfigsStr(const char filedata[], const char *arg = nullptr) {
276+
template<size_t size>
277+
std::string getConfigsStr(const char (&code)[size], const char *arg = nullptr) {
278278
Settings settings;
279279
if (arg && std::strncmp(arg,"-D",2)==0)
280280
settings.userDefines = arg + 2;
281281
if (arg && std::strncmp(arg,"-U",2)==0)
282282
settings.userUndefs.insert(arg+2);
283283
Preprocessor preprocessor(settings, *this);
284284
std::vector<std::string> files;
285-
std::istringstream istr(filedata);
286-
simplecpp::TokenList tokens(istr,files);
285+
simplecpp::TokenList tokens(code, size-1,files);
287286
tokens.removeComments();
288287
const std::set<std::string> configs = preprocessor.getConfigs(tokens);
289288
std::string ret;
@@ -292,12 +291,12 @@ class TestPreprocessor : public TestFixture {
292291
return ret;
293292
}
294293

295-
std::size_t getHash(const char filedata[]) {
294+
template<size_t size>
295+
std::size_t getHash(const char (&code)[size]) {
296296
Settings settings;
297297
Preprocessor preprocessor(settings, *this);
298298
std::vector<std::string> files;
299-
std::istringstream istr(filedata);
300-
simplecpp::TokenList tokens(istr,files);
299+
simplecpp::TokenList tokens(code,size-1,files);
301300
tokens.removeComments();
302301
return preprocessor.calculateHash(tokens, "");
303302
}
@@ -450,9 +449,8 @@ class TestPreprocessor : public TestFixture {
450449
"#else\n"
451450
"2\n"
452451
"#endif\n";
453-
std::istringstream istr(filedata);
454452
std::vector<std::string> files;
455-
simplecpp::TokenList tokens(istr, files, "test.c");
453+
simplecpp::TokenList tokens(filedata, sizeof(filedata), files, "test.c");
456454

457455
// preprocess code with unix32 platform..
458456
{
@@ -775,14 +773,14 @@ class TestPreprocessor : public TestFixture {
775773
}
776774

777775
void if_macro_eq_macro() {
778-
const char *code = "#define A B\n"
779-
"#define B 1\n"
780-
"#define C 1\n"
781-
"#if A == C\n"
782-
"Wilma\n"
783-
"#else\n"
784-
"Betty\n"
785-
"#endif\n";
776+
const char code[] = "#define A B\n"
777+
"#define B 1\n"
778+
"#define C 1\n"
779+
"#if A == C\n"
780+
"Wilma\n"
781+
"#else\n"
782+
"Betty\n"
783+
"#endif\n";
786784
ASSERT_EQUALS("\n", getConfigsStr(code));
787785
}
788786

0 commit comments

Comments
 (0)