@@ -48,10 +48,21 @@ query TargetSummaryModelCsv getAParseFailure(string reason) {
48
48
)
49
49
}
50
50
51
+ private class CallableToTest extends Callable {
52
+ CallableToTest ( ) {
53
+ exists (
54
+ string namespace , string type , boolean subtypes , string name , string signature , string ext
55
+ |
56
+ summaryModel ( namespace , type , subtypes , name , signature , ext , _, _, _) and
57
+ this = interpretElement ( namespace , type , subtypes , name , signature , ext )
58
+ )
59
+ }
60
+ }
61
+
51
62
/**
52
63
* Returns type of parameter `i` of `callable`, including the type of `this` for parameter -1.
53
64
*/
54
- Type getParameterType ( Private :: External :: SummarizedCallableExternal callable , int i ) {
65
+ Type getParameterType ( CallableToTest callable , int i ) {
55
66
if i = - 1 then result = callable .getDeclaringType ( ) else result = callable .getParameterType ( i )
56
67
}
57
68
@@ -149,37 +160,45 @@ Type getRootSourceDeclaration(Type t) {
149
160
* from `input` to `output`). Usually there is one of these per CSV row (`row`), but there may be more if `row` describes more than one
150
161
* override or overload of a particular method, or if the input or output specifications cover more than one argument.
151
162
*/
152
- newtype TRowTestSnippet =
153
- MkSnippet (
154
- CsvRow row , Private :: External :: SummarizedCallableExternal callable , SummaryComponentStack input ,
155
- SummaryComponentStack output , boolean preservesValue
163
+ newtype TTestCase =
164
+ MkTestCase (
165
+ CallableToTest callable , SummaryComponentStack input , SummaryComponentStack output , string kind ,
166
+ string row
156
167
) {
157
- callable .propagatesFlowForRow ( input , output , preservesValue , row )
168
+ exists (
169
+ string namespace , string type , boolean subtypes , string name , string signature , string ext ,
170
+ string inputSpec , string outputSpec
171
+ |
172
+ summaryModel ( namespace , type , subtypes , name , signature , ext , inputSpec , outputSpec , kind , row ) and
173
+ callable = interpretElement ( namespace , type , subtypes , name , signature , ext ) and
174
+ Private:: External:: interpretSpec ( inputSpec , input ) and
175
+ Private:: External:: interpretSpec ( outputSpec , output )
176
+ )
158
177
}
159
178
160
179
/**
161
- * A test snippet (as `TRowTestSnippet `, except `baseInput` and `baseOutput` hold the bottom of the summary stacks
180
+ * A test snippet (as `TTestCase `, except `baseInput` and `baseOutput` hold the bottom of the summary stacks
162
181
* `input` and `output` respectively (hence, `baseInput` and `baseOutput` are parameters or return values).
163
182
*/
164
- class RowTestSnippet extends TRowTestSnippet {
165
- string row ;
166
- Private:: External:: SummarizedCallableExternal callable ;
183
+ class TestCase extends TTestCase {
184
+ CallableToTest callable ;
167
185
SummaryComponentStack input ;
168
186
SummaryComponentStack output ;
169
187
SummaryComponentStack baseInput ;
170
188
SummaryComponentStack baseOutput ;
171
- boolean preservesValue ;
189
+ string kind ;
190
+ string row ;
172
191
173
- RowTestSnippet ( ) {
174
- this = MkSnippet ( row , callable , input , output , preservesValue ) and
192
+ TestCase ( ) {
193
+ this = MkTestCase ( callable , input , output , kind , row ) and
175
194
baseInput = input .drop ( input .length ( ) - 1 ) and
176
195
baseOutput = output .drop ( output .length ( ) - 1 )
177
196
}
178
197
179
198
string toString ( ) {
180
199
result =
181
200
row + " / " + callable + " / " + input + " / " + output + " / " + baseInput + " / " +
182
- baseOutput + " / " + preservesValue
201
+ baseOutput + " / " + kind
183
202
}
184
203
185
204
/**
@@ -261,9 +280,9 @@ class RowTestSnippet extends TRowTestSnippet {
261
280
* Returns an inline test expectation appropriate to this CSV row.
262
281
*/
263
282
string getExpectation ( ) {
264
- preservesValue = true and result = "// $hasValueFlow"
283
+ kind = "value" and result = "// $hasValueFlow"
265
284
or
266
- preservesValue = false and result = "// $hasTaintFlow"
285
+ kind = "taint" and result = "// $hasTaintFlow"
267
286
}
268
287
269
288
/**
@@ -371,6 +390,26 @@ class RowTestSnippet extends TRowTestSnippet {
371
390
"(Object container) { return null; }"
372
391
}
373
392
393
+ /**
394
+ * Gets a string that specifies summary component `c` in a summary specification CSV row.
395
+ */
396
+ string getComponentSpec ( SummaryComponent c ) {
397
+ exists ( Content content |
398
+ c = SummaryComponent:: content ( content ) and
399
+ (
400
+ content instanceof ArrayContent and result = "ArrayElement"
401
+ or
402
+ content instanceof MapValueContent and result = "MapValue"
403
+ or
404
+ content instanceof MapKeyContent and result = "MapKey"
405
+ or
406
+ content instanceof CollectionContent and result = "Element"
407
+ or
408
+ result = "Field[" + content .( FieldContent ) .getField ( ) .getQualifiedName ( ) + "]"
409
+ )
410
+ )
411
+ }
412
+
374
413
/**
375
414
* Returns a CSV row describing a support method (`newWith` or `get` method) needed to set up the output for this test.
376
415
*
@@ -379,15 +418,15 @@ class RowTestSnippet extends TRowTestSnippet {
379
418
*/
380
419
string getASupportMethodModel ( ) {
381
420
exists ( SummaryComponent c , string contentSsvDescription |
382
- c = input .drop ( _) .head ( ) and c = Private :: External :: interpretComponent ( contentSsvDescription )
421
+ c = input .drop ( _) .head ( ) and contentSsvDescription = getComponentSpec ( c )
383
422
|
384
423
result =
385
424
"generatedtest;Test;false;newWith" + contentToken ( getContent ( c ) ) + ";;;Argument[0];" +
386
425
contentSsvDescription + " of ReturnValue;value"
387
426
)
388
427
or
389
428
exists ( SummaryComponent c , string contentSsvDescription |
390
- c = output .drop ( _) .head ( ) and c = Private :: External :: interpretComponent ( contentSsvDescription )
429
+ c = output .drop ( _) .head ( ) and contentSsvDescription = getComponentSpec ( c )
391
430
|
392
431
result =
393
432
"generatedtest;Test;false;get" + contentToken ( getContent ( c ) ) + ";;;" + contentSsvDescription
@@ -428,10 +467,10 @@ class RowTestSnippet extends TRowTestSnippet {
428
467
* Holds if type `t` does not clash with another type we want to import that has the same base name.
429
468
*/
430
469
predicate isImportable ( Type t ) {
431
- t = any ( RowTestSnippet r ) .getADesiredImport ( ) and
470
+ t = any ( TestCase tc ) .getADesiredImport ( ) and
432
471
t =
433
472
unique( Type sharesBaseName |
434
- sharesBaseName = any ( RowTestSnippet r ) .getADesiredImport ( ) and
473
+ sharesBaseName = any ( TestCase tc ) .getADesiredImport ( ) and
435
474
sharesBaseName .getName ( ) = t .getName ( )
436
475
|
437
476
sharesBaseName
@@ -444,7 +483,7 @@ predicate isImportable(Type t) {
444
483
* if we cannot import it due to a name clash.
445
484
*/
446
485
string getShortNameIfPossible ( Type t ) {
447
- getRootSourceDeclaration ( t ) = any ( RowTestSnippet r ) .getADesiredImport ( ) and
486
+ getRootSourceDeclaration ( t ) = any ( TestCase tc ) .getADesiredImport ( ) and
448
487
if t instanceof RefType
449
488
then
450
489
exists ( RefType replaced , string nestedName |
@@ -463,7 +502,7 @@ string getShortNameIfPossible(Type t) {
463
502
*/
464
503
string getAnImportStatement ( ) {
465
504
exists ( RefType t |
466
- t = any ( RowTestSnippet r ) .getADesiredImport ( ) and
505
+ t = any ( TestCase tc ) .getADesiredImport ( ) and
467
506
isImportable ( t ) and
468
507
t .getPackage ( ) .getName ( ) != "java.lang"
469
508
|
@@ -477,24 +516,24 @@ string getAnImportStatement() {
477
516
string getASupportMethod ( ) {
478
517
result = "Object source() { return null; }" or
479
518
result = "void sink(Object o) { }" or
480
- result = any ( RowTestSnippet r ) .getASupportMethod ( )
519
+ result = any ( TestCase tc ) .getASupportMethod ( )
481
520
}
482
521
483
522
/**
484
523
* Returns a CSV specification of the taint-/value-propagation behaviour of a test support method (`get` or `newWith` method).
485
524
*/
486
- query string getASupportMethodModel ( ) { result = any ( RowTestSnippet r ) .getASupportMethodModel ( ) }
525
+ query string getASupportMethodModel ( ) { result = any ( TestCase tc ) .getASupportMethodModel ( ) }
487
526
488
527
/**
489
- * Gets a Java file body testing all `CsvRow` instances in scope against whatever classes and methods they resolve against.
528
+ * Gets a Java file body testing all requested SSV rows against whatever classes and methods they resolve against.
490
529
*/
491
530
query string getTestCase ( ) {
492
531
result =
493
532
"package generatedtest;\n\n" + concat ( getAnImportStatement ( ) + "\n" ) +
494
- "\n//Test case generated by GenerateFlowTestCase.ql\npublic class Test {\n\n" +
533
+ "\n// Test case generated by GenerateFlowTestCase.ql\npublic class Test {\n\n" +
495
534
concat ( "\t" + getASupportMethod ( ) + "\n" ) + "\n\tpublic void test() {\n\n" +
496
535
concat ( string row , string snippet |
497
- snippet = any ( RowTestSnippet r ) .getATestSnippetForRow ( row )
536
+ snippet = any ( TestCase tc ) .getATestSnippetForRow ( row )
498
537
|
499
538
snippet order by row
500
539
) + "\n\t}\n\n}"
0 commit comments