14
14
15
15
namespace UnityExplorer . Tests
16
16
{
17
- public class TestIndexer : IList < int >
18
- {
19
- private readonly List < int > list = new List < int > ( ) { 1 , 2 , 3 , 4 , 5 } ;
20
-
21
- public int Count => list . Count ;
22
- public bool IsReadOnly => false ;
23
-
24
- int IList < int > . this [ int index ]
25
- {
26
- get => list [ index ] ;
27
- set => list [ index ] = value ;
28
- }
29
-
30
- public int IndexOf ( int item ) => list . IndexOf ( item ) ;
31
- public bool Contains ( int item ) => list . Contains ( item ) ;
32
-
33
- public void Add ( int item ) => list . Add ( item ) ;
34
- public void Insert ( int index , int item ) => list . Insert ( index , item ) ;
35
-
36
- public bool Remove ( int item ) => list . Remove ( item ) ;
37
- public void RemoveAt ( int index ) => list . RemoveAt ( index ) ;
38
-
39
- public void Clear ( ) => list . Clear ( ) ;
40
-
41
- public void CopyTo ( int [ ] array , int arrayIndex ) => list . CopyTo ( array , arrayIndex ) ;
42
-
43
- public IEnumerator < int > GetEnumerator ( ) => list . GetEnumerator ( ) ;
44
- IEnumerator IEnumerable . GetEnumerator ( ) => list . GetEnumerator ( ) ;
45
- }
46
-
47
17
public static class TestClass
48
18
{
49
- public static readonly TestIndexer AAAAATest = new TestIndexer ( ) ;
50
-
51
- public static void ATestMethod ( string s , float f , Vector3 vector , DateTime date , Quaternion quater , bool b , CameraClearFlags enumvalue )
19
+ static TestClass ( )
52
20
{
53
- ExplorerCore . Log ( $ "{ s } , { f } , { vector . ToString ( ) } , { date } , { quater . eulerAngles . ToString ( ) } , { b } , { enumvalue } ") ;
21
+ Init_Mono ( ) ;
22
+ #if CPP
23
+ Init_IL2CPP ( ) ;
24
+ #endif
54
25
}
55
26
56
- public static List < int > AWritableList = new List < int > { 1 , 2 , 3 , 4 , 5 } ;
57
- public static Dictionary < string , int > AWritableDict = new Dictionary < string , int > { { "one" , 1 } , { "two" , 2 } } ;
58
-
59
- public static IEnumerable ANestedList = new List < List < List < string > > >
60
- {
61
- new List < List < string > >
62
- {
63
- new List < string >
64
- {
65
- "one" ,
66
- "two" ,
67
- "one" ,
68
- "two" ,
69
- "one" ,
70
- "two" ,
71
- "one" ,
72
- "two" ,
73
- "one" ,
74
- "two" ,
75
- "one" ,
76
- "two" ,
77
- "one" ,
78
- "two" ,
79
- "one" ,
80
- "two" ,
81
- } ,
82
- new List < string >
83
- {
84
- "three" ,
85
- "four" ,
86
- }
87
- } ,
88
- new List < List < string > >
89
- {
90
- new List < string >
91
- {
92
- "five"
93
- }
94
- }
95
- } ;
96
-
97
- public static IDictionary ARandomDictionary = new Dictionary < object , object >
98
- {
99
- { 1 , 2 } ,
100
- { "one" , "two" } ,
101
- { true , false } ,
102
- { new Vector3 ( 0 , 1 , 2 ) , new Vector3 ( 1 , 2 , 3 ) } ,
103
- { CameraClearFlags . Depth , CameraClearFlags . Color } ,
104
- { "################################################\r \n ##########" , null } ,
105
- { "subdict" , new Dictionary < object , object > { { "key" , "value" } } }
106
- } ;
107
-
108
- public static Hashtable TestHashtable = new Hashtable
109
- {
110
- { "one" , "value" } ,
111
- { "two" , "value" } ,
112
- { "three" , "value" } ,
113
- } ;
114
-
115
- public const int ConstantInt = 5 ;
27
+ // Test enumerables
28
+ public static List < object > ListOfInts ;
29
+ public static List < List < List < string > > > NestedList ;
30
+ public static IDictionary MixedDictionary ;
31
+ public static Hashtable Hashtable ;
32
+ public static byte [ ] ByteArray = new byte [ 16 ] ;
33
+ public static List < short > ABigList = new List < short > ( 10000 ) ;
116
34
117
- public static Color AColor = Color . magenta ;
118
- public static Color32 AColor32 = Color . red ;
35
+ // Test const behaviour (should be a readonly field)
36
+ public const int ConstantInt5 = 5 ;
119
37
120
- public static byte [ ] ByteArray = new byte [ 16 ] ;
121
- public static string LongString = new string ( '#' , 10000 ) ;
122
- public static List < string > BigList = new List < string > ( 10000 ) ;
38
+ // Testing other InteractiveValues
39
+ public static Color Color = Color . magenta ;
40
+ public static Color32 Color32 = Color . red ;
41
+ public static string ALongString = new string ( '#' , 10000 ) ;
123
42
124
43
public static List < object > RandomList
125
44
{
@@ -133,25 +52,7 @@ public static List<object> RandomList
133
52
}
134
53
}
135
54
136
- private static void TestGeneric < T > ( )
137
- {
138
- ExplorerCore . Log ( "Test1 " + typeof ( T ) . FullName ) ;
139
- }
140
-
141
- private static void TestGenericClass < T > ( ) where T : class
142
- {
143
- ExplorerCore . Log ( "Test2 " + typeof ( T ) . FullName ) ;
144
- }
145
-
146
- private static void TestComponent < T > ( ) where T : Component
147
- {
148
- ExplorerCore . Log ( "Test3 " + typeof ( T ) . FullName ) ;
149
- }
150
-
151
- private static void TestStruct < T > ( ) where T : struct
152
- {
153
- ExplorerCore . Log ( "Test3 " + typeof ( T ) . FullName ) ;
154
- }
55
+ // Test methods
155
56
156
57
private static object GetRandomObject ( )
157
58
{
@@ -165,109 +66,133 @@ private static object GetRandomObject()
165
66
case 2 : return true ;
166
67
case 3 : return "hello" ;
167
68
case 4 : return 50.5f ;
168
- case 5 : return UnityEngine . CameraClearFlags . Color ;
169
- case 6 : return new List < string > { "sub list " , "lol " } ;
69
+ case 5 : return CameraClearFlags . Color ;
70
+ case 6 : return new List < string > { "one " , "two " } ;
170
71
}
171
72
172
73
return ret ;
173
74
}
174
75
175
- #if CPP
76
+ public static void TestComponent < T > ( ) where T : Component
77
+ {
78
+ ExplorerCore . Log ( $ "Test3 { typeof ( T ) . FullName } ") ;
79
+ }
176
80
177
- public static Il2CppSystem . Collections . IList IL2CPP_IList ;
178
- public static Il2CppSystem . Collections . Generic . List < string > IL2CPP_ListString ;
179
- public static Il2CppSystem . Collections . Generic . HashSet < string > IL2CPP_HashSet ;
81
+ public static void TestArgumentParse ( string s , int i , Color color , CameraClearFlags flags , Vector3 vector , Quaternion quaternion )
82
+ {
83
+ ExplorerCore . Log ( $ "{ s } , { i } , { color . ToString ( ) } , { flags } , { vector . ToString ( ) } , { quaternion . ToString ( ) } ") ;
84
+ }
180
85
181
- public static Il2CppSystem . Collections . Generic . Dictionary < string , string > IL2CPP_Dict ;
182
- public static Il2CppSystem . Collections . Hashtable IL2CPP_HashTable ;
183
- public static Il2CppSystem . Collections . IDictionary IL2CPP_IDict ;
86
+ private static void Init_Mono ( )
87
+ {
88
+ ExplorerCore . Log ( $ "1: Basic list") ;
89
+ ListOfInts = new List < object > { 1 , 2 , 3 , 4 , 5 } ;
184
90
185
- public static string IL2CPP_systemString = "Test" ;
186
- public static Il2CppSystem . Object IL2CPP_objectString = "string boxed as cpp object" ;
187
- public static Il2CppSystem . String IL2CPP_il2cppString = "string boxed as cpp string" ;
188
- public static string nullString = null ;
91
+ ExplorerCore . Log ( $ "2: Nested list") ;
92
+ NestedList = new List < List < List < string > > >
93
+ {
94
+ new List < List < string > > {
95
+ new List < string > { "1" , "2" , "3" } ,
96
+ new List < string > { "4" , "5" , "6" } ,
97
+ } ,
98
+ new List < List < string > >
99
+ {
100
+ new List < string > { "7" , "8" , "9" }
101
+ }
102
+ } ;
189
103
104
+ ExplorerCore . Log ( $ "3: Dictionary") ;
105
+ MixedDictionary = new Dictionary < object , object >
106
+ {
107
+ { 1 , 2 } ,
108
+ { "one" , "two" } ,
109
+ { true , false } ,
110
+ { new Vector3 ( 0 , 1 , 2 ) , new Vector3 ( 1 , 2 , 3 ) } ,
111
+ { CameraClearFlags . Depth , CameraClearFlags . Color } ,
112
+ { "################################################\r \n ##########" , null } ,
113
+ { "subdict" , new Dictionary < object , object > { { "key" , "value" } } }
114
+ } ;
115
+
116
+ ExplorerCore . Log ( $ "4: Hashtable") ;
117
+ Hashtable = new Hashtable { { "One" , 1 } , { "Two" , 2 } } ;
118
+
119
+ ExplorerCore . Log ( $ "5: Big list") ;
120
+ for ( int i = 0 ; i < ABigList . Capacity ; i ++ )
121
+ ABigList [ i ] = ( short ) UnityEngine . Random . Range ( 0 , short . MaxValue ) ;
122
+
123
+ ExplorerCore . Log ( "Finished TestClass Init_Mono" ) ;
124
+ }
125
+
126
+ #if CPP
127
+ public static Il2CppSystem . Collections . Generic . List < string > IL2CPP_ListString ;
190
128
public static List < Il2CppSystem . Object > IL2CPP_listOfBoxedObjects ;
191
129
public static Il2CppStructArray < int > IL2CPP_structArray ;
192
- public static Il2CppStringArray IL2CPP_stringArray ;
193
130
public static Il2CppReferenceArray < Il2CppSystem . Object > IL2CPP_ReferenceArray ;
131
+ public static Il2CppSystem . Collections . IDictionary IL2CPP_IDict ;
132
+ public static Il2CppSystem . Collections . IList IL2CPP_IList ;
133
+ public static Dictionary < Il2CppSystem . String , Il2CppSystem . Object > CppBoxedDict ;
194
134
135
+ public static Il2CppSystem . Collections . Generic . HashSet < string > IL2CPP_HashSet ;
136
+ public static Il2CppSystem . Collections . Generic . Dictionary < string , string > IL2CPP_Dict ;
137
+ public static Il2CppSystem . Collections . Hashtable IL2CPP_HashTable ;
195
138
public static Il2CppSystem . Object cppBoxedInt ;
196
139
public static Il2CppSystem . Int32 cppInt ;
197
140
public static Il2CppSystem . Decimal cppDecimal ;
198
141
public static Il2CppSystem . Object cppDecimalBoxed ;
199
142
public static Il2CppSystem . Object cppVector3Boxed ;
143
+ public static string IL2CPP_systemString = "Test" ;
144
+ public static Il2CppSystem . Object IL2CPP_objectString = "string boxed as cpp object" ;
145
+ public static Il2CppSystem . String IL2CPP_il2cppString = "string boxed as cpp string" ;
146
+ public static string nullString = null ;
200
147
201
- public static Il2CppSystem . Object RandomBoxedColor
202
- {
203
- get
204
- {
205
- int ran = UnityEngine . Random . Range ( 0 , 3 ) ;
206
- switch ( ran )
207
- {
208
- case 1 : return new Color32 ( ) . BoxIl2CppObject ( ) ;
209
- case 2 : return Color . magenta . BoxIl2CppObject ( ) ;
210
- default :
211
- return null ;
212
- }
213
- }
214
- }
215
-
216
- public static Il2CppSystem . Collections . Hashtable cppHashset ;
217
-
218
- public static Dictionary < Il2CppSystem . String , Il2CppSystem . Object > CppBoxedDict ;
219
-
220
- #endif
221
-
222
- static TestClass ( )
148
+ private static void Init_IL2CPP ( )
223
149
{
224
- for ( int i = 0 ; i < BigList . Capacity ; i ++ )
225
- BigList . Add ( i . ToString ( ) ) ;
226
-
227
- #if CPP
150
+ ExplorerCore . Log ( $ "IL2CPP 1: Il2Cpp Dictionary<string, string>") ;
228
151
IL2CPP_Dict = new Il2CppSystem . Collections . Generic . Dictionary < string , string > ( ) ;
229
152
IL2CPP_Dict . Add ( "key1" , "value1" ) ;
230
153
IL2CPP_Dict . Add ( "key2" , "value2" ) ;
231
154
IL2CPP_Dict . Add ( "key3" , "value3" ) ;
232
155
156
+ ExplorerCore . Log ( $ "IL2CPP 2: Il2Cpp Hashtable") ;
233
157
IL2CPP_HashTable = new Il2CppSystem . Collections . Hashtable ( ) ;
234
158
IL2CPP_HashTable . Add ( "key1" , "value1" ) ;
235
159
IL2CPP_HashTable . Add ( "key2" , "value2" ) ;
236
160
IL2CPP_HashTable . Add ( "key3" , "value3" ) ;
237
161
162
+ ExplorerCore . Log ( $ "IL2CPP 3: Il2Cpp IDictionary") ;
238
163
var dict2 = new Il2CppSystem . Collections . Generic . Dictionary < string , string > ( ) ;
239
164
dict2 . Add ( "key1" , "value1" ) ;
240
165
IL2CPP_IDict = dict2 . TryCast < Il2CppSystem . Collections . IDictionary > ( ) ;
241
166
167
+ ExplorerCore . Log ( $ "IL2CPP 4: Il2Cpp List of Il2Cpp Object") ;
242
168
var list = new Il2CppSystem . Collections . Generic . List < Il2CppSystem . Object > ( 5 ) ;
243
169
list . Add ( "one" ) ;
244
170
list . Add ( "two" ) ;
245
171
IL2CPP_IList = list . TryCast < Il2CppSystem . Collections . IList > ( ) ;
246
172
173
+ ExplorerCore . Log ( $ "IL2CPP 5: Il2Cpp List of strings") ;
247
174
IL2CPP_ListString = new Il2CppSystem . Collections . Generic . List < string > ( ) ;
248
175
IL2CPP_ListString . Add ( "hello," ) ;
249
176
IL2CPP_ListString . Add ( "world!" ) ;
250
177
178
+ ExplorerCore . Log ( $ "IL2CPP 6: Il2Cpp HashSet of strings") ;
251
179
IL2CPP_HashSet = new Il2CppSystem . Collections . Generic . HashSet < string > ( ) ;
252
180
IL2CPP_HashSet . Add ( "one" ) ;
253
181
IL2CPP_HashSet . Add ( "two" ) ;
254
182
183
+ ExplorerCore . Log ( $ "IL2CPP 7: Dictionary of Il2Cpp String and Il2Cpp Object") ;
255
184
CppBoxedDict = new Dictionary < Il2CppSystem . String , Il2CppSystem . Object > ( ) ;
256
185
CppBoxedDict . Add ( "1" , new Il2CppSystem . Int32 { m_value = 1 } . BoxIl2CppObject ( ) ) ;
257
186
CppBoxedDict . Add ( "2" , new Il2CppSystem . Int32 { m_value = 2 } . BoxIl2CppObject ( ) ) ;
258
187
CppBoxedDict . Add ( "3" , new Il2CppSystem . Int32 { m_value = 3 } . BoxIl2CppObject ( ) ) ;
259
188
CppBoxedDict . Add ( "4" , new Il2CppSystem . Int32 { m_value = 4 } . BoxIl2CppObject ( ) ) ;
260
189
261
- cppDecimal = new Il2CppSystem . Decimal ( 1f ) ;
262
- cppDecimalBoxed = new Il2CppSystem . Decimal ( 1f ) . BoxIl2CppObject ( ) ;
263
- cppVector3Boxed = Vector3 . down . BoxIl2CppObject ( ) ;
264
-
265
-
190
+ ExplorerCore . Log ( $ "IL2CPP 8: List of boxed Il2Cpp Objects") ;
266
191
IL2CPP_listOfBoxedObjects = new List < Il2CppSystem . Object > ( ) ;
267
192
IL2CPP_listOfBoxedObjects . Add ( ( Il2CppSystem . String ) "boxedString" ) ;
268
193
IL2CPP_listOfBoxedObjects . Add ( new Il2CppSystem . Int32 { m_value = 5 } . BoxIl2CppObject ( ) ) ;
269
194
IL2CPP_listOfBoxedObjects . Add ( Color . red . BoxIl2CppObject ( ) ) ;
270
-
195
+ // boxed enum test
271
196
try
272
197
{
273
198
var cppType = Il2CppType . Of < CameraClearFlags > ( ) ;
@@ -283,34 +208,32 @@ static TestClass()
283
208
}
284
209
catch ( Exception ex )
285
210
{
286
- ExplorerCore . LogWarning ( $ "Test fail: { ex } ") ;
211
+ ExplorerCore . LogWarning ( $ "Boxed enum test fail: { ex } ") ;
287
212
}
288
213
214
+ ExplorerCore . Log ( $ "IL2CPP 9: Il2Cpp struct array of ints") ;
289
215
IL2CPP_structArray = new UnhollowerBaseLib . Il2CppStructArray < int > ( 5 ) ;
290
216
IL2CPP_structArray [ 0 ] = 0 ;
291
217
IL2CPP_structArray [ 1 ] = 1 ;
292
218
IL2CPP_structArray [ 2 ] = 2 ;
293
219
IL2CPP_structArray [ 3 ] = 3 ;
294
220
IL2CPP_structArray [ 4 ] = 4 ;
295
221
296
- IL2CPP_stringArray = new UnhollowerBaseLib . Il2CppStringArray ( 2 ) ;
297
- IL2CPP_stringArray [ 0 ] = "hello, " ;
298
- IL2CPP_stringArray [ 1 ] = "world!" ;
299
-
222
+ ExplorerCore . Log ( $ "IL2CPP 10: Il2Cpp reference array of boxed objects") ;
300
223
IL2CPP_ReferenceArray = new UnhollowerBaseLib . Il2CppReferenceArray < Il2CppSystem . Object > ( 3 ) ;
301
224
IL2CPP_ReferenceArray [ 0 ] = new Il2CppSystem . Int32 { m_value = 5 } . BoxIl2CppObject ( ) ;
302
225
IL2CPP_ReferenceArray [ 1 ] = null ;
303
226
IL2CPP_ReferenceArray [ 2 ] = ( Il2CppSystem . String ) "whats up" ;
304
227
228
+ ExplorerCore . Log ( $ "IL2CPP 11: Misc il2cpp members") ;
305
229
cppBoxedInt = new Il2CppSystem . Int32 ( ) { m_value = 5 } . BoxIl2CppObject ( ) ;
306
230
cppInt = new Il2CppSystem . Int32 { m_value = 420 } ;
231
+ cppDecimal = new Il2CppSystem . Decimal ( 1f ) ;
232
+ cppDecimalBoxed = new Il2CppSystem . Decimal ( 1f ) . BoxIl2CppObject ( ) ;
233
+ cppVector3Boxed = Vector3 . down . BoxIl2CppObject ( ) ;
307
234
308
- cppHashset = new Il2CppSystem . Collections . Hashtable ( ) ;
309
- cppHashset . Add ( "key1" , "itemOne" ) ;
310
- cppHashset . Add ( "key2" , "itemTwo" ) ;
311
- cppHashset . Add ( "key3" , "itemThree" ) ;
312
-
313
- #endif
235
+ ExplorerCore . Log ( $ "Finished Init_Il2Cpp") ;
314
236
}
237
+ #endif
315
238
}
316
239
}
0 commit comments