@@ -93,9 +93,9 @@ class TestPreprocessor : public TestFixture {
93
93
}
94
94
95
95
// TODO: we should be using the actual Preprocessor implementation
96
- static std::string getcodeforcfg (const Settings& settings, ErrorLogger& errorlogger, const std::string &filedata , const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr )
96
+ static std::string getcodeforcfg (const Settings& settings, ErrorLogger& errorlogger, const char code[] , const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr )
97
97
{
98
- std::map<std::string, std::string> cfgcode = getcode (settings, errorlogger, filedata. c_str () , std::set<std::string>{cfg}, filename, inlineSuppression);
98
+ std::map<std::string, std::string> cfgcode = getcode (settings, errorlogger, code , std::set<std::string>{cfg}, filename, inlineSuppression);
99
99
const auto it = cfgcode.find (cfg);
100
100
if (it == cfgcode.end ())
101
101
return " " ;
@@ -430,7 +430,7 @@ class TestPreprocessor : public TestFixture {
430
430
431
431
void error3 () {
432
432
const auto settings = dinit (Settings, $.userDefines = " __cplusplus" );
433
- const std::string code ( " #error hello world!\n " ) ;
433
+ const char code[] = " #error hello world!\n " ;
434
434
(void )getcodeforcfg (settings, *this , code, " X" , " test.c" );
435
435
ASSERT_EQUALS (" [test.c:1:0]: (error) #error hello world! [preprocessorErrorDirective]\n " , errout_str ());
436
436
}
@@ -440,15 +440,15 @@ class TestPreprocessor : public TestFixture {
440
440
// In included file
441
441
{
442
442
const auto settings = dinit (Settings, $.userDefines = " TEST" );
443
- const std::string code ( " #file \" ab.h\"\n #error hello world!\n #endfile" ) ;
443
+ const char code[] = " #file \" ab.h\"\n #error hello world!\n #endfile" ;
444
444
(void )getcodeforcfg (settings, *this , code, " TEST" , " test.c" );
445
445
ASSERT_EQUALS (" [ab.h:1:0]: (error) #error hello world! [preprocessorErrorDirective]\n " , errout_str ());
446
446
}
447
447
448
448
// After including a file
449
449
{
450
450
const auto settings = dinit (Settings, $.userDefines = " TEST" );
451
- const std::string code ( " #file \" ab.h\"\n\n #endfile\n #error aaa" ) ;
451
+ const char code[] = " #file \" ab.h\"\n\n #endfile\n #error aaa" ;
452
452
(void )getcodeforcfg (settings, *this , code, " TEST" , " test.c" );
453
453
ASSERT_EQUALS (" [test.c:2:0]: (error) #error aaa [preprocessorErrorDirective]\n " , errout_str ());
454
454
}
@@ -459,7 +459,7 @@ class TestPreprocessor : public TestFixture {
459
459
const auto settings = dinit (Settings,
460
460
$.userDefines = " TEST" ,
461
461
$.force = true );
462
- const std::string code ( " #error hello world!\n " ) ;
462
+ const char code[] = " #error hello world!\n " ;
463
463
(void )getcodeforcfg (settings, *this , code, " X" , " test.c" );
464
464
ASSERT_EQUALS (" " , errout_str ());
465
465
}
@@ -1974,10 +1974,10 @@ class TestPreprocessor : public TestFixture {
1974
1974
settings.inlineSuppressions = true ;
1975
1975
settings.checks .enable (Checks::missingInclude);
1976
1976
1977
- const std::string code ( " // cppcheck-suppress missingInclude\n "
1978
- " #include \" missing.h\"\n "
1979
- " // cppcheck-suppress missingIncludeSystem\n "
1980
- " #include <missing2.h>\n " ) ;
1977
+ const char code[] = " // cppcheck-suppress missingInclude\n "
1978
+ " #include \" missing.h\"\n "
1979
+ " // cppcheck-suppress missingIncludeSystem\n "
1980
+ " #include <missing2.h>\n " ;
1981
1981
SuppressionList inlineSuppr;
1982
1982
(void )getcodeforcfg (settings, *this , code, " " , " test.c" , &inlineSuppr);
1983
1983
@@ -2036,25 +2036,25 @@ class TestPreprocessor : public TestFixture {
2036
2036
}
2037
2037
2038
2038
void predefine1 () {
2039
- const std::string src ( " #if defined X || Y\n "
2040
- " Fred & Wilma\n "
2041
- " #endif\n " ) ;
2042
- std::string actual = getcodeforcfg (settings0, *this , src , " X=1" , " test.c" );
2039
+ const char code[] = " #if defined X || Y\n "
2040
+ " Fred & Wilma\n "
2041
+ " #endif\n " ;
2042
+ std::string actual = getcodeforcfg (settings0, *this , code , " X=1" , " test.c" );
2043
2043
2044
2044
ASSERT_EQUALS (" \n Fred & Wilma" , actual);
2045
2045
}
2046
2046
2047
2047
void predefine2 () {
2048
- const std::string src ( " #if defined(X) && Y\n "
2049
- " Fred & Wilma\n "
2050
- " #endif\n " ) ;
2048
+ const char code[] = " #if defined(X) && Y\n "
2049
+ " Fred & Wilma\n "
2050
+ " #endif\n " ;
2051
2051
{
2052
- std::string actual = getcodeforcfg (settings0, *this , src , " X=1" , " test.c" );
2052
+ std::string actual = getcodeforcfg (settings0, *this , code , " X=1" , " test.c" );
2053
2053
ASSERT_EQUALS (" " , actual);
2054
2054
}
2055
2055
2056
2056
{
2057
- std::string actual = getcodeforcfg (settings0, *this , src , " X=1;Y=2" , " test.c" );
2057
+ std::string actual = getcodeforcfg (settings0, *this , code , " X=1;Y=2" , " test.c" );
2058
2058
ASSERT_EQUALS (" \n Fred & Wilma" , actual);
2059
2059
}
2060
2060
}
@@ -2376,7 +2376,7 @@ class TestPreprocessor : public TestFixture {
2376
2376
2377
2377
void wrongPathOnErrorDirective () {
2378
2378
const auto settings = dinit (Settings, $.userDefines = " foo" );
2379
- const std::string code ( " #error hello world!\n " ) ;
2379
+ const char code[] = " #error hello world!\n " ;
2380
2380
(void )getcodeforcfg (settings, *this , code, " X" , " ./././test.c" );
2381
2381
ASSERT_EQUALS (" [test.c:1:0]: (error) #error hello world! [preprocessorErrorDirective]\n " , errout_str ());
2382
2382
}
@@ -2391,7 +2391,7 @@ class TestPreprocessor : public TestFixture {
2391
2391
2392
2392
ScopedFile header (" header.h" , " " );
2393
2393
2394
- std::string code ( " #include \" header.h\" " ) ;
2394
+ const char code[] = " #include \" header.h\" " ;
2395
2395
(void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2396
2396
2397
2397
ASSERT_EQUALS (" " , errout_str ());
@@ -2405,7 +2405,7 @@ class TestPreprocessor : public TestFixture {
2405
2405
settings.templateFormat = " simple" ; // has no effect
2406
2406
setTemplateFormat (" simple" );
2407
2407
2408
- std::string code ( " #include \" header.h\" " ) ;
2408
+ const char code[] = " #include \" header.h\" " ;
2409
2409
(void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2410
2410
2411
2411
ASSERT_EQUALS (" test.c:1:0: information: Include file: \" header.h\" not found. [missingInclude]\n " , errout_str ());
@@ -2421,7 +2421,7 @@ class TestPreprocessor : public TestFixture {
2421
2421
2422
2422
ScopedFile header (" header.h" , " " , " inc" );
2423
2423
2424
- std::string code ( " #include \" header.h\" " ) ;
2424
+ const char code[] = " #include \" header.h\" " ;
2425
2425
(void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2426
2426
2427
2427
ASSERT_EQUALS (" test.c:1:0: information: Include file: \" header.h\" not found. [missingInclude]\n " , errout_str ());
@@ -2438,7 +2438,7 @@ class TestPreprocessor : public TestFixture {
2438
2438
2439
2439
ScopedFile header (" header.h" , " " , " inc" );
2440
2440
2441
- std::string code ( " #include \" inc/header.h\" " ) ;
2441
+ const char code[] = " #include \" inc/header.h\" " ;
2442
2442
(void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2443
2443
2444
2444
ASSERT_EQUALS (" " , errout_str ());
@@ -2456,7 +2456,7 @@ class TestPreprocessor : public TestFixture {
2456
2456
ScopedFile header (" header.h" , " " , Path::getCurrentPath ());
2457
2457
2458
2458
std::string code (" #include \" " + header.path () + " \" " );
2459
- (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2459
+ (void )getcodeforcfg (settings, *this , code. c_str () , " " , " test.c" );
2460
2460
2461
2461
ASSERT_EQUALS (" " , errout_str ());
2462
2462
}
@@ -2472,7 +2472,7 @@ class TestPreprocessor : public TestFixture {
2472
2472
const std::string header = Path::join (Path::getCurrentPath (), " header.h" );
2473
2473
2474
2474
std::string code (" #include \" " + header + " \" " );
2475
- (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2475
+ (void )getcodeforcfg (settings, *this , code. c_str () , " " , " test.c" );
2476
2476
2477
2477
ASSERT_EQUALS (" test.c:1:0: information: Include file: \" " + header + " \" not found. [missingInclude]\n " , errout_str ());
2478
2478
}
@@ -2487,7 +2487,7 @@ class TestPreprocessor : public TestFixture {
2487
2487
2488
2488
ScopedFile header (" header.h" , " " );
2489
2489
2490
- std::string code ( " #include <header.h>" ) ;
2490
+ const char code[] = " #include <header.h>" ;
2491
2491
(void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2492
2492
2493
2493
ASSERT_EQUALS (" test.c:1:0: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n " , errout_str ());
@@ -2501,7 +2501,7 @@ class TestPreprocessor : public TestFixture {
2501
2501
settings.templateFormat = " simple" ; // has no effect
2502
2502
setTemplateFormat (" simple" );
2503
2503
2504
- std::string code ( " #include <header.h>" ) ;
2504
+ const char code[] = " #include <header.h>" ;
2505
2505
(void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2506
2506
2507
2507
ASSERT_EQUALS (" test.c:1:0: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n " , errout_str ());
@@ -2518,7 +2518,7 @@ class TestPreprocessor : public TestFixture {
2518
2518
2519
2519
ScopedFile header (" header.h" , " " , " system" );
2520
2520
2521
- std::string code ( " #include <header.h>" ) ;
2521
+ const char code[] = " #include <header.h>" ;
2522
2522
(void )getcodeforcfg (settings0, *this , code, " " , " test.c" );
2523
2523
2524
2524
ASSERT_EQUALS (" " , errout_str ());
@@ -2536,7 +2536,7 @@ class TestPreprocessor : public TestFixture {
2536
2536
ScopedFile header (" header.h" , " " , Path::getCurrentPath ());
2537
2537
2538
2538
std::string code (" #include <" + header.path () + " >" );
2539
- (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2539
+ (void )getcodeforcfg (settings, *this , code. c_str () , " " , " test.c" );
2540
2540
2541
2541
ASSERT_EQUALS (" " , errout_str ());
2542
2542
}
@@ -2552,7 +2552,7 @@ class TestPreprocessor : public TestFixture {
2552
2552
const std::string header = Path::join (Path::getCurrentPath (), " header.h" );
2553
2553
2554
2554
std::string code (" #include <" + header + " >" );
2555
- (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2555
+ (void )getcodeforcfg (settings, *this , code. c_str () , " " , " test.c" );
2556
2556
2557
2557
ASSERT_EQUALS (" test.c:1:0: information: Include file: <" + header + " > not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n " , errout_str ());
2558
2558
}
@@ -2568,10 +2568,10 @@ class TestPreprocessor : public TestFixture {
2568
2568
ScopedFile header (" header.h" , " " );
2569
2569
ScopedFile header2 (" header2.h" , " " );
2570
2570
2571
- std::string code ( " #include \" missing.h\"\n "
2572
- " #include <header.h>\n "
2573
- " #include <missing2.h>\n "
2574
- " #include \" header2.h\" " ) ;
2571
+ const char code[] = " #include \" missing.h\"\n "
2572
+ " #include <header.h>\n "
2573
+ " #include <missing2.h>\n "
2574
+ " #include \" header2.h\" " ;
2575
2575
(void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2576
2576
2577
2577
ASSERT_EQUALS (" test.c:1:0: information: Include file: \" missing.h\" not found. [missingInclude]\n "
@@ -2608,7 +2608,7 @@ class TestPreprocessor : public TestFixture {
2608
2608
" #include \" " + missing3 + " \"\n "
2609
2609
" #include <" + header6.path () + " >\n "
2610
2610
" #include <" + missing4 + " >\n " );
2611
- (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2611
+ (void )getcodeforcfg (settings, *this , code. c_str () , " " , " test.c" );
2612
2612
2613
2613
ASSERT_EQUALS (" test.c:1:0: information: Include file: \" missing.h\" not found. [missingInclude]\n "
2614
2614
" test.c:2:0: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n "
0 commit comments