Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba23857

Browse files
committed
Add stubbing tests
1 parent 7e7a52d commit ba23857

9 files changed

Lines changed: 152 additions & 5 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Tool to generate C# stubs from a qltest snapshot.
3+
*/
4+
5+
import csharp
6+
import Stubs
7+
8+
/** All public declarations from source. */
9+
class AllDeclarations extends GeneratedDeclaration {
10+
AllDeclarations() { not this.fromLibrary() }
11+
}
12+
13+
select generatedCode()

csharp/ql/src/Stubs/Stubs.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ abstract private class GeneratedType extends ValueOrRefType, GeneratedElement {
3434
this instanceof DelegateType
3535
) and
3636
not this instanceof ConstructedType and
37-
not this.getALocation() instanceof ExcludedAssembly and
38-
this.fromLibrary()
37+
not this.getALocation() instanceof ExcludedAssembly
3938
}
4039

4140
/**
@@ -103,7 +102,8 @@ abstract private class GeneratedType extends ValueOrRefType, GeneratedElement {
103102
private ValueOrRefType getAnInterestingBaseType() {
104103
result = this.getABaseType() and
105104
not result instanceof ObjectType and
106-
not result.getQualifiedName() = "System.ValueType"
105+
not result.getQualifiedName() = "System.ValueType" and
106+
(not result instanceof Interface or result.(Interface).isEffectivelyPublic())
107107
}
108108

109109
private string stubBaseTypesString() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| // This file contains auto-generated code.\n\nnamespace Test\n{\n// Generated from `Test.Class1` in `Test.cs:3:18:3:23`\npublic class Class1\n{\n public Class1() => throw null;\n// Generated from `Test.Class1.Class11` in `Test.cs:29:22:29:28`\npublic class Class11 : Test.Class1.Interface2, Test.Class1.Interface1\n{\n public Class11(int i) => throw null;\n int Test.Class1.Interface2.this[int i] { get => throw null; }\n public void Method1() => throw null;\n void Test.Class1.Interface2.Method2() => throw null;\n}\n\n\n// Generated from `Test.Class1.Class12` in `Test.cs:46:22:46:28`\npublic class Class12 : Test.Class1.Class11\n{\n public Class12(int i, float j) : base(default(int)) => throw null;\n}\n\n\n// Generated from `Test.Class1.Class13` in `Test.cs:58:31:58:37`\nabstract public class Class13\n{\n protected Class13() => throw null;\n protected internal virtual void M() => throw null;\n public virtual void M1<T>() where T: Test.Class1.Class13 => throw null;\n public abstract void M2();\n}\n\n\n// Generated from `Test.Class1.Class14` in `Test.cs:65:31:65:37`\nabstract public class Class14 : Test.Class1.Class13\n{\n protected Class14() => throw null;\n protected internal override void M() => throw null;\n public override void M1<T>() => throw null;\n public abstract override void M2();\n}\n\n\n// Generated from `Test.Class1.Delegate1<>` in `Test.cs:42:30:42:41`\npublic delegate void Delegate1<T>(T i, int j);\n\n\n public event Test.Class1.Delegate1<int> Event1;\n// Generated from `Test.Class1.GenericType<>` in `Test.cs:51:22:51:35`\npublic class GenericType<T>\n{\n public GenericType() => throw null;\n// Generated from `Test.Class1.GenericType<>.X` in `Test.cs:53:26:53:26`\npublic class X\n{\n public X() => throw null;\n}\n\n\n}\n\n\n// Generated from `Test.Class1.Interface1` in `Test.cs:13:26:13:35`\npublic interface Interface1\n{\n void Method1();\n}\n\n\n// Generated from `Test.Class1.Interface2` in `Test.cs:18:38:18:47`\nprotected internal interface Interface2\n{\n int this[int i] { get; }\n void Method2();\n}\n\n\n public Test.Class1.GenericType<int>.X Prop { get => throw null; }\n// Generated from `Test.Class1.Struct1` in `Test.cs:5:23:5:29`\npublic struct Struct1\n{\n public void Method(Test.Class1.Struct1 s = default(Test.Class1.Struct1)) => throw null;\n // Stub generator skipped constructor \n public int i;\n public static int j = default;\n}\n\n\n}\n\n// Generated from `Test.Class3` in `Test.cs:79:18:79:23`\npublic class Class3\n{\n public Class3() => throw null;\n public object Item { get => throw null; set => throw null; }\n [System.Runtime.CompilerServices.IndexerName("MyItem")]\n public object this[string index] { get => throw null; set => throw null; }\n}\n\n// Generated from `Test.Class4` in `Test.cs:86:18:86:23`\npublic class Class4\n{\n public Class4() => throw null;\n unsafe public void M(int* p) => throw null;\n}\n\n// Generated from `Test.Class5` in `Test.cs:97:18:97:23`\npublic class Class5 : Test.IInterface1\n{\n public Class5() => throw null;\n public void M2() => throw null;\n}\n\n// Generated from `Test.Class6<>` in `Test.cs:102:18:102:26`\npublic class Class6<T> where T: class, Test.IInterface1\n{\n public Class6(int i) => throw null;\n public virtual void M1<T>() where T: class, Test.IInterface1, new() => throw null;\n}\n\n// Generated from `Test.Class7` in `Test.cs:109:18:109:23`\npublic class Class7 : Test.Class6<Test.Class5>\n{\n public Class7(int i) : base(default(int)) => throw null;\n public override void M1<T>() where T: class => throw null;\n}\n\n// Generated from `Test.Class8` in `Test.cs:116:18:116:23`\npublic class Class8\n{\n public Class8() => throw null;\n public static int @this = default;\n}\n\n// Generated from `Test.Class9` in `Test.cs:121:18:121:23`\npublic class Class9\n{\n private Class9(int i) => throw null;\n// Generated from `Test.Class9.Nested` in `Test.cs:125:22:125:27`\npublic class Nested : Test.Class9\n{\n internal Nested(int i) : base(default(int)) => throw null;\n}\n\n\n public Test.Class9.Nested NestedInstance { get => throw null; }\n}\n\n// Generated from `Test.IInterface1` in `Test.cs:91:22:91:32`\npublic interface IInterface1\n{\n void M1() => throw null;\n void M2();\n}\n\n}\n |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Stubs/AllStubsFromSource.ql
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
namespace Test
2+
{
3+
public class Class1
4+
{
5+
public struct Struct1
6+
{
7+
public int i;
8+
public const int j = 42;
9+
10+
public void Method(Struct1 s = new Struct1()) => throw null;
11+
}
12+
13+
public interface Interface1
14+
{
15+
void Method1();
16+
}
17+
18+
internal protected interface Interface2
19+
{
20+
void Method2();
21+
int this[int i] { get; }
22+
}
23+
24+
private protected interface Interface3
25+
{
26+
void Method3();
27+
}
28+
29+
public class Class11 : Interface1, Interface2, Interface3
30+
{
31+
public Class11(int i) => throw null;
32+
33+
public void Method1() => throw null;
34+
35+
void Interface2.Method2() => throw null;
36+
37+
int Interface2.this[int i] => throw null;
38+
39+
void Interface3.Method3() => throw null;
40+
}
41+
42+
public delegate void Delegate1<T>(T i, int j);
43+
44+
public event Delegate1<int> Event1 { add { } remove { } }
45+
46+
public class Class12 : Class11
47+
{
48+
public Class12(int i, float j) : base(1) => throw null;
49+
}
50+
51+
public class GenericType<T>
52+
{
53+
public class X { }
54+
}
55+
56+
public GenericType<int>.X Prop { get; }
57+
58+
public abstract class Class13
59+
{
60+
protected internal virtual void M() => throw null;
61+
public virtual void M1<T>() where T : Class13 => throw null;
62+
public abstract void M2();
63+
}
64+
65+
public abstract class Class14 : Class13
66+
{
67+
protected internal override void M() => throw null;
68+
public override void M1<T>() => throw null;
69+
public abstract override void M2();
70+
}
71+
72+
}
73+
74+
internal class Class2
75+
{
76+
public void M() => throw null;
77+
}
78+
79+
public class Class3
80+
{
81+
public object Item { get; set; }
82+
[System.Runtime.CompilerServices.IndexerName("MyItem")]
83+
public object this[string index] { get { return null; } set { } }
84+
}
85+
86+
public class Class4
87+
{
88+
unsafe public void M(int* p) => throw null;
89+
}
90+
91+
public interface IInterface1
92+
{
93+
void M1() => throw null;
94+
void M2();
95+
}
96+
97+
public class Class5 : IInterface1
98+
{
99+
public void M2() => throw null;
100+
}
101+
102+
public class Class6<T> where T : class, IInterface1
103+
{
104+
public Class6(int i) => throw null;
105+
106+
public virtual void M1<T>() where T : class, IInterface1, new() => throw null;
107+
}
108+
109+
public class Class7 : Class6<Class5>
110+
{
111+
public Class7(int i) : base(i) => throw null;
112+
113+
public override void M1<T>() where T : class => throw null;
114+
}
115+
116+
public class Class8
117+
{
118+
public const int @this = 10;
119+
}
120+
121+
public class Class9
122+
{
123+
private Class9(int i) => throw null;
124+
125+
public class Nested : Class9
126+
{
127+
internal Nested(int i) : base(i) => throw null;
128+
}
129+
130+
public Class9.Nested NestedInstance { get; } = new Class9.Nested(1);
131+
}
132+
}

0 commit comments

Comments
 (0)