-
Notifications
You must be signed in to change notification settings - Fork 82
/
test.cpp
3159 lines (2713 loc) · 110 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* simplecpp - A simple and high-fidelity C/C++ preprocessor library
* Copyright (C) 2016-2023 simplecpp team
*/
#include "simplecpp.h"
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <iostream>
#include <map>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
#define STRINGIZE_(x) #x
#define STRINGIZE(x) STRINGIZE_(x)
static int numberOfFailedAssertions = 0;
#define ASSERT_EQUALS(expected, actual) (assertEquals((expected), (actual), __LINE__))
#define ASSERT_THROW_EQUALS(stmt, e, expected) do { try { stmt; assertThrowFailed(__LINE__); } catch (const e& ex) { assertEquals((expected), (ex.what()), __LINE__); } } while(false)
static std::string pprint(const std::string &in)
{
std::string ret;
for (std::string::size_type i = 0; i < in.size(); ++i) {
if (in[i] == '\n')
ret += "\\n";
ret += in[i];
}
return ret;
}
static int assertEquals(const std::string &expected, const std::string &actual, int line)
{
if (expected != actual) {
numberOfFailedAssertions++;
std::cerr << "------ assertion failed ---------" << std::endl;
std::cerr << "line " << line << std::endl;
std::cerr << "expected:" << pprint(expected) << std::endl;
std::cerr << "actual:" << pprint(actual) << std::endl;
}
return (expected == actual);
}
static int assertEquals(const long long &expected, const long long &actual, int line)
{
return assertEquals(std::to_string(expected), std::to_string(actual), line);
}
static void assertThrowFailed(int line)
{
numberOfFailedAssertions++;
std::cerr << "------ assertion failed ---------" << std::endl;
std::cerr << "line " << line << std::endl;
std::cerr << "exception not thrown" << std::endl;
}
static void testcase(const std::string &name, void (*f)(), int argc, char * const *argv)
{
if (argc == 1)
f();
else {
for (int i = 1; i < argc; i++) {
if (name == argv[i])
f();
}
}
}
#define TEST_CASE(F) (testcase(#F, F, argc, argv))
static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
{
std::istringstream istr(std::string(code, size));
return simplecpp::TokenList(istr,filenames,filename,outputList);
}
static simplecpp::TokenList makeTokenList(const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
{
return makeTokenList(code, strlen(code), filenames, filename, outputList);
}
static std::string readfile(const char code[], simplecpp::OutputList *outputList=nullptr)
{
std::vector<std::string> files;
return makeTokenList(code,files,std::string(),outputList).stringify();
}
static std::string readfile(const char code[], std::size_t size, simplecpp::OutputList *outputList=nullptr)
{
std::vector<std::string> files;
return makeTokenList(code,size,files,std::string(),outputList).stringify();
}
static std::string preprocess(const char code[], const simplecpp::DUI &dui, simplecpp::OutputList *outputList)
{
std::vector<std::string> files;
std::map<std::string, simplecpp::TokenList*> filedata;
simplecpp::TokenList tokens = makeTokenList(code,files);
tokens.removeComments();
simplecpp::TokenList tokens2(files);
simplecpp::preprocess(tokens2, tokens, files, filedata, dui, outputList);
return tokens2.stringify();
}
static std::string preprocess(const char code[])
{
return preprocess(code, simplecpp::DUI(), nullptr);
}
static std::string preprocess(const char code[], const simplecpp::DUI &dui)
{
return preprocess(code, dui, nullptr);
}
static std::string preprocess(const char code[], simplecpp::OutputList *outputList)
{
return preprocess(code, simplecpp::DUI(), outputList);
}
static std::string toString(const simplecpp::OutputList &outputList)
{
std::ostringstream ostr;
for (const simplecpp::Output &output : outputList) {
ostr << "file" << output.location.fileIndex << ',' << output.location.line << ',';
switch (output.type) {
case simplecpp::Output::Type::ERROR:
ostr << "#error,";
break;
case simplecpp::Output::Type::WARNING:
ostr << "#warning,";
break;
case simplecpp::Output::Type::MISSING_HEADER:
ostr << "missing_header,";
break;
case simplecpp::Output::Type::INCLUDE_NESTED_TOO_DEEPLY:
ostr << "include_nested_too_deeply,";
break;
case simplecpp::Output::Type::SYNTAX_ERROR:
ostr << "syntax_error,";
break;
case simplecpp::Output::Type::PORTABILITY_BACKSLASH:
ostr << "portability_backslash,";
break;
case simplecpp::Output::Type::UNHANDLED_CHAR_ERROR:
ostr << "unhandled_char_error,";
break;
case simplecpp::Output::Type::EXPLICIT_INCLUDE_NOT_FOUND:
ostr << "explicit_include_not_found,";
break;
case simplecpp::Output::Type::FILE_NOT_FOUND:
ostr << "file_not_found,";
break;
case simplecpp::Output::Type::DUI_ERROR:
ostr << "dui_error,";
break;
}
ostr << output.msg << '\n';
}
return ostr.str();
}
static void backslash()
{
// <backslash><space><newline> preprocessed differently
simplecpp::OutputList outputList;
readfile("//123 \\\n456", &outputList);
ASSERT_EQUALS("", toString(outputList));
readfile("//123 \\ \n456", &outputList);
ASSERT_EQUALS("file0,1,portability_backslash,Combination 'backslash space newline' is not portable.\n", toString(outputList));
outputList.clear();
readfile("#define A \\\n123", &outputList);
ASSERT_EQUALS("", toString(outputList));
readfile("#define A \\ \n123", &outputList);
ASSERT_EQUALS("file0,1,portability_backslash,Combination 'backslash space newline' is not portable.\n", toString(outputList));
}
static void builtin()
{
ASSERT_EQUALS("\"\" 1 0", preprocess("__FILE__ __LINE__ __COUNTER__"));
ASSERT_EQUALS("\n\n3", preprocess("\n\n__LINE__"));
ASSERT_EQUALS("\n\n0", preprocess("\n\n__COUNTER__"));
ASSERT_EQUALS("\n\n0 1", preprocess("\n\n__COUNTER__ __COUNTER__"));
ASSERT_EQUALS("\n0 + 0", preprocess("#define A(c) c+c\n"
"A(__COUNTER__)\n"));
ASSERT_EQUALS("\n0 + 0 + 1", preprocess("#define A(c) c+c+__COUNTER__\n"
"A(__COUNTER__)\n"));
}
static std::string testConstFold(const char code[])
{
try {
std::vector<std::string> files;
simplecpp::TokenList expr = makeTokenList(code, files);
expr.constFold();
return expr.stringify();
} catch (std::exception &) {
return "exception";
}
}
static void characterLiteral()
{
ASSERT_EQUALS('A', simplecpp::characterLiteralToLL("'A'"));
ASSERT_EQUALS('\'', simplecpp::characterLiteralToLL("'\\''"));
ASSERT_EQUALS('\"', simplecpp::characterLiteralToLL("'\\\"'"));
ASSERT_EQUALS('\?', simplecpp::characterLiteralToLL("'\\?'"));
ASSERT_EQUALS('\\', simplecpp::characterLiteralToLL("'\\\\'"));
ASSERT_EQUALS('\a', simplecpp::characterLiteralToLL("'\\a'"));
ASSERT_EQUALS('\b', simplecpp::characterLiteralToLL("'\\b'"));
ASSERT_EQUALS('\f', simplecpp::characterLiteralToLL("'\\f'"));
ASSERT_EQUALS('\n', simplecpp::characterLiteralToLL("'\\n'"));
ASSERT_EQUALS('\r', simplecpp::characterLiteralToLL("'\\r'"));
ASSERT_EQUALS('\t', simplecpp::characterLiteralToLL("'\\t'"));
ASSERT_EQUALS('\v', simplecpp::characterLiteralToLL("'\\v'"));
// GCC extension for ESC character
ASSERT_EQUALS(0x1b, simplecpp::characterLiteralToLL("'\\e'"));
ASSERT_EQUALS(0x1b, simplecpp::characterLiteralToLL("'\\E'"));
// more obscure GCC extensions
ASSERT_EQUALS('(', simplecpp::characterLiteralToLL("'\\('"));
ASSERT_EQUALS('[', simplecpp::characterLiteralToLL("'\\['"));
ASSERT_EQUALS('{', simplecpp::characterLiteralToLL("'\\{'"));
ASSERT_EQUALS('%', simplecpp::characterLiteralToLL("'\\%'"));
ASSERT_EQUALS('\0', simplecpp::characterLiteralToLL("'\\0'"));
ASSERT_EQUALS('\1', simplecpp::characterLiteralToLL("'\\1'"));
ASSERT_EQUALS('\10', simplecpp::characterLiteralToLL("'\\10'"));
ASSERT_EQUALS('\010', simplecpp::characterLiteralToLL("'\\010'"));
ASSERT_EQUALS('\377', simplecpp::characterLiteralToLL("'\\377'"));
ASSERT_EQUALS('\x0', simplecpp::characterLiteralToLL("'\\x0'"));
ASSERT_EQUALS('\x10', simplecpp::characterLiteralToLL("'\\x10'"));
ASSERT_EQUALS('\xff', simplecpp::characterLiteralToLL("'\\xff'"));
ASSERT_EQUALS('\u0012', simplecpp::characterLiteralToLL("'\\u0012'"));
ASSERT_EQUALS('\U00000012', simplecpp::characterLiteralToLL("'\\U00000012'"));
ASSERT_EQUALS((static_cast<unsigned int>(static_cast<unsigned char>('b')) << 8) | static_cast<unsigned char>('c'), simplecpp::characterLiteralToLL("'bc'"));
ASSERT_EQUALS((static_cast<unsigned int>(static_cast<unsigned char>('\x23')) << 8) | static_cast<unsigned char>('\x45'), simplecpp::characterLiteralToLL("'\\x23\\x45'"));
ASSERT_EQUALS((static_cast<unsigned int>(static_cast<unsigned char>('\11')) << 8) | static_cast<unsigned char>('\222'), simplecpp::characterLiteralToLL("'\\11\\222'"));
ASSERT_EQUALS((static_cast<unsigned int>(static_cast<unsigned char>('\a')) << 8) | static_cast<unsigned char>('\b'), simplecpp::characterLiteralToLL("'\\a\\b'"));
if (sizeof(int) <= 4)
ASSERT_EQUALS(-1, simplecpp::characterLiteralToLL("'\\xff\\xff\\xff\\xff'"));
else
ASSERT_EQUALS(0xffffffff, simplecpp::characterLiteralToLL("'\\xff\\xff\\xff\\xff'"));
ASSERT_EQUALS('A', simplecpp::characterLiteralToLL("u8'A'"));
ASSERT_EQUALS('A', simplecpp::characterLiteralToLL("u'A'"));
ASSERT_EQUALS('A', simplecpp::characterLiteralToLL("L'A'"));
ASSERT_EQUALS('A', simplecpp::characterLiteralToLL("U'A'"));
ASSERT_EQUALS(0xff, simplecpp::characterLiteralToLL("u8'\\xff'"));
ASSERT_EQUALS(0xff, simplecpp::characterLiteralToLL("u'\\xff'"));
ASSERT_EQUALS(0xff, simplecpp::characterLiteralToLL("L'\\xff'"));
ASSERT_EQUALS(0xff, simplecpp::characterLiteralToLL("U'\\xff'"));
ASSERT_EQUALS(0xfedc, simplecpp::characterLiteralToLL("u'\\xfedc'"));
ASSERT_EQUALS(0xfedcba98, simplecpp::characterLiteralToLL("L'\\xfedcba98'"));
ASSERT_EQUALS(0xfedcba98, simplecpp::characterLiteralToLL("U'\\xfedcba98'"));
ASSERT_EQUALS(0x12, simplecpp::characterLiteralToLL("u8'\\u0012'"));
ASSERT_EQUALS(0x1234, simplecpp::characterLiteralToLL("u'\\u1234'"));
ASSERT_EQUALS(0x00012345, simplecpp::characterLiteralToLL("L'\\U00012345'"));
ASSERT_EQUALS(0x00012345, simplecpp::characterLiteralToLL("U'\\U00012345'"));
#ifdef __GNUC__
// BEGIN Implementation-specific results
ASSERT_EQUALS(static_cast<int>('AB'), simplecpp::characterLiteralToLL("'AB'"));
ASSERT_EQUALS(static_cast<int>('ABC'), simplecpp::characterLiteralToLL("'ABC'"));
ASSERT_EQUALS(static_cast<int>('ABCD'), simplecpp::characterLiteralToLL("'ABCD'"));
ASSERT_EQUALS('\134t', simplecpp::characterLiteralToLL("'\\134t'")); // cppcheck ticket #7452
// END Implementation-specific results
#endif
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("'\\9'"), std::runtime_error, "invalid escape sequence");
// Input is manually encoded to (escaped) UTF-8 byte sequences
// to avoid dependence on source encoding used for this file
ASSERT_EQUALS(0xb5, simplecpp::characterLiteralToLL("U'\302\265'"));
ASSERT_EQUALS(0x157, simplecpp::characterLiteralToLL("U'\305\227'"));
ASSERT_EQUALS(0xff0f, simplecpp::characterLiteralToLL("U'\357\274\217'"));
ASSERT_EQUALS(0x3042, simplecpp::characterLiteralToLL("U'\343\201\202'"));
ASSERT_EQUALS(0x13000, simplecpp::characterLiteralToLL("U'\360\223\200\200'"));
ASSERT_EQUALS(0xb5, simplecpp::characterLiteralToLL("L'\302\265'"));
ASSERT_EQUALS(0x157, simplecpp::characterLiteralToLL("L'\305\227'"));
ASSERT_EQUALS(0xff0f, simplecpp::characterLiteralToLL("L'\357\274\217'"));
ASSERT_EQUALS(0x3042, simplecpp::characterLiteralToLL("L'\343\201\202'"));
ASSERT_EQUALS(0x13000, simplecpp::characterLiteralToLL("L'\360\223\200\200'"));
ASSERT_EQUALS(0xb5, simplecpp::characterLiteralToLL("u'\302\265'"));
ASSERT_EQUALS(0x157, simplecpp::characterLiteralToLL("u'\305\227'"));
ASSERT_EQUALS(0xff0f, simplecpp::characterLiteralToLL("u'\357\274\217'"));
ASSERT_EQUALS(0x3042, simplecpp::characterLiteralToLL("u'\343\201\202'"));
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("u'\360\223\200\200'"), std::runtime_error, "code point too large");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("u8'\302\265'"), std::runtime_error, "code point too large");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("u8'\305\227'"), std::runtime_error, "code point too large");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("u8'\357\274\217'"), std::runtime_error, "code point too large");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("u8'\343\201\202'"), std::runtime_error, "code point too large");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("u8'\360\223\200\200'"), std::runtime_error, "code point too large");
ASSERT_EQUALS('\x89', simplecpp::characterLiteralToLL("'\x89'"));
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\x89'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xf4\x90\x80\x80'"), std::runtime_error, "code point too large");
// following examples based on https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
ASSERT_EQUALS(0x80, simplecpp::characterLiteralToLL("U'\xc2\x80'"));
ASSERT_EQUALS(0x800, simplecpp::characterLiteralToLL("U'\xe0\xa0\x80'"));
ASSERT_EQUALS(0x10000, simplecpp::characterLiteralToLL("U'\xf0\x90\x80\x80'"));
ASSERT_EQUALS(0x7f, simplecpp::characterLiteralToLL("U'\x7f'"));
ASSERT_EQUALS(0x7ff, simplecpp::characterLiteralToLL("U'\xdf\xbf'"));
ASSERT_EQUALS(0xffff, simplecpp::characterLiteralToLL("U'\xef\xbf\xbf'"));
ASSERT_EQUALS(0xd7ff, simplecpp::characterLiteralToLL("U'\xed\x9f\xbf'"));
ASSERT_EQUALS(0xe000, simplecpp::characterLiteralToLL("U'\xee\x80\x80'"));
ASSERT_EQUALS(0xfffd, simplecpp::characterLiteralToLL("U'\xef\xbf\xbd'"));
ASSERT_EQUALS(0x10ffff, simplecpp::characterLiteralToLL("U'\xf4\x8f\xbf\xbf'"));
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\x80'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\x80\x8f'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\x80\x8f\x8f'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\x80\x8f\x8f\x8f'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xbf'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xbf\x8f'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xbf\x8f\x8f'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xbf\x8f\x8f\x8f'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xc0'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xc0 '"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xe0\x8f'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xe0\x8f '"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xf0\x8f\x8f'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xf0\x8f\x8f '"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xf8'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xff'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xc0\xaf'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xe0\x80\xaf'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xf0\x80\x80\xaf'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xc1\xbf'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xe0\x9f\xbf'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xf0\x8f\xbf\xbf'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xc0\x80'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xe0\x80\x80'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xf0\x80\x80\x80'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xed\xa0\x80'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
ASSERT_THROW_EQUALS(simplecpp::characterLiteralToLL("U'\xed\xbf\xbf'"), std::runtime_error, "assumed UTF-8 encoded source, but sequence is invalid");
}
static void combineOperators_floatliteral()
{
ASSERT_EQUALS("1.", preprocess("1."));
ASSERT_EQUALS("1.f", preprocess("1.f"));
ASSERT_EQUALS(".1", preprocess(".1"));
ASSERT_EQUALS(".1f", preprocess(".1f"));
ASSERT_EQUALS("3.1", preprocess("3.1"));
ASSERT_EQUALS("1E7", preprocess("1E7"));
ASSERT_EQUALS("1E-7", preprocess("1E-7"));
ASSERT_EQUALS("1E+7", preprocess("1E+7"));
ASSERT_EQUALS("1.e+7", preprocess("1.e+7"));
ASSERT_EQUALS("0x1E + 7", preprocess("0x1E+7"));
ASSERT_EQUALS("0x1ffp10", preprocess("0x1ffp10"));
ASSERT_EQUALS("0x0p-1", preprocess("0x0p-1"));
ASSERT_EQUALS("0x1.p0", preprocess("0x1.p0"));
ASSERT_EQUALS("0xf.p-1", preprocess("0xf.p-1"));
ASSERT_EQUALS("0x1.2p3", preprocess("0x1.2p3"));
ASSERT_EQUALS("0x1.ap3", preprocess("0x1.ap3"));
ASSERT_EQUALS("0x1.2ap3", preprocess("0x1.2ap3"));
ASSERT_EQUALS("0x1p+3", preprocess("0x1p+3"));
ASSERT_EQUALS("0x1p+3f", preprocess("0x1p+3f"));
ASSERT_EQUALS("0x1p+3L", preprocess("0x1p+3L"));
ASSERT_EQUALS("1p + 3", preprocess("1p+3"));
ASSERT_EQUALS("1.0_a . b", preprocess("1.0_a.b"));
ASSERT_EQUALS("1_a . b", preprocess("1_a.b"));
}
static void combineOperators_increment()
{
ASSERT_EQUALS("; ++ x ;", preprocess(";++x;"));
ASSERT_EQUALS("; x ++ ;", preprocess(";x++;"));
ASSERT_EQUALS("1 + + 2", preprocess("1++2"));
}
static void combineOperators_coloncolon()
{
ASSERT_EQUALS("x ? y : :: z", preprocess("x ? y : ::z"));
}
static void combineOperators_andequal()
{
ASSERT_EQUALS("x &= 2 ;", preprocess("x &= 2;"));
ASSERT_EQUALS("void f ( x & = 2 ) ;", preprocess("void f(x &= 2);"));
ASSERT_EQUALS("f ( x &= 2 ) ;", preprocess("f(x &= 2);"));
}
static void combineOperators_ellipsis()
{
ASSERT_EQUALS("void f ( int , ... ) ;", preprocess("void f(int, ...);"));
ASSERT_EQUALS("void f ( ) { switch ( x ) { case 1 ... 4 : } }", preprocess("void f() { switch(x) { case 1 ... 4: } }"));
}
static void comment()
{
ASSERT_EQUALS("// abc", readfile("// abc"));
ASSERT_EQUALS("", preprocess("// abc"));
ASSERT_EQUALS("/*\n\n*/abc", readfile("/*\n\n*/abc"));
ASSERT_EQUALS("\n\nabc", preprocess("/*\n\n*/abc"));
ASSERT_EQUALS("* p = a / * b / * c ;", readfile("*p=a/ *b/ *c;"));
ASSERT_EQUALS("* p = a / * b / * c ;", preprocess("*p=a/ *b/ *c;"));
}
static void comment_multiline()
{
const char code[] = "#define ABC {// \\\n"
"}\n"
"void f() ABC\n";
ASSERT_EQUALS("\n\nvoid f ( ) { }", preprocess(code));
}
static void constFold()
{
ASSERT_EQUALS("7", testConstFold("1+2*3"));
ASSERT_EQUALS("15", testConstFold("1+2*(3+4)"));
ASSERT_EQUALS("123", testConstFold("+123"));
ASSERT_EQUALS("1", testConstFold("-123<1"));
ASSERT_EQUALS("6", testConstFold("14 & 7"));
ASSERT_EQUALS("29", testConstFold("13 ^ 16"));
ASSERT_EQUALS("25", testConstFold("24 | 1"));
ASSERT_EQUALS("2", testConstFold("1?2:3"));
ASSERT_EQUALS("24", testConstFold("010+020"));
ASSERT_EQUALS("1", testConstFold("010==8"));
ASSERT_EQUALS("exception", testConstFold("!1 ? 2 :"));
ASSERT_EQUALS("exception", testConstFold("?2:3"));
}
#ifdef __CYGWIN__
static void convertCygwinPath()
{
// absolute paths
ASSERT_EQUALS("X:\\", simplecpp::convertCygwinToWindowsPath("/cygdrive/x")); // initial backslash
ASSERT_EQUALS("X:\\", simplecpp::convertCygwinToWindowsPath("/cygdrive/x/"));
ASSERT_EQUALS("X:\\dir", simplecpp::convertCygwinToWindowsPath("/cygdrive/x/dir"));
ASSERT_EQUALS("X:\\dir\\file", simplecpp::convertCygwinToWindowsPath("/cygdrive/x/dir/file"));
// relative paths
ASSERT_EQUALS("file", simplecpp::convertCygwinToWindowsPath("file"));
ASSERT_EQUALS("dir\\file", simplecpp::convertCygwinToWindowsPath("dir/file"));
ASSERT_EQUALS("..\\dir\\file", simplecpp::convertCygwinToWindowsPath("../dir/file"));
// incorrect Cygwin paths
ASSERT_EQUALS("\\cygdrive", simplecpp::convertCygwinToWindowsPath("/cygdrive"));
ASSERT_EQUALS("\\cygdrive\\", simplecpp::convertCygwinToWindowsPath("/cygdrive/"));
}
#endif
static void define1()
{
const char code[] = "#define A 1+2\n"
"a=A+3;";
ASSERT_EQUALS("# define A 1 + 2\n"
"a = A + 3 ;",
readfile(code));
ASSERT_EQUALS("\na = 1 + 2 + 3 ;",
preprocess(code));
}
static void define2()
{
const char code[] = "#define ADD(A,B) A+B\n"
"ADD(1+2,3);";
ASSERT_EQUALS("# define ADD ( A , B ) A + B\n"
"ADD ( 1 + 2 , 3 ) ;",
readfile(code));
ASSERT_EQUALS("\n1 + 2 + 3 ;",
preprocess(code));
}
static void define3()
{
const char code[] = "#define A 123\n"
"#define B A\n"
"A B";
ASSERT_EQUALS("# define A 123\n"
"# define B A\n"
"A B",
readfile(code));
ASSERT_EQUALS("\n\n123 123",
preprocess(code));
}
static void define4()
{
const char code[] = "#define A 123\n"
"#define B(C) A\n"
"A B(1)";
ASSERT_EQUALS("# define A 123\n"
"# define B ( C ) A\n"
"A B ( 1 )",
readfile(code));
ASSERT_EQUALS("\n\n123 123",
preprocess(code));
}
static void define5()
{
const char code[] = "#define add(x,y) x+y\n"
"add(add(1,2),3)";
ASSERT_EQUALS("\n1 + 2 + 3", preprocess(code));
}
static void define6()
{
const char code[] = "#define A() 1\n"
"A()";
ASSERT_EQUALS("\n1", preprocess(code));
}
static void define7()
{
const char code[] = "#define A(X) X+1\n"
"A(1 /*23*/)";
ASSERT_EQUALS("\n1 + 1", preprocess(code));
}
static void define8() // 6.10.3.10
{
const char code[] = "#define A(X) \n"
"int A[10];";
ASSERT_EQUALS("\nint A [ 10 ] ;", preprocess(code));
}
static void define9()
{
const char code[] = "#define AB ab.AB\n"
"AB.CD\n";
ASSERT_EQUALS("\nab . AB . CD", preprocess(code));
}
static void define10() // don't combine prefix with space in macro
{
const char code[] = "#define A u8 \"a b\"\n"
"A;";
ASSERT_EQUALS("\nu8 \"a b\" ;", preprocess(code));
}
static void define11() // location of expanded argument
{
const char code[] = "#line 4 \"version.h\"\n"
"#define A(x) B(x)\n"
"#define B(x) x\n"
"#define VER A(1)\n"
"\n"
"#line 10 \"cppcheck.cpp\"\n"
"VER;";
ASSERT_EQUALS("\n#line 10 \"cppcheck.cpp\"\n1 ;", preprocess(code));
}
static void define12()
{
const char code[] = "struct foo x = {\n"
" #define V 0\n"
" .x = V,\n"
"};\n";
ASSERT_EQUALS("struct foo x = {\n"
"# define V 0\n"
". x = V ,\n"
"} ;", readfile(code));
ASSERT_EQUALS("struct foo x = {\n"
"\n"
". x = 0 ,\n"
"} ;", preprocess(code));
}
static void define13()
{
const char code[] = "#define M 180.\n"
"extern void g();\n"
"void f(double d) {\n"
" if (d > M) {}\n"
"}\n";
ASSERT_EQUALS("\nextern void g ( ) ;\n"
"void f ( double d ) {\n"
"if ( d > 180. ) { }\n"
"}", preprocess(code));
}
static void define_invalid_1()
{
const char code[] = "#define A(\nB\n";
simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess(code, &outputList));
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define\n", toString(outputList));
}
static void define_invalid_2()
{
const char code[] = "#define\nhas#";
simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess(code, &outputList));
ASSERT_EQUALS("file0,1,syntax_error,Failed to parse #define\n", toString(outputList));
}
static void define_define_1()
{
const char code[] = "#define A(x) (x+1)\n"
"#define B A(\n"
"B(i))";
ASSERT_EQUALS("\n\n( ( i ) + 1 )", preprocess(code));
}
static void define_define_2()
{
const char code[] = "#define A(m) n=m\n"
"#define B(x) A(x)\n"
"B(0)";
ASSERT_EQUALS("\n\nn = 0", preprocess(code));
}
static void define_define_3()
{
const char code[] = "#define ABC 123\n"
"#define A(B) A##B\n"
"A(BC)";
ASSERT_EQUALS("\n\n123", preprocess(code));
}
static void define_define_4()
{
const char code[] = "#define FOO1()\n"
"#define TEST(FOO) FOO FOO()\n"
"TEST(FOO1)";
ASSERT_EQUALS("\n\nFOO1", preprocess(code));
}
static void define_define_5()
{
const char code[] = "#define X() Y\n"
"#define Y() X\n"
"A: X()()()\n";
// mcpp outputs "A: X()" and gcc/clang/vc outputs "A: Y"
ASSERT_EQUALS("\n\nA : Y", preprocess(code)); // <- match the output from gcc/clang/vc
}
static void define_define_6()
{
const char code1[] = "#define f(a) a*g\n"
"#define g f\n"
"a: f(2)(9)\n";
ASSERT_EQUALS("\n\na : 2 * f ( 9 )", preprocess(code1));
const char code2[] = "#define f(a) a*g\n"
"#define g(a) f(a)\n"
"a: f(2)(9)\n";
ASSERT_EQUALS("\n\na : 2 * 9 * g", preprocess(code2));
}
static void define_define_7()
{
const char code[] = "#define f(x) g(x\n"
"#define g(x) x()\n"
"f(f))\n";
ASSERT_EQUALS("\n\nf ( )", preprocess(code));
}
static void define_define_8() // line break in nested macro call
{
const char code[] = "#define A(X,Y) ((X)*(Y))\n"
"#define B(X,Y) ((X)+(Y))\n"
"B(0,A(255,x+\n"
"y))\n";
ASSERT_EQUALS("\n\n( ( 0 ) + ( ( ( 255 ) * ( x + y ) ) ) )", preprocess(code));
}
static void define_define_9() // line break in nested macro call
{
const char code[] = "#define A(X) X\n"
"#define B(X) X\n"
"A(\nB(dostuff(1,\n2)))\n";
ASSERT_EQUALS("\n\ndostuff ( 1 , 2 )", preprocess(code));
}
static void define_define_10()
{
const char code[] = "#define glue(a, b) a ## b\n"
"#define xglue(a, b) glue(a, b)\n"
"#define AB 1\n"
"#define B B 2\n"
"xglue(A, B)\n";
ASSERT_EQUALS("\n\n\n\n1 2", preprocess(code));
}
static void define_define_11()
{
const char code[] = "#define XY(x, y) x ## y\n"
"#define XY2(x, y) XY(x, y)\n"
"#define PORT XY2(P, 2)\n"
"#define ABC XY2(PORT, DIR)\n"
"ABC;\n";
ASSERT_EQUALS("\n\n\n\nP2DIR ;", preprocess(code));
}
static void define_define_11a()
{
const char code[] = "#define A_B_C 0x1\n"
"#define A_ADDRESS 0x00001000U\n"
"#define A ((uint32_t ) A_ADDRESS)\n"
"#define CONCAT(x, y, z) x ## _ ## y ## _ ## z\n"
"#define TEST_MACRO CONCAT(A, B, C)\n"
"TEST_MACRO\n";
ASSERT_EQUALS("\n\n\n\n\n0x1", preprocess(code));
const char code2[] = "#define ADDER_S(a, b) a + b\n" // #374
"#define ADDER(x) ADDER_S(x)\n"
"#define ARGUMENTS 1, 2\n"
"#define RUN ADDER(ARGUMENTS)\n"
"void f() { RUN; }\n";
ASSERT_EQUALS("\n\n\n\nvoid f ( ) { 1 + 2 ; }", preprocess(code2));
}
static void define_define_12()
{
const char code[] = "#define XY(Z) Z\n"
"#define X(ID) X##ID(0)\n"
"X(Y)\n";
ASSERT_EQUALS("\n\n0", preprocess(code));
}
static void define_define_13() // issue #49 - empty macro
{
const char code[] = "#define f()\n"
"#define t(a) a\n"
"(t(f))\n";
ASSERT_EQUALS("\n\n( f )", preprocess(code));
}
static void define_define_14() // issue #58 - endless recursion
{
const char code[] = "#define z f(w\n"
"#define f()\n"
"#define w f(z\n"
"w\n";
ASSERT_EQUALS("\n\n\nf ( f ( w", preprocess(code)); // Don't crash
}
static void define_define_15() // issue #72 without __VA_ARGS__
{
const char code[] = "#define a f\n"
"#define foo(x,y) a(x,y)\n"
"#define f(x, y) x y\n"
"foo(1,2)";
ASSERT_EQUALS("\n\n\n1 2", preprocess(code));
}
static void define_define_16() // issue #72 with __VA_ARGS__
{
const char code[] = "#define ab(a, b) a##b\n"
"#define foo(...) ab(f, 2) (__VA_ARGS__)\n"
"#define f2(x, y) x y\n"
"foo(1,2)";
ASSERT_EQUALS("\n\n\n1 2", preprocess(code));
}
static void define_define_17()
{
const char code[] = "#define Bar(x) x\n"
"#define Foo Bar(1)\n"
"Bar( Foo ) ;";
ASSERT_EQUALS("\n\n1 ;", preprocess(code));
}
static void define_define_18()
{
const char code[] = "#define FOO(v) BAR(v, 0)\n"
"#define BAR(v, x) (v)\n"
"#define var (p->var)\n"
"FOO(var);";
ASSERT_EQUALS("\n\n\n( ( p -> var ) ) ;", preprocess(code));
}
static void define_define_19() // #292
{
const char code[] = "#define X 1,2,3\n"
"#define Foo(A, B) A\n"
"#define Bar Foo(X, 0)\n"
"Bar\n";
ASSERT_EQUALS("\n\n\n1 , 2 , 3", preprocess(code));
}
static void define_va_args_1()
{
const char code[] = "#define A(fmt...) dostuff(fmt)\n"
"A(1,2);";
ASSERT_EQUALS("\ndostuff ( 1 , 2 ) ;", preprocess(code));
}
static void define_va_args_2()
{
const char code[] = "#define A(X,...) X(#__VA_ARGS__)\n"
"A(f,123);";
ASSERT_EQUALS("\nf ( \"123\" ) ;", preprocess(code));
}
static void define_va_args_3() // min number of arguments
{
const char code[] = "#define A(x, y, z...) 1\n"
"A(1, 2)\n";
ASSERT_EQUALS("\n1", preprocess(code));
}
static void define_va_args_4() // cppcheck trac #9754
{
const char code[] = "#define A(x, y, ...) printf(x, y, __VA_ARGS__)\n"
"A(1, 2)\n";
ASSERT_EQUALS("\nprintf ( 1 , 2 )", preprocess(code));
}
static void define_va_opt_1()
{
const char code[] = "#define p1(fmt, args...) printf(fmt __VA_OPT__(,) args)\n"
"p1(\"hello\");\n"
"p1(\"%s\", \"hello\");\n";
ASSERT_EQUALS("\nprintf ( \"hello\" ) ;\n"
"printf ( \"%s\" , \"hello\" ) ;",
preprocess(code));
}
static void define_va_opt_2()
{
const char code[] = "#define err(...)\\\n"
"__VA_OPT__(\\\n"
"printf(__VA_ARGS__);\\\n"
")\n"
"#define err2(something, ...) __VA_OPT__(err(__VA_ARGS__))\n"
"err2(test)\n"
"err2(test, \"%d\", 2)\n";
ASSERT_EQUALS("\n\n\n\n\n\nprintf ( \"%d\" , 2 ) ;", preprocess(code));
}
static void define_va_opt_3()
{
// non-escaped newline without closing parenthesis
const char code1[] = "#define err(...) __VA_OPT__(printf( __VA_ARGS__);\n"
")\n"
"err()";
simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess(code1, &outputList));
ASSERT_EQUALS("file0,1,syntax_error,failed to expand 'err', Missing parenthesis for __VA_OPT__(content)\n",
toString(outputList));
outputList.clear();
// non-escaped newline without open parenthesis
const char code2[] = "#define err(...) __VA_OPT__\n"
"(something)\n"
"err()";
ASSERT_EQUALS("", preprocess(code2, &outputList));
ASSERT_EQUALS("file0,1,syntax_error,failed to expand 'err', Missing parenthesis for __VA_OPT__(content)\n",
toString(outputList));
}
static void define_va_opt_4()
{
// missing parenthesis
const char code1[] = "#define err(...) __VA_OPT__ something\n"
"err()";
simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess(code1, &outputList));
ASSERT_EQUALS("file0,1,syntax_error,failed to expand 'err', Missing parenthesis for __VA_OPT__(content)\n",
toString(outputList));
outputList.clear();
// missing open parenthesis
const char code2[] = "#define err(...) __VA_OPT__ something)\n"
"err()";
ASSERT_EQUALS("", preprocess(code2, &outputList));
ASSERT_EQUALS("file0,1,syntax_error,failed to expand 'err', Missing parenthesis for __VA_OPT__(content)\n",
toString(outputList));
}
static void define_va_opt_5()
{
// parenthesis not directly proceeding __VA_OPT__
const char code[] = "#define err(...) __VA_OPT__ something (something)\n"
"err()";
simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess(code, &outputList));
ASSERT_EQUALS("file0,1,syntax_error,failed to expand 'err', Missing parenthesis for __VA_OPT__(content)\n",
toString(outputList));
}
static void define_ifdef()
{
const char code[] = "#define A(X) X\n"
"A(1\n"
"#ifdef CFG\n"
"#endif\n"
")\n";
simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess(code, &outputList));
ASSERT_EQUALS("file0,3,syntax_error,failed to expand 'A', it is invalid to use a preprocessor directive as macro parameter\n", toString(outputList));
}
static void pragma_backslash()
{
const char code[] = "#pragma comment (longstring, \\\n"
"\"HEADER\\\n"
"This is a very long string that is\\\n"
"a multi-line string.\\\n"
"How much more do I have to say?\\\n"
"Well, be prepared, because the\\\n"
"story is just beginning. This is a test\\\n"
"string for demonstration purposes. \")\n";
simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess(code, &outputList));
}
static void dollar()
{
ASSERT_EQUALS("$ab", readfile("$ab"));
ASSERT_EQUALS("a$b", readfile("a$b"));
}
static void error1()
{
const char code[] = "#error hello world!\n";
simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess(code, &outputList));
ASSERT_EQUALS("file0,1,#error,#error hello world!\n", toString(outputList));
}
static void error2()
{
const char code[] = "#error it's an error\n";
simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess(code, &outputList));
ASSERT_EQUALS("file0,1,#error,#error it's an error\n", toString(outputList));
}
static void error3()
{
const char code[] = "#error \"bla bla\\\n"
" bla bla.\"\n";
std::vector<std::string> files;
simplecpp::OutputList outputList;
const simplecpp::TokenList rawtokens = makeTokenList(code, files, "test.c", &outputList);
ASSERT_EQUALS("", toString(outputList));
}
static void error4()
{
// "#error x\n1"
const char code[] = "\xFE\xFF\x00\x23\x00\x65\x00\x72\x00\x72\x00\x6f\x00\x72\x00\x20\x00\x78\x00\x0a\x00\x31";
std::vector<std::string> files;
std::map<std::string, simplecpp::TokenList*> filedata;
simplecpp::OutputList outputList;
simplecpp::TokenList tokens2(files);
const simplecpp::TokenList rawtoken = makeTokenList(code, sizeof(code),files,"test.c");
simplecpp::preprocess(tokens2, rawtoken, files, filedata, simplecpp::DUI(), &outputList);
ASSERT_EQUALS("file0,1,#error,#error x\n", toString(outputList));
}
static void error5()
{
// "#error x\n1"
const char code[] = "\xFF\xFE\x23\x00\x65\x00\x72\x00\x72\x00\x6f\x00\x72\x00\x20\x00\x78\x00\x0a\x00\x78\x00\x31\x00";
std::vector<std::string> files;