Skip to content

Commit 0d343c5

Browse files
committed
C#: Add external flow tests for synthetic fields.
1 parent 642ec38 commit 0d343c5

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,42 @@ void M2()
291291

292292
static void Sink(object o) { }
293293
}
294+
295+
// Test synthetic fields
296+
public class K {
297+
298+
public object MyField;
299+
300+
public void SetMySyntheticField(object o) => throw null;
301+
302+
public object GetMySyntheticField() => throw null;
303+
304+
public void SetMyNestedSyntheticField(object o) => throw null;
305+
306+
public object GetMyNestedSyntheticField() => throw null;
307+
308+
public void SetMyFieldOnSyntheticField(object o) => throw null;
309+
310+
public object GetMyFieldOnSyntheticField() => throw null;
311+
312+
public void M1() {
313+
var o = new object();
314+
SetMySyntheticField(o);
315+
Sink(GetMySyntheticField());
316+
}
317+
318+
public void M2() {
319+
var o = new object();
320+
SetMyNestedSyntheticField(o);
321+
Sink(GetMyNestedSyntheticField());
322+
}
323+
324+
public void M3() {
325+
var o = new object();
326+
SetMyFieldOnSyntheticField(o);
327+
Sink(GetMyFieldOnSyntheticField());
328+
}
329+
330+
static void Sink(object o) { }
331+
}
294332
}

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ nodes
243243
subpaths
244244
| ExternalFlow.cs:84:29:84:32 | access to local variable objs : null [element] : Object | ExternalFlow.cs:84:35:84:35 | o : Object | ExternalFlow.cs:84:40:84:40 | access to parameter o : Object | ExternalFlow.cs:84:25:84:41 | call to method Map<Object,Object> : T[] [element] : Object |
245245
invalidModelRow
246+
| Unrecognized input specification "SyntheticField[My.Qltest.K.MySyntheticField1]" in summary model. |
247+
| Unrecognized input specification "SyntheticField[My.Qltest.K.MySyntheticField2]" in summary model. |
248+
| Unrecognized input specification "SyntheticField[My.Qltest.K.MySyntheticField]" in summary model. |
249+
| Unrecognized input specification "SyntheticField[MySyntheticField1.MyNestedSyntheticField]" in summary model. |
250+
| Unrecognized output specification "SyntheticField[My.Qltest.K.MySyntheticField1]" in summary model. |
251+
| Unrecognized output specification "SyntheticField[My.Qltest.K.MySyntheticField2]" in summary model. |
252+
| Unrecognized output specification "SyntheticField[My.Qltest.K.MySyntheticField]" in summary model. |
253+
| Unrecognized output specification "SyntheticField[MySyntheticField1.MyNestedSyntheticField]" in summary model. |
246254
#select
247255
| ExternalFlow.cs:10:18:10:33 | call to method StepArgRes | ExternalFlow.cs:9:27:9:38 | object creation of type Object : Object | ExternalFlow.cs:10:18:10:33 | call to method StepArgRes | $@ | ExternalFlow.cs:9:27:9:38 | object creation of type Object : Object | object creation of type Object : Object |
248256
| ExternalFlow.cs:18:18:18:24 | access to local variable argOut1 | ExternalFlow.cs:15:29:15:40 | object creation of type Object : Object | ExternalFlow.cs:18:18:18:24 | access to local variable argOut1 | $@ | ExternalFlow.cs:15:29:15:40 | object creation of type Object : Object | object creation of type Object : Object |

csharp/ql/test/library-tests/dataflow/external-models/ExternalFlow.ext.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ extensions:
3737
- ["My.Qltest", "J", false, "SetProp1", "(System.Object)", "", "Argument[0]", "Argument[this]", "value", "manual"]
3838
- ["My.Qltest", "J", false, "get_Prop2", "()", "", "Argument[this]", "ReturnValue", "value", "df-generated"]
3939
- ["My.Qltest", "J", false, "SetProp2", "(System.Object)", "", "Argument[0]", "Argument[this]", "value", "manual"]
40+
- ["My.Qltest", "K", false, "SetMySyntheticField", "(System.Object)", "", "Argument[0]", "Argument[this].SyntheticField[My.Qltest.K.MySyntheticField]", "value", "manual"]
41+
- ["My.Qltest", "K", false, "GetMySyntheticField", "()", "", "Argument[this].SyntheticField[My.Qltest.K.MySyntheticField]", "ReturnValue", "value", "manual"]
42+
- ["My.Qltest", "K", false, "SetMyNestedSyntheticField", "(System.Object)", "", "Argument[0]", "Argument[this].SyntheticField[My.Qltest.K.MySyntheticField1].SyntheticField[MySyntheticField1.MyNestedSyntheticField]", "value", "manual"]
43+
- ["My.Qltest", "K", false, "GetMyNestedSyntheticField", "()", "", "Argument[this].SyntheticField[My.Qltest.K.MySyntheticField1].SyntheticField[MySyntheticField1.MyNestedSyntheticField]", "ReturnValue", "value", "manual"]
44+
- ["My.Qltest", "K", false, "SetMyFieldOnSyntheticField", "(System.Object)", "", "Argument[0]", "Argument[this].SyntheticField[My.Qltest.K.MySyntheticField2].Field[My.Qltest.K.MyField]", "value", "manual"]
45+
- ["My.Qltest", "K", false, "GetMyFieldOnSyntheticField", "()", "", "Argument[this].SyntheticField[My.Qltest.K.MySyntheticField2].Field[My.Qltest.K.MyField]", "ReturnValue", "value", "manual"]
46+
4047
- addsTo:
4148
pack: codeql/csharp-all
4249
extensible: neutralModel

0 commit comments

Comments
 (0)