Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 5a9af69

Browse files
committed
Fix System.Reflection.Emit tests to use non-static RNG
1 parent 1b5d9fb commit 5a9af69

File tree

51 files changed

+421
-657
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+421
-657
lines changed

src/System.Reflection.Emit/tests/ConstructorBuilder/ConstructorBuilderGetILGenerator2.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ConstructorBuilderGetILGenerator2
1515
private const string DefaultTypeName = "DynamicType";
1616
private const AssemblyBuilderAccess DefaultAssemblyBuilderAccess = AssemblyBuilderAccess.Run;
1717
private const CallingConventions DefaultCallingConvention = CallingConventions.Standard;
18+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
1819

1920
private ModuleBuilder TestModuleBuilder
2021
{
@@ -37,7 +38,7 @@ public void TestIlGeneratorOnNonDefaultConstructor()
3738
{
3839
int i = 0;
3940
int randValue = 0;
40-
randValue = TestLibrary.Generator.GetInt16();
41+
randValue = _generator.GetInt16();
4142
MethodAttributes[] attributes = new MethodAttributes[] {
4243
MethodAttributes.Assembly,
4344
MethodAttributes.CheckAccessOnOverride,
@@ -74,7 +75,7 @@ public void TestIlGeneratorOnNonDefaultConstructor()
7475
public void TestThrowsExceptionWithNoMethodyBody()
7576
{
7677
int randValue = 0;
77-
randValue = TestLibrary.Generator.GetInt16();
78+
randValue = _generator.GetInt16();
7879
Assert.Throws<InvalidOperationException>(() =>
7980
{
8081
ILGenerator generator = CreateConstructorBuilder("NegTest1_Type1", MethodAttributes.PinvokeImpl).GetILGenerator(randValue);
@@ -85,7 +86,7 @@ public void TestThrowsExceptionWithNoMethodyBody()
8586
public void TestThrowsExceptionOnDefaultConstructor()
8687
{
8788
int randValue = 0;
88-
randValue = TestLibrary.Generator.GetInt16();
89+
randValue = _generator.GetInt16();
8990
TypeBuilder type = TestModuleBuilder.DefineType("NegTest2_Type1");
9091

9192
Assert.Throws<InvalidOperationException>(() =>

src/System.Reflection.Emit/tests/EnumBuilder/EnumBuilderMakeArrayType2.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace System.Reflection.Emit.Tests
1313
public class EnumBuilderMakeArrayType2
1414
{
1515
private AssemblyBuilder _myAssemblyBuilder;
16+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
1617

1718
private ModuleBuilder CreateCallee()
1819
{
@@ -67,7 +68,7 @@ private int GetInt32(int minValue, int maxValue)
6768
}
6869
if (minValue < maxValue)
6970
{
70-
return minValue + TestLibrary.Generator.GetInt32() % (maxValue - minValue);
71+
return minValue + _generator.GetInt32() % (maxValue - minValue);
7172
}
7273
}
7374
catch

src/System.Reflection.Emit/tests/EventBuilder/EventBuilderAddOtherMethod.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace System.Reflection.Emit.Tests
1111
public class EventBuilderAddOtherMethod
1212
{
1313
public delegate void TestEventHandler(object sender, object arg);
14+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
1415

1516
private TypeBuilder TypeBuilder
1617
{
@@ -61,7 +62,7 @@ public void TestAddOtherMethodWithInstanceMethod()
6162
public void TestAddOtherMethodWithStaticMethod()
6263
{
6364
byte[] bytes = new byte[MethodBodyLength];
64-
TestLibrary.Generator.GetBytes(bytes);
65+
_generator.GetBytes(bytes);
6566
EventBuilder ev = TypeBuilder.DefineEvent("Event_PosTest3", EventAttributes.None, typeof(TestEventHandler));
6667
MethodBuilder method = TypeBuilder.DefineMethod("Method_PosTest3", MethodAttributes.Static);
6768
ILGenerator ilgen = method.GetILGenerator();
@@ -89,7 +90,7 @@ public void TestAddOtherMethodWithPInvokeMethod()
8990
public void TestAddOtherMethodWithMultipleMethods()
9091
{
9192
byte[] bytes = new byte[MethodBodyLength];
92-
TestLibrary.Generator.GetBytes(bytes);
93+
_generator.GetBytes(bytes);
9394

9495
EventBuilder ev = TypeBuilder.DefineEvent("Event_PosTest5", EventAttributes.None, typeof(TestEventHandler));
9596
MethodBuilder method1 = TypeBuilder.DefineMethod("PMethod_PosTest5", MethodAttributes.PinvokeImpl);

src/System.Reflection.Emit/tests/EventBuilder/EventBuilderSetAddOnMethod.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace System.Reflection.Emit.Tests
1111
public class EventBuilderSetAddOnMethod
1212
{
1313
public delegate void TestEventHandler(object sender, object arg);
14+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
1415

1516
private TypeBuilder TypeBuilder
1617
{
@@ -49,7 +50,7 @@ public void TestOnAbstractMethod()
4950
public void TestOnInstanceMethod()
5051
{
5152
byte[] bytes = new byte[MethodBodyLength];
52-
TestLibrary.Generator.GetBytes(bytes);
53+
_generator.GetBytes(bytes);
5354
EventBuilder ev = TypeBuilder.DefineEvent("Event_PosTest2", EventAttributes.None, typeof(TestEventHandler));
5455
MethodBuilder method = TypeBuilder.DefineMethod("Method_PosTest2", MethodAttributes.Public);
5556
ILGenerator ilgen = method.GetILGenerator();
@@ -65,7 +66,7 @@ public void TestOnInstanceMethod()
6566
public void TestOnStaticMethod()
6667
{
6768
byte[] bytes = new byte[MethodBodyLength];
68-
TestLibrary.Generator.GetBytes(bytes);
69+
_generator.GetBytes(bytes);
6970
EventBuilder ev = TypeBuilder.DefineEvent("Event_PosTest3", EventAttributes.None, typeof(TestEventHandler));
7071
MethodBuilder method = TypeBuilder.DefineMethod("Method_PosTest3", MethodAttributes.Static);
7172
ILGenerator ilgen = method.GetILGenerator();
@@ -93,7 +94,7 @@ public void TestOnPInvokeMethod()
9394
public void TestOnMultipleDifferentMethods()
9495
{
9596
byte[] bytes = new byte[MethodBodyLength];
96-
TestLibrary.Generator.GetBytes(bytes);
97+
_generator.GetBytes(bytes);
9798

9899
EventBuilder ev = TypeBuilder.DefineEvent("Event_PosTest5", EventAttributes.None, typeof(TestEventHandler));
99100
MethodBuilder method1 = TypeBuilder.DefineMethod("PMethod_PosTest5", MethodAttributes.PinvokeImpl);

src/System.Reflection.Emit/tests/EventBuilder/EventBuilderSetCustomAttribute1.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class EvBMyAttribute1 : Attribute
1515
public class EventBuilderSetCustomAttribute1
1616
{
1717
public delegate void TestEventHandler(object sender, object arg);
18+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
1819

1920
private TypeBuilder TypeBuilder
2021
{
@@ -43,7 +44,7 @@ public void TestSetCustomAttribute()
4344
Type type = typeof(EvBMyAttribute1);
4445
ConstructorInfo con = type.GetConstructor(new Type[] { });
4546
byte[] bytes = new byte[ArraySize];
46-
TestLibrary.Generator.GetBytes(bytes);
47+
_generator.GetBytes(bytes);
4748

4849
ev.SetCustomAttribute(con, bytes);
4950
}
@@ -72,7 +73,7 @@ public void TestThrowsExceptionOnCreateTypeCalled()
7273
Type type = typeof(EvBMyAttribute1);
7374
ConstructorInfo con = type.GetConstructor(new Type[] { });
7475
byte[] bytes = new byte[ArraySize];
75-
TestLibrary.Generator.GetBytes(bytes);
76+
_generator.GetBytes(bytes);
7677
TypeBuilder.CreateTypeInfo().AsType();
7778

7879
Assert.Throws<InvalidOperationException>(() => { ev.SetCustomAttribute(con, bytes); });

src/System.Reflection.Emit/tests/EventBuilder/EventBuilderSetRaiseMethod.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace System.Reflection.Emit.Tests
1111
public class EventBuilderSetRaiseMethod
1212
{
1313
public delegate void TestEventHandler(object sender, object arg);
14+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
1415

1516
private TypeBuilder TypeBuilder
1617
{
@@ -47,7 +48,7 @@ public void TestOnAbstractMethod()
4748
public void TestOnInstanceMethod()
4849
{
4950
byte[] bytes = new byte[MethodBodyLength];
50-
TestLibrary.Generator.GetBytes(bytes);
51+
_generator.GetBytes(bytes);
5152
EventBuilder ev = TypeBuilder.DefineEvent("Event_PosTest2", EventAttributes.None, typeof(TestEventHandler));
5253
MethodBuilder method = TypeBuilder.DefineMethod("Method_PosTest2", MethodAttributes.Public);
5354
ILGenerator ilgen = method.GetILGenerator();
@@ -64,7 +65,7 @@ public void TestOnInstanceMethod()
6465
public void TestOnStaticMethod()
6566
{
6667
byte[] bytes = new byte[MethodBodyLength];
67-
TestLibrary.Generator.GetBytes(bytes);
68+
_generator.GetBytes(bytes);
6869
EventBuilder ev = TypeBuilder.DefineEvent("Event_PosTest3", EventAttributes.None, typeof(TestEventHandler));
6970
MethodBuilder method = TypeBuilder.DefineMethod("Method_PosTest3", MethodAttributes.Static);
7071
ILGenerator ilgen = method.GetILGenerator();
@@ -93,7 +94,7 @@ public void TestOnPInvokeMethod()
9394
public void TestOnMultipleDifferentMethods()
9495
{
9596
byte[] bytes = new byte[MethodBodyLength];
96-
TestLibrary.Generator.GetBytes(bytes);
97+
_generator.GetBytes(bytes);
9798

9899
EventBuilder ev = TypeBuilder.DefineEvent("Event_PosTest5", EventAttributes.None, typeof(TestEventHandler));
99100
MethodBuilder method1 = TypeBuilder.DefineMethod("PMethod_PosTest5", MethodAttributes.PinvokeImpl);

src/System.Reflection.Emit/tests/EventBuilder/EventBuilderSetRemoveOnMethod.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace System.Reflection.Emit.Tests
1111
public class EventBuilderSetRemoveOnMethod
1212
{
1313
public delegate void TestEventHandler(object sender, object arg);
14+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
1415

1516
private TypeBuilder TypeBuilder
1617
{
@@ -48,7 +49,7 @@ public void TestOnAbstractMethod()
4849
public void TestOnInstanceMethod()
4950
{
5051
byte[] bytes = new byte[MethodBodyLength];
51-
TestLibrary.Generator.GetBytes(bytes);
52+
_generator.GetBytes(bytes);
5253
EventBuilder ev = TypeBuilder.DefineEvent("Event_PosTest2", EventAttributes.None, typeof(TestEventHandler));
5354
MethodBuilder method = TypeBuilder.DefineMethod("Method_PosTest2", MethodAttributes.Public);
5455
ILGenerator ilgen = method.GetILGenerator();
@@ -65,7 +66,7 @@ public void TestOnInstanceMethod()
6566
public void TestOnStaticMethod()
6667
{
6768
byte[] bytes = new byte[MethodBodyLength];
68-
TestLibrary.Generator.GetBytes(bytes);
69+
_generator.GetBytes(bytes);
6970
EventBuilder ev = TypeBuilder.DefineEvent("Event_PosTest3", EventAttributes.None, typeof(TestEventHandler));
7071
MethodBuilder method = TypeBuilder.DefineMethod("Method_PosTest3", MethodAttributes.Static);
7172
ILGenerator ilgen = method.GetILGenerator();
@@ -94,7 +95,7 @@ public void TestOnPInvokeMethod()
9495
public void TestOnMultipleDifferentMethods()
9596
{
9697
byte[] bytes = new byte[MethodBodyLength];
97-
TestLibrary.Generator.GetBytes(bytes);
98+
_generator.GetBytes(bytes);
9899

99100
EventBuilder ev = TypeBuilder.DefineEvent("Event_PosTest5", EventAttributes.None, typeof(TestEventHandler));
100101
MethodBuilder method1 = TypeBuilder.DefineMethod("PMethod_PosTest5", MethodAttributes.PinvokeImpl);

src/System.Reflection.Emit/tests/FieldBuilder/FieldBuilderName.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace System.Reflection.Emit.Tests
1010
{
1111
public class FieldBuilderName
1212
{
13+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
14+
1315
[Fact]
1416
public void TestNameProperty()
1517
{
@@ -18,7 +20,7 @@ public void TestNameProperty()
1820
ModuleBuilder module = TestLibrary.Utilities.GetModuleBuilder(assembly, "FieldBuilderName_Module");
1921
TypeBuilder type = module.DefineType("FieldBuilderName_Type", TypeAttributes.Abstract);
2022

21-
string expected = TestLibrary.Generator.GetString(false, 1, 30);
23+
string expected = _generator.GetString(false, 1, 30);
2224
FieldBuilder field = type.DefineField(expected, typeof(object), FieldAttributes.Public);
2325
string actual = field.Name;
2426

src/System.Reflection.Emit/tests/FieldBuilder/FieldBuilderSetConstant.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public struct FBTestStruct
2222

2323
public class FieldBuilderSetConstant
2424
{
25+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
26+
2527
private TypeBuilder TypeBuilder
2628
{
2729
get
@@ -205,7 +207,7 @@ public void TestForString()
205207
field.SetConstant(null);
206208

207209
// change default value
208-
field.SetConstant(TestLibrary.Generator.GetString(false, 1, 30));
210+
field.SetConstant(_generator.GetString(false, 1, 30));
209211
}
210212

211213
[Fact]

src/System.Reflection.Emit/tests/FieldBuilder/FieldBuilderSetCustomAttribute1.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private TypeBuilder TypeBuilder
3333

3434
private TypeBuilder _typeBuilder;
3535
private const int ArraySize = 256;
36+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
3637

3738
[Fact]
3839
public void TestSetCustomAttribute()
@@ -41,7 +42,7 @@ public void TestSetCustomAttribute()
4142
Type type = typeof(FBTestAttribute1);
4243
ConstructorInfo con = type.GetConstructor(new Type[] { });
4344
byte[] bytes = new byte[ArraySize];
44-
TestLibrary.Generator.GetBytes(bytes);
45+
_generator.GetBytes(bytes);
4546

4647
field.SetCustomAttribute(con, bytes);
4748
}
@@ -70,7 +71,7 @@ public void TestThrowsExceptionForCreateTypeCalled()
7071
Type type = typeof(FBTestAttribute1);
7172
ConstructorInfo con = type.GetConstructor(new Type[] { });
7273
byte[] bytes = new byte[ArraySize];
73-
TestLibrary.Generator.GetBytes(bytes);
74+
_generator.GetBytes(bytes);
7475
TypeBuilder.CreateTypeInfo().AsType();
7576

7677
Assert.Throws<InvalidOperationException>(() => { field.SetCustomAttribute(con, bytes); });

0 commit comments

Comments
 (0)