1414
1515namespace UnityExplorer . Tests
1616{
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-
4717 public static class TestClass
4818 {
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 ( )
5220 {
53- ExplorerCore . Log ( $ "{ s } , { f } , { vector . ToString ( ) } , { date } , { quater . eulerAngles . ToString ( ) } , { b } , { enumvalue } ") ;
21+ Init_Mono ( ) ;
22+ #if CPP
23+ Init_IL2CPP ( ) ;
24+ #endif
5425 }
5526
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 ) ;
11634
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 ;
11937
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 ) ;
12342
12443 public static List < object > RandomList
12544 {
@@ -133,25 +52,7 @@ public static List<object> RandomList
13352 }
13453 }
13554
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
15556
15657 private static object GetRandomObject ( )
15758 {
@@ -165,109 +66,133 @@ private static object GetRandomObject()
16566 case 2 : return true ;
16667 case 3 : return "hello" ;
16768 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 " } ;
17071 }
17172
17273 return ret ;
17374 }
17475
175- #if CPP
76+ public static void TestComponent < T > ( ) where T : Component
77+ {
78+ ExplorerCore . Log ( $ "Test3 { typeof ( T ) . FullName } ") ;
79+ }
17680
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+ }
18085
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 } ;
18490
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+ } ;
189103
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 ;
190128 public static List < Il2CppSystem . Object > IL2CPP_listOfBoxedObjects ;
191129 public static Il2CppStructArray < int > IL2CPP_structArray ;
192- public static Il2CppStringArray IL2CPP_stringArray ;
193130 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 ;
194134
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 ;
195138 public static Il2CppSystem . Object cppBoxedInt ;
196139 public static Il2CppSystem . Int32 cppInt ;
197140 public static Il2CppSystem . Decimal cppDecimal ;
198141 public static Il2CppSystem . Object cppDecimalBoxed ;
199142 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 ;
200147
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 ( )
223149 {
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>") ;
228151 IL2CPP_Dict = new Il2CppSystem . Collections . Generic . Dictionary < string , string > ( ) ;
229152 IL2CPP_Dict . Add ( "key1" , "value1" ) ;
230153 IL2CPP_Dict . Add ( "key2" , "value2" ) ;
231154 IL2CPP_Dict . Add ( "key3" , "value3" ) ;
232155
156+ ExplorerCore . Log ( $ "IL2CPP 2: Il2Cpp Hashtable") ;
233157 IL2CPP_HashTable = new Il2CppSystem . Collections . Hashtable ( ) ;
234158 IL2CPP_HashTable . Add ( "key1" , "value1" ) ;
235159 IL2CPP_HashTable . Add ( "key2" , "value2" ) ;
236160 IL2CPP_HashTable . Add ( "key3" , "value3" ) ;
237161
162+ ExplorerCore . Log ( $ "IL2CPP 3: Il2Cpp IDictionary") ;
238163 var dict2 = new Il2CppSystem . Collections . Generic . Dictionary < string , string > ( ) ;
239164 dict2 . Add ( "key1" , "value1" ) ;
240165 IL2CPP_IDict = dict2 . TryCast < Il2CppSystem . Collections . IDictionary > ( ) ;
241166
167+ ExplorerCore . Log ( $ "IL2CPP 4: Il2Cpp List of Il2Cpp Object") ;
242168 var list = new Il2CppSystem . Collections . Generic . List < Il2CppSystem . Object > ( 5 ) ;
243169 list . Add ( "one" ) ;
244170 list . Add ( "two" ) ;
245171 IL2CPP_IList = list . TryCast < Il2CppSystem . Collections . IList > ( ) ;
246172
173+ ExplorerCore . Log ( $ "IL2CPP 5: Il2Cpp List of strings") ;
247174 IL2CPP_ListString = new Il2CppSystem . Collections . Generic . List < string > ( ) ;
248175 IL2CPP_ListString . Add ( "hello," ) ;
249176 IL2CPP_ListString . Add ( "world!" ) ;
250177
178+ ExplorerCore . Log ( $ "IL2CPP 6: Il2Cpp HashSet of strings") ;
251179 IL2CPP_HashSet = new Il2CppSystem . Collections . Generic . HashSet < string > ( ) ;
252180 IL2CPP_HashSet . Add ( "one" ) ;
253181 IL2CPP_HashSet . Add ( "two" ) ;
254182
183+ ExplorerCore . Log ( $ "IL2CPP 7: Dictionary of Il2Cpp String and Il2Cpp Object") ;
255184 CppBoxedDict = new Dictionary < Il2CppSystem . String , Il2CppSystem . Object > ( ) ;
256185 CppBoxedDict . Add ( "1" , new Il2CppSystem . Int32 { m_value = 1 } . BoxIl2CppObject ( ) ) ;
257186 CppBoxedDict . Add ( "2" , new Il2CppSystem . Int32 { m_value = 2 } . BoxIl2CppObject ( ) ) ;
258187 CppBoxedDict . Add ( "3" , new Il2CppSystem . Int32 { m_value = 3 } . BoxIl2CppObject ( ) ) ;
259188 CppBoxedDict . Add ( "4" , new Il2CppSystem . Int32 { m_value = 4 } . BoxIl2CppObject ( ) ) ;
260189
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") ;
266191 IL2CPP_listOfBoxedObjects = new List < Il2CppSystem . Object > ( ) ;
267192 IL2CPP_listOfBoxedObjects . Add ( ( Il2CppSystem . String ) "boxedString" ) ;
268193 IL2CPP_listOfBoxedObjects . Add ( new Il2CppSystem . Int32 { m_value = 5 } . BoxIl2CppObject ( ) ) ;
269194 IL2CPP_listOfBoxedObjects . Add ( Color . red . BoxIl2CppObject ( ) ) ;
270-
195+ // boxed enum test
271196 try
272197 {
273198 var cppType = Il2CppType . Of < CameraClearFlags > ( ) ;
@@ -283,34 +208,32 @@ static TestClass()
283208 }
284209 catch ( Exception ex )
285210 {
286- ExplorerCore . LogWarning ( $ "Test fail: { ex } ") ;
211+ ExplorerCore . LogWarning ( $ "Boxed enum test fail: { ex } ") ;
287212 }
288213
214+ ExplorerCore . Log ( $ "IL2CPP 9: Il2Cpp struct array of ints") ;
289215 IL2CPP_structArray = new UnhollowerBaseLib . Il2CppStructArray < int > ( 5 ) ;
290216 IL2CPP_structArray [ 0 ] = 0 ;
291217 IL2CPP_structArray [ 1 ] = 1 ;
292218 IL2CPP_structArray [ 2 ] = 2 ;
293219 IL2CPP_structArray [ 3 ] = 3 ;
294220 IL2CPP_structArray [ 4 ] = 4 ;
295221
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") ;
300223 IL2CPP_ReferenceArray = new UnhollowerBaseLib . Il2CppReferenceArray < Il2CppSystem . Object > ( 3 ) ;
301224 IL2CPP_ReferenceArray [ 0 ] = new Il2CppSystem . Int32 { m_value = 5 } . BoxIl2CppObject ( ) ;
302225 IL2CPP_ReferenceArray [ 1 ] = null ;
303226 IL2CPP_ReferenceArray [ 2 ] = ( Il2CppSystem . String ) "whats up" ;
304227
228+ ExplorerCore . Log ( $ "IL2CPP 11: Misc il2cpp members") ;
305229 cppBoxedInt = new Il2CppSystem . Int32 ( ) { m_value = 5 } . BoxIl2CppObject ( ) ;
306230 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 ( ) ;
307234
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") ;
314236 }
237+ #endif
315238 }
316239}
0 commit comments