FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppcheck/test/testlibrary.cpp at master · 2php/cppcheck · GitHub
2php
/
cppcheck
Public
forked from
cppcheck-opensource/cppcheck
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppcheck
/
test
/
testlibrary.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
918 lines (801 loc) · 41.6 KB
Breadcrumbs
cppcheck
/
test
/
testlibrary.cpp
Copy path
File metadata and controls
918 lines (801 loc) · 41.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2018 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#
include
"
errorlogger.h
"
#
include
"
library.h
"
#
include
"
settings.h
"
#
include
"
standards.h
"
#
include
"
testsuite.h
"
#
include
"
token.h
"
#
include
"
tokenize.h
"
#
include
"
tokenlist.h
"
#
include
<
tinyxml2.h
>
#
include
<
map
>
#
include
<
set
>
#
include
<
string
>
#
include
<
vector
>
class
TestLibrary
:
public
TestFixture
{
public:
TestLibrary
() : TestFixture(
"
TestLibrary
"
) { }
private:
Settings settings;
void
run
()
override
{
TEST_CASE
(empty);
TEST_CASE
(function);
TEST_CASE
(function_match_scope);
TEST_CASE
(function_match_args);
TEST_CASE
(function_match_args_default);
TEST_CASE
(function_match_var);
TEST_CASE
(function_arg);
TEST_CASE
(function_arg_any);
TEST_CASE
(function_arg_variadic);
TEST_CASE
(function_arg_valid);
TEST_CASE
(function_arg_minsize);
TEST_CASE
(function_namespace);
TEST_CASE
(function_method);
TEST_CASE
(function_baseClassMethod);
//
calling method in base class
TEST_CASE
(function_warn);
TEST_CASE
(memory);
TEST_CASE
(memory2);
//
define extra "free" allocation functions
TEST_CASE
(memory3);
TEST_CASE
(resource);
TEST_CASE
(podtype);
TEST_CASE
(container);
TEST_CASE
(version);
TEST_CASE
(loadLibErrors);
}
static
Library::Error
readLibrary
(Library& library,
const
char
* xmldata) {
tinyxml2::XMLDocument doc;
doc.
Parse
(xmldata);
return
library.
load
(doc);
}
void
empty
()
const
{
//
Reading an empty library file is considered to be OK
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
<def/>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT
(library.
functions
.
empty
());
}
void
function
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
foo
\"
>
\n
"
"
<noreturn>false</noreturn>
\n
"
"
</function>
\n
"
"
</def>
"
;
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
foo();
"
);
tokenList.
createTokens
(istr);
tokenList.
front
()->
next
()->
astOperand1
(tokenList.
front
());
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT_EQUALS
(library.
functions
.
size
(),
1U
);
ASSERT
(library.
functions
.
at
(
"
foo
"
).
argumentChecks
.
empty
());
ASSERT
(library.
isnotnoreturn
(tokenList.
front
()));
}
void
function_match_scope
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
foo
\"
>
\n
"
"
<arg nr=
\"
1
\"
/>
"
"
</function>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
{
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
fred.foo(123);
"
);
//
<- wrong scope, not library function
tokenList.
createTokens
(istr);
ASSERT
(library.
isNotLibraryFunction
(tokenList.
front
()->
tokAt
(
2
)));
}
{
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
Fred::foo(123);
"
);
//
<- wrong scope, not library function
tokenList.
createTokens
(istr);
ASSERT
(library.
isNotLibraryFunction
(tokenList.
front
()->
tokAt
(
2
)));
}
}
void
function_match_args
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
foo
\"
>
\n
"
"
<arg nr=
\"
1
\"
/>
"
"
</function>
\n
"
"
</def>
"
;
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
foo();
"
);
//
<- too few arguments, not library function
tokenList.
createTokens
(istr);
Token::createMutualLinks
(tokenList.
front
()->
next
(), tokenList.
back
()->
previous
());
tokenList.
createAst
();
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT
(library.
isNotLibraryFunction
(tokenList.
front
()));
}
void
function_match_args_default
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
foo
\"
>
\n
"
"
<arg nr=
\"
1
\"
/>
"
"
<arg nr=
\"
2
\"
default=
\"
0
\"
/>
"
"
</function>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
{
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
foo();
"
);
//
<- too few arguments, not library function
tokenList.
createTokens
(istr);
Token::createMutualLinks
(tokenList.
front
()->
next
(), tokenList.
back
()->
previous
());
tokenList.
createAst
();
ASSERT
(library.
isNotLibraryFunction
(tokenList.
front
()));
}
{
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
foo(a);
"
);
//
<- library function
tokenList.
createTokens
(istr);
Token::createMutualLinks
(tokenList.
front
()->
next
(), tokenList.
back
()->
previous
());
tokenList.
createAst
();
ASSERT
(!library.
isNotLibraryFunction
(tokenList.
front
()));
}
{
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
foo(a, b);
"
);
//
<- library function
tokenList.
createTokens
(istr);
Token::createMutualLinks
(tokenList.
front
()->
next
(), tokenList.
back
()->
previous
());
tokenList.
createAst
();
ASSERT
(!library.
isNotLibraryFunction
(tokenList.
front
()));
}
{
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
foo(a, b, c);
"
);
//
<- too much arguments, not library function
tokenList.
createTokens
(istr);
Token::createMutualLinks
(tokenList.
front
()->
next
(), tokenList.
back
()->
previous
());
tokenList.
createAst
();
ASSERT
(library.
isNotLibraryFunction
(tokenList.
front
()));
}
}
void
function_match_var
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
foo
\"
>
\n
"
"
<arg nr=
\"
1
\"
/>
"
"
</function>
\n
"
"
</def>
"
;
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
Fred foo(123);
"
);
//
<- Variable declaration, not library function
tokenList.
createTokens
(istr);
tokenList.
front
()->
next
()->
astOperand1
(tokenList.
front
());
tokenList.
front
()->
next
()->
varId
(
1
);
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT
(library.
isNotLibraryFunction
(tokenList.
front
()->
next
()));
}
void
function_arg
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
foo
\"
>
\n
"
"
<arg nr=
\"
1
\"
><not-uninit/></arg>
\n
"
"
<arg nr=
\"
2
\"
><not-null/></arg>
\n
"
"
<arg nr=
\"
3
\"
><formatstr/></arg>
\n
"
"
<arg nr=
\"
4
\"
><strz/></arg>
\n
"
"
<arg nr=
\"
5
\"
default=
\"
0
\"
><not-bool/></arg>
\n
"
"
</function>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT_EQUALS
(
true
, library.
functions
[
"
foo
"
].
argumentChecks
[
1
].
notuninit
);
ASSERT_EQUALS
(
true
, library.
functions
[
"
foo
"
].
argumentChecks
[
2
].
notnull
);
ASSERT_EQUALS
(
true
, library.
functions
[
"
foo
"
].
argumentChecks
[
3
].
formatstr
);
ASSERT_EQUALS
(
true
, library.
functions
[
"
foo
"
].
argumentChecks
[
4
].
strz
);
ASSERT_EQUALS
(
false
, library.
functions
[
"
foo
"
].
argumentChecks
[
4
].
optional
);
ASSERT_EQUALS
(
true
, library.
functions
[
"
foo
"
].
argumentChecks
[
5
].
notbool
);
ASSERT_EQUALS
(
true
, library.
functions
[
"
foo
"
].
argumentChecks
[
5
].
optional
);
}
void
function_arg_any
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
foo
\"
>
\n
"
"
<arg nr=
\"
any
\"
><not-uninit/></arg>
\n
"
"
</function>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT_EQUALS
(
true
, library.
functions
[
"
foo
"
].
argumentChecks
[-
1
].
notuninit
);
}
void
function_arg_variadic
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
foo
\"
>
\n
"
"
<arg nr=
\"
1
\"
></arg>
\n
"
"
<arg nr=
\"
variadic
\"
><not-uninit/></arg>
\n
"
"
</function>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT_EQUALS
(
true
, library.
functions
[
"
foo
"
].
argumentChecks
[-
1
].
notuninit
);
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
foo(a,b,c,d,e);
"
);
tokenList.
createTokens
(istr);
tokenList.
front
()->
next
()->
astOperand1
(tokenList.
front
());
ASSERT_EQUALS
(
false
, library.
isuninitargbad
(tokenList.
front
(),
1
));
ASSERT_EQUALS
(
true
, library.
isuninitargbad
(tokenList.
front
(),
2
));
ASSERT_EQUALS
(
true
, library.
isuninitargbad
(tokenList.
front
(),
3
));
ASSERT_EQUALS
(
true
, library.
isuninitargbad
(tokenList.
front
(),
4
));
}
void
function_arg_valid
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
foo
\"
>
\n
"
"
<arg nr=
\"
1
\"
><valid>1:</valid></arg>
\n
"
"
<arg nr=
\"
2
\"
><valid>-7:0</valid></arg>
\n
"
"
<arg nr=
\"
3
\"
><valid>1:5,8</valid></arg>
\n
"
"
<arg nr=
\"
4
\"
><valid>-1,5</valid></arg>
\n
"
"
<arg nr=
\"
5
\"
><valid>:1,5</valid></arg>
\n
"
"
<arg nr=
\"
6
\"
><valid>1.5:</valid></arg>
\n
"
"
<arg nr=
\"
7
\"
><valid>-6.7:-5.5,-3.3:-2.7</valid></arg>
\n
"
"
<arg nr=
\"
8
\"
><valid>0.0:</valid></arg>
\n
"
"
<arg nr=
\"
9
\"
><valid>:2.0</valid></arg>
\n
"
"
<arg nr=
\"
10
\"
><valid>0.0</valid></arg>
\n
"
"
</function>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
foo(a,b,c,d,e,f,g,h,i,j);
"
);
tokenList.
createTokens
(istr);
tokenList.
front
()->
next
()->
astOperand1
(tokenList.
front
());
//
1-
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
1
, -
10
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
1
, -
10.0
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
1
,
0
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
1
,
0.0
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
1
,
1
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
1
,
1.0
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
1
,
10
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
1
,
10.0
));
//
-7-0
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
2
, -
10
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
2
, -
10.0
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
2
, -
7.5
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
2
, -
7.1
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
2
, -
7
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
2
, -
7.0
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
2
, -
3
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
2
, -
3.0
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
2
, -
3.5
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
2
,
0
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
2
,
0.0
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
2
,
0.5
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
2
,
1
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
2
,
1.0
));
//
1-5,8
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
3
,
0
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
3
,
0.0
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
3
,
1
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
3
,
1.0
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
3
,
3
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
3
,
3.0
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
3
,
5
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
3
,
5.0
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
3
,
6
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
3
,
6.0
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
3
,
7
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
3
,
7.0
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
3
,
8
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
3
,
8.0
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
3
,
9
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
3
,
9.0
));
//
-1,5
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
4
, -
10
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
4
, -
10.0
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
4
, -
1
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
4
, -
1.0
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
4
,
5.000001
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
4
,
5.5
));
//
:1,5
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
5
, -
10
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
5
, -
10.0
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
5
,
1
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
5
,
1.0
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
5
,
2
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
5
,
2.0
));
//
1.5:
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
6
,
0
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
6
,
0.0
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
6
,
1
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
6
,
1.499999
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
6
,
1.5
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
6
,
2
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
6
,
10
));
//
-6.7:-5.5,-3.3:-2.7
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
7
, -
7
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
7.0
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
6.7000001
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
6.7
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
7
, -
6
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
6.0
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
5.5
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
5.4999999
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
3.3000001
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
3.3
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
7
, -
3
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
3.0
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
2.7
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
2.6999999
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
7
, -
2
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
7
, -
2.0
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
7
,
0
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
7
,
0.0
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
7
,
3
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
7
,
3.0
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
7
,
6
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
7
,
6.0
));
//
0.0:
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
8
, -
1
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
8
, -
1.0
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
8
, -
0.00000001
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
8
,
0
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
8
,
0.0
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
8
,
0.000000001
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
8
,
1
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
8
,
1.0
));
//
:2.0
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
9
, -
1
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
9
, -
1.0
));
ASSERT_EQUALS
(
true
, library.
isIntArgValid
(tokenList.
front
(),
9
,
2
));
ASSERT_EQUALS
(
true
, library.
isFloatArgValid
(tokenList.
front
(),
9
,
2.0
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
9
,
2.00000001
));
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
9
,
200
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
9
,
200.0
));
//
0.0
ASSERT_EQUALS
(
false
, library.
isIntArgValid
(tokenList.
front
(),
10
,
0
));
ASSERT_EQUALS
(
false
, library.
isFloatArgValid
(tokenList.
front
(),
10
,
0.0
));
}
void
function_arg_minsize
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
foo
\"
>
\n
"
"
<arg nr=
\"
1
\"
><minsize type=
\"
strlen
\"
arg=
\"
2
\"
/></arg>
\n
"
"
<arg nr=
\"
2
\"
><minsize type=
\"
argvalue
\"
arg=
\"
3
\"
/></arg>
\n
"
"
<arg nr=
\"
3
\"
/>
\n
"
"
</function>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
foo(a,b,c);
"
);
tokenList.
createTokens
(istr);
tokenList.
front
()->
next
()->
astOperand1
(tokenList.
front
());
//
arg1: type=strlen arg2
const
std::vector<Library::ArgumentChecks::MinSize> *minsizes = library.
argminsizes
(tokenList.
front
(),
1
);
ASSERT_EQUALS
(
true
, minsizes !=
nullptr
);
ASSERT_EQUALS
(
1U
, minsizes ? minsizes->
size
() :
1U
);
if
(minsizes && minsizes->
size
() ==
1U
) {
const
Library::ArgumentChecks::MinSize &m = minsizes->
front
();
ASSERT_EQUALS
(Library::ArgumentChecks::MinSize::
STRLEN
, m.
type
);
ASSERT_EQUALS
(
2
, m.
arg
);
}
//
arg2: type=argvalue arg3
minsizes = library.
argminsizes
(tokenList.
front
(),
2
);
ASSERT_EQUALS
(
true
, minsizes !=
nullptr
);
ASSERT_EQUALS
(
1U
, minsizes ? minsizes->
size
() :
1U
);
if
(minsizes && minsizes->
size
() ==
1U
) {
const
Library::ArgumentChecks::MinSize &m = minsizes->
front
();
ASSERT_EQUALS
(Library::ArgumentChecks::MinSize::
ARGVALUE
, m.
type
);
ASSERT_EQUALS
(
3
, m.
arg
);
}
}
void
function_namespace
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
Foo::foo,bar
\"
>
\n
"
"
<noreturn>false</noreturn>
\n
"
"
</function>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT_EQUALS
(library.
functions
.
size
(),
2U
);
ASSERT
(library.
functions
.
at
(
"
Foo::foo
"
).
argumentChecks
.
empty
());
ASSERT
(library.
functions
.
at
(
"
bar
"
).
argumentChecks
.
empty
());
{
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
Foo::foo();
"
);
tokenList.
createTokens
(istr);
ASSERT
(library.
isnotnoreturn
(tokenList.
front
()->
tokAt
(
2
)));
}
{
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
bar();
"
);
tokenList.
createTokens
(istr);
ASSERT
(library.
isnotnoreturn
(tokenList.
front
()));
}
}
void
function_method
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
CString::Format
\"
>
\n
"
"
<noreturn>false</noreturn>
\n
"
"
</function>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT_EQUALS
(library.
functions
.
size
(),
1U
);
{
Tokenizer
tokenizer
(&settings,
nullptr
);
std::istringstream
istr
(
"
CString str; str.Format();
"
);
tokenizer.
tokenize
(istr,
"
test.cpp
"
);
ASSERT
(library.
isnotnoreturn
(
Token::findsimplematch
(tokenizer.
tokens
(),
"
Format
"
)));
}
{
Tokenizer
tokenizer
(&settings,
nullptr
);
std::istringstream
istr
(
"
HardDrive hd; hd.Format();
"
);
tokenizer.
tokenize
(istr,
"
test.cpp
"
);
ASSERT
(!library.
isnotnoreturn
(
Token::findsimplematch
(tokenizer.
tokens
(),
"
Format
"
)));
}
}
void
function_baseClassMethod
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
Base::f
\"
>
\n
"
"
<arg nr=
\"
1
\"
><not-null/></arg>
\n
"
"
</function>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
{
Tokenizer
tokenizer
(&settings,
nullptr
);
std::istringstream
istr
(
"
struct X : public Base { void dostuff() { f(0); } };
"
);
tokenizer.
tokenize
(istr,
"
test.cpp
"
);
ASSERT
(library.
isnullargbad
(
Token::findsimplematch
(tokenizer.
tokens
(),
"
f
"
),
1
));
}
{
Tokenizer
tokenizer
(&settings,
nullptr
);
std::istringstream
istr
(
"
struct X : public Base { void dostuff() { f(1,2); } };
"
);
tokenizer.
tokenize
(istr,
"
test.cpp
"
);
ASSERT
(!library.
isnullargbad
(
Token::findsimplematch
(tokenizer.
tokens
(),
"
f
"
),
1
));
}
}
void
function_warn
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<function name=
\"
a
\"
>
\n
"
"
<warn severity=
\"
style
\"
cstd=
\"
c99
\"
>Message</warn>
\n
"
"
</function>
\n
"
"
<function name=
\"
b
\"
>
\n
"
"
<warn severity=
\"
performance
\"
cppstd=
\"
c++11
\"
reason=
\"
Obsolescent
\"
alternatives=
\"
c,d,e
\"
/>
\n
"
"
</function>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
TokenList
tokenList
(
nullptr
);
std::istringstream
istr
(
"
a(); b();
"
);
tokenList.
createTokens
(istr);
const
Library::WarnInfo* a = library.
getWarnInfo
(tokenList.
front
());
const
Library::WarnInfo* b = library.
getWarnInfo
(tokenList.
front
()->
tokAt
(
4
));
ASSERT_EQUALS
(
2
, library.
functionwarn
.
size
());
ASSERT
(a && b);
if
(a && b) {
ASSERT_EQUALS
(
"
Message
"
, a->
message
);
ASSERT_EQUALS
(Severity::style, a->
severity
);
ASSERT_EQUALS
(Standards::
C99
, a->
standards
.
c
);
ASSERT_EQUALS
(Standards::
CPP03
, a->
standards
.
cpp
);
ASSERT_EQUALS
(
"
Obsolescent function 'b' called. It is recommended to use 'c', 'd' or 'e' instead.
"
, b->
message
);
ASSERT_EQUALS
(Severity::performance, b->
severity
);
ASSERT_EQUALS
(Standards::
C89
, b->
standards
.
c
);
ASSERT_EQUALS
(Standards::
CPP11
, b->
standards
.
cpp
);
}
}
void
memory
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<memory>
\n
"
"
<alloc>CreateX</alloc>
\n
"
"
<dealloc>DeleteX</dealloc>
\n
"
"
</memory>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT
(library.
functions
.
empty
());
ASSERT
(
Library::ismemory
(library.
alloc
(
"
CreateX
"
)));
ASSERT_EQUALS
(library.
allocId
(
"
CreateX
"
), library.
deallocId
(
"
DeleteX
"
));
const
Library::AllocFunc* af = library.
alloc
(
"
CreateX
"
);
ASSERT
(af && af->
arg
== -
1
);
const
Library::AllocFunc* df = library.
dealloc
(
"
DeleteX
"
);
ASSERT
(df && df->
arg
==
1
);
}
void
memory2
()
const
{
const
char
xmldata1[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<memory>
\n
"
"
<alloc>malloc</alloc>
\n
"
"
<dealloc>free</dealloc>
\n
"
"
</memory>
\n
"
"
</def>
"
;
const
char
xmldata2[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<memory>
\n
"
"
<alloc>foo</alloc>
\n
"
"
<dealloc>free</dealloc>
\n
"
"
</memory>
\n
"
"
</def>
"
;
Library library;
library.
loadxmldata
(xmldata1,
sizeof
(xmldata1));
library.
loadxmldata
(xmldata2,
sizeof
(xmldata2));
ASSERT_EQUALS
(library.
deallocId
(
"
free
"
), library.
allocId
(
"
malloc
"
));
ASSERT_EQUALS
(library.
deallocId
(
"
free
"
), library.
allocId
(
"
foo
"
));
}
void
memory3
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<memory>
\n
"
"
<alloc arg=
\"
5
\"
init=
\"
false
\"
>CreateX</alloc>
\n
"
"
<dealloc arg=
\"
2
\"
>DeleteX</dealloc>
\n
"
"
</memory>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT
(library.
functions
.
empty
());
const
Library::AllocFunc* af = library.
alloc
(
"
CreateX
"
);
ASSERT
(af && af->
arg
==
5
);
const
Library::AllocFunc* df = library.
dealloc
(
"
DeleteX
"
);
ASSERT
(df && df->
arg
==
2
);
ASSERT
(library.
returnuninitdata
.
find
(
"
CreateX
"
) != library.
returnuninitdata
.
cend
());
}
void
resource
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<resource>
\n
"
"
<alloc>CreateX</alloc>
\n
"
"
<dealloc>DeleteX</dealloc>
\n
"
"
</resource>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
ASSERT
(library.
functions
.
empty
());
ASSERT
(
Library::isresource
(library.
allocId
(
"
CreateX
"
)));
ASSERT_EQUALS
(library.
allocId
(
"
CreateX
"
), library.
deallocId
(
"
DeleteX
"
));
}
void
podtype
()
const
{
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<podtype name=
\"
s8
\"
sign=
\"
s
\"
size=
\"
1
\"
/>
\n
"
"
<podtype name=
\"
u8
\"
sign=
\"
u
\"
size=
\"
1
\"
/>
\n
"
"
<podtype name=
\"
u16
\"
sign=
\"
u
\"
size=
\"
2
\"
/>
\n
"
"
<podtype name=
\"
s16
\"
sign=
\"
s
\"
size=
\"
2
\"
/>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
//
s8
{
const
struct
Library
::PodType *
const
type = library.
podtype
(
"
s8
"
);
ASSERT_EQUALS
(
true
, type !=
0
);
if
(type) {
ASSERT_EQUALS
(
1U
, type->
size
);
ASSERT_EQUALS
(
'
s
'
, type->
sign
);
}
}
//
u8
{
const
struct
Library
::PodType *
const
type = library.
podtype
(
"
u8
"
);
ASSERT_EQUALS
(
true
, type !=
0
);
if
(type) {
ASSERT_EQUALS
(
1U
, type->
size
);
ASSERT_EQUALS
(
'
u
'
, type->
sign
);
}
}
//
u16
{
const
struct
Library
::PodType *
const
type = library.
podtype
(
"
u16
"
);
ASSERT_EQUALS
(
true
, type !=
0
);
if
(type) {
ASSERT_EQUALS
(
2U
, type->
size
);
ASSERT_EQUALS
(
'
u
'
, type->
sign
);
}
}
//
s16
{
const
struct
Library
::PodType *
const
type = library.
podtype
(
"
s16
"
);
ASSERT_EQUALS
(
true
, type !=
0
);
if
(type) {
ASSERT_EQUALS
(
2U
, type->
size
);
ASSERT_EQUALS
(
'
s
'
, type->
sign
);
}
}
//
robustness test: provide cfg without PodType
{
const
struct
Library
::PodType *
const
type = library.
podtype
(
"
nonExistingPodType
"
);
ASSERT_EQUALS
(
true
, type ==
0
);
}
}
}
void
container
()
const
{
const
char
xmldata[] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<container id=
\"
A
\"
startPattern=
\"
std :: A <
\"
endPattern=
\"
> !!::
\"
itEndPattern=
\"
> :: iterator
\"
>
\n
"
"
<type templateParameter=
\"
1
\"
/>
\n
"
"
<size templateParameter=
\"
4
\"
>
\n
"
"
<function name=
\"
resize
\"
action=
\"
resize
\"
/>
\n
"
"
<function name=
\"
clear
\"
action=
\"
clear
\"
/>
\n
"
"
<function name=
\"
size
\"
yields=
\"
size
\"
/>
\n
"
"
<function name=
\"
empty
\"
yields=
\"
empty
\"
/>
\n
"
"
<function name=
\"
push_back
\"
action=
\"
push
\"
/>
\n
"
"
<function name=
\"
pop_back
\"
action=
\"
pop
\"
/>
\n
"
"
</size>
\n
"
"
<access>
\n
"
"
<function name=
\"
at
\"
yields=
\"
at_index
\"
/>
\n
"
"
<function name=
\"
begin
\"
yields=
\"
start-iterator
\"
/>
\n
"
"
<function name=
\"
end
\"
yields=
\"
end-iterator
\"
/>
\n
"
"
<function name=
\"
data
\"
yields=
\"
buffer
\"
/>
\n
"
"
<function name=
\"
c_str
\"
yields=
\"
buffer-nt
\"
/>
\n
"
"
<function name=
\"
front
\"
yields=
\"
item
\"
/>
\n
"
"
<function name=
\"
find
\"
action=
\"
find
\"
/>
\n
"
"
</access>
\n
"
"
</container>
\n
"
"
<container id=
\"
B
\"
startPattern=
\"
std :: B <
\"
inherits=
\"
A
\"
opLessAllowed=
\"
false
\"
>
\n
"
"
<size templateParameter=
\"
3
\"
/>
\n
"
//
Inherits all but templateParameter
"
</container>
\n
"
"
<container id=
\"
C
\"
>
\n
"
"
<type string=
\"
std-like
\"
/>
\n
"
"
<access indexOperator=
\"
array-like
\"
/>
\n
"
"
</container>
\n
"
"
</def>
"
;
Library library;
ASSERT_EQUALS
(
true
, Library::
OK
== (
readLibrary
(library, xmldata)).
errorcode
);
Library::Container& A = library.
containers
[
"
A
"
];
Library::Container& B = library.
containers
[
"
B
"
];
Library::Container& C = library.
containers
[
"
C
"
];
ASSERT_EQUALS
(A.
type_templateArgNo
,
1
);
ASSERT_EQUALS
(A.
size_templateArgNo
,
4
);
ASSERT_EQUALS
(A.
startPattern
,
"
std :: A <
"
);
ASSERT_EQUALS
(A.
endPattern
,
"
> !!::
"
);
ASSERT_EQUALS
(A.
itEndPattern
,
"
> :: iterator
"
);
ASSERT_EQUALS
(A.
stdStringLike
,
false
);
ASSERT_EQUALS
(A.
arrayLike_indexOp
,
false
);
ASSERT_EQUALS
(A.
opLessAllowed
,
true
);
ASSERT_EQUALS
(Library::Container::
SIZE
, A.
getYield
(
"
size
"
));
ASSERT_EQUALS
(Library::Container::
EMPTY
, A.
getYield
(
"
empty
"
));
ASSERT_EQUALS
(Library::Container::
AT_INDEX
, A.
getYield
(
"
at
"
));
ASSERT_EQUALS
(Library::Container::
START_ITERATOR
, A.
getYield
(
"
begin
"
));
ASSERT_EQUALS
(Library::Container::
END_ITERATOR
, A.
getYield
(
"
end
"
));
ASSERT_EQUALS
(Library::Container::
BUFFER
, A.
getYield
(
"
data
"
));
ASSERT_EQUALS
(Library::Container::
BUFFER_NT
, A.
getYield
(
"
c_str
"
));
ASSERT_EQUALS
(Library::Container::
ITEM
, A.
getYield
(
"
front
"
));
ASSERT_EQUALS
(Library::Container::
NO_YIELD
, A.
getYield
(
"
foo
"
));
ASSERT_EQUALS
(Library::Container::
RESIZE
, A.
getAction
(
"
resize
"
));
ASSERT_EQUALS
(Library::Container::
CLEAR
, A.
getAction
(
"
clear
"
));
ASSERT_EQUALS
(Library::Container::
PUSH
, A.
getAction
(
"
push_back
"
));
ASSERT_EQUALS
(Library::Container::
POP
, A.
getAction
(
"
pop_back
"
));
ASSERT_EQUALS
(Library::Container::
FIND
, A.
getAction
(
"
find
"
));
ASSERT_EQUALS
(Library::Container::
NO_ACTION
, A.
getAction
(
"
foo
"
));
ASSERT_EQUALS
(B.
type_templateArgNo
,
1
);
ASSERT_EQUALS
(B.
size_templateArgNo
,
3
);
ASSERT_EQUALS
(B.
startPattern
,
"
std :: B <
"
);
ASSERT_EQUALS
(B.
endPattern
,
"
> !!::
"
);
ASSERT_EQUALS
(B.
itEndPattern
,
"
> :: iterator
"
);
ASSERT_EQUALS
(B.
functions
.
size
(), A.
functions
.
size
());
ASSERT_EQUALS
(B.
opLessAllowed
,
false
);
ASSERT
(C.
functions
.
empty
());
ASSERT_EQUALS
(C.
type_templateArgNo
, -
1
);
ASSERT_EQUALS
(C.
size_templateArgNo
, -
1
);
ASSERT_EQUALS
(C.
stdStringLike
,
true
);
ASSERT_EQUALS
(C.
arrayLike_indexOp
,
true
);
}
void
version
()
const
{
{
const
char
xmldata [] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
</def>
"
;
Library library;
const
Library::Error err =
readLibrary
(library, xmldata);
ASSERT_EQUALS
(err.
errorcode
, Library::
OK
);
}
{
const
char
xmldata [] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def format=
\"
1
\"
>
\n
"
"
</def>
"
;
Library library;
const
Library::Error err =
readLibrary
(library, xmldata);
ASSERT_EQUALS
(err.
errorcode
, Library::
OK
);
}
{
const
char
xmldata [] =
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def format=
\"
42
\"
>
\n
"
"
</def>
"
;
Library library;
const
Library::Error err =
readLibrary
(library, xmldata);
ASSERT_EQUALS
(err.
errorcode
, Library::
UNSUPPORTED_FORMAT
);
}
}
void
loadLibError
(
const
char
xmldata [], Library::ErrorCode errorcode,
const
char
* file,
unsigned
line)
const
{
Library library;
assertEquals
(file, line, errorcode,
readLibrary
(library, xmldata).
errorcode
);
}
#
define
LOADLIBERROR
(
xmldata, errorcode
) loadLibError(xmldata, errorcode, __FILE__, __LINE__)
#
define
LOADLIB_ERROR_INVALID_RANGE
(
valid
)
LOADLIBERROR
(
"
<?xml version=
\"
1.0
\"
?>
\n
"
\
"
<def>
\n
"
\
"
<function name=
\"
f
\"
>
\n
"
\
"
<arg nr=
\"
1
\"
>
\n
"
\
"
<valid>
"
valid
"
</valid>
\n
"
\
"
</arg>
\n
"
\
"
</function>
\n
"
\
"
</def>
"
, \
Library::
BAD_ATTRIBUTE_VALUE
)
void
loadLibErrors
()
const
{
LOADLIBERROR
(
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<X name=
\"
uint8_t,std::uint8_t
\"
size=
\"
1
\"
/>
\n
"
"
</def>
"
,
Library::
UNKNOWN_ELEMENT
);
//
#define without attributes
LOADLIBERROR
(
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<define />
\n
"
//
no attributes provided at all
"
</def>
"
,
Library::
MISSING_ATTRIBUTE
);
//
#define with name but without value
LOADLIBERROR
(
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<define name=
\"
foo
\"
/>
\n
"
//
no value provided
"
</def>
"
,
Library::
MISSING_ATTRIBUTE
);
LOADLIBERROR
(
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<def>
\n
"
"
<define value=
\"
1
\"
/>
\n
"
//
no name provided
"
</def>
"
,
Library::
MISSING_ATTRIBUTE
);
LOADLIBERROR
(
"
<?xml version=
\"
1.0
\"
?>
\n
"
"
<X>
\n
"
"
</X>
"
,
Library::
UNSUPPORTED_FORMAT
);
//
empty range
LOADLIB_ERROR_INVALID_RANGE
(
"
"
);
//
letter as range
LOADLIB_ERROR_INVALID_RANGE
(
"
a
"
);
//
letter and number as range
LOADLIB_ERROR_INVALID_RANGE
(
"
1a
"
);
//
digit followed by dash
LOADLIB_ERROR_INVALID_RANGE
(
"
0:2-1
"
);
//
single dash
LOADLIB_ERROR_INVALID_RANGE
(
"
-
"
);
//
range with multiple colons
LOADLIB_ERROR_INVALID_RANGE
(
"
1:2:3
"
);
//
extra dot
LOADLIB_ERROR_INVALID_RANGE
(
"
1.0.0:10
"
);
//
consecutive dots
LOADLIB_ERROR_INVALID_RANGE
(
"
1..0:10
"
);
//
dot followed by dash
LOADLIB_ERROR_INVALID_RANGE
(
"
1.-0:10
"
);
//
dot without preceding number
LOADLIB_ERROR_INVALID_RANGE
(
"
.5:10
"
);
//
dash followed by dot
LOADLIB_ERROR_INVALID_RANGE
(
"
-.5:10
"
);
//
colon followed by dot without preceding number
LOADLIB_ERROR_INVALID_RANGE
(
"
0:.5
"
);
//
colon followed by dash followed by dot
LOADLIB_ERROR_INVALID_RANGE
(
"
-10:-.5
"
);
//
dot not followed by number
LOADLIB_ERROR_INVALID_RANGE
(
"
1:5.
"
);
//
dot not followed by number
LOADLIB_ERROR_INVALID_RANGE
(
"
1.:5
"
);
//
dot followed by comma
LOADLIB_ERROR_INVALID_RANGE
(
"
1:5.,6:10
"
);
//
comma followed by dot
LOADLIB_ERROR_INVALID_RANGE
(
"
-10:0,.5:
"
);
}
};
REGISTER_TEST
(TestLibrary)
Back
|
FazBrowse Home
|
New Git URL