-
Notifications
You must be signed in to change notification settings - Fork 659
/
Copy pathTestValueTypeBinding.cs
624 lines (519 loc) · 16.4 KB
/
TestValueTypeBinding.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
using System;
using System.Collections.Generic;
using ILRuntimeTest;
using ILRuntimeTest.TestFramework;
namespace TestCases
{
public class TestValueTypeBinding
{
class TestValueTypeCls
{
public TestVectorStruct A;
public Vector3 B;
}
public static void Test00()
{
var a = TestVector3.One;
a.X += 100;
Console.WriteLine(a.ToString());
}
[ILRuntimeTest(IsToDo = true)]
public static void Test01()
{
TestVector3 vec = new TestVector3(100, 1, 0);
TestVector3.One.X += vec.X;
Console.WriteLine(TestVector3.One.ToString());
if (TestVector3.One.X == 1)
throw new Exception();
}
public static void Test02()
{
TestVector3 vec = new TestVector3(100, 1, 0);
vec += TestVector3.One;
Console.WriteLine(vec.ToString());
}
public static object Test03()
{
TestVector3[] a = new TestVector3[10000];
Vector3[] b = new Vector3[100];
Console.WriteLine(b[0]);
for (int i = 0; i < 10000; i++)
{
a[i] = TestVector3.One;
}
return a;
}
public static void UnitTest_10022()
{
TestVector3 pos = TestVector3.One;
pos.X += 1;
pos.Y += 2;
if (pos.X > 10)
pos.X = 10;
if (pos.X < -10)
pos.X = -10;
if (pos.Y > 10)
pos.Y = 10;
if (pos.Y < -10)
pos.Y = -10;
var pos2 = tttt(pos);
Console.WriteLine("pos.x = " + pos.X);
Console.WriteLine("pos2.x = " + pos2.X);
if (pos.X == pos2.X)
throw new Exception("Value Type Violation");
}
static TestVector3 tttt(TestVector3 a)
{
a.X = 12345;
return a;
}
public static void UnitTest_10023()
{
TestVectorStruct a;
a = Sub10023();
TestVector3 pos = a.C;
pos.X += 123;
TestVector3 pos2 = a.B.Vector;
pos2.X -= 120;
Console.WriteLine("pos.x=" + pos.X);
Console.WriteLine("a.C.x=" + a.C.X);
if (pos.X == a.C.X)
throw new Exception("Value Type Violation");
Console.WriteLine("pos2.x=" + pos2.X);
Console.WriteLine("a.B.Vector.x=" + a.B.Vector.X);
if (pos2.X == a.B.Vector.X)
throw new Exception("Value Type Violation");
}
static TestVectorStruct Sub10023()
{
TestVectorStruct a;
a.A = 123;
a.C = TestVector3.One;
a.B = new TestVectorStruct2();
a.B.Vector = TestVector3.One * 123;
return a;
}
public static void UnitTest_10024()
{
TestVectorStruct a;
a = Sub10023();
Sub10024(a);
}
static void Sub10024(object obj)
{
TestVectorStruct a = (TestVectorStruct)obj;
Console.WriteLine("a.B.Vector.x=" + a.B.Vector.X);
}
public static void UnitTest_10025()
{
TestValueTypeCls cls = new TestValueTypeCls();
cls.A = Sub10023();
cls.B = Vector3.One;
Console.WriteLine("a.B.Vector.x=" + cls.A.B.Vector.X);
Console.WriteLine("cls.B.x=" + cls.B.x);
}
public static void UnitTest_10026()
{
Console.WriteLine(DateTime.UtcNow.ToString());
}
public static void UnitTest_10027()
{
TestVectorClass cls = new TestVectorClass();
cls.vector = new TestVector3(123, 123, 123);
Console.WriteLine("x:" + cls.vector.X + " y:" + cls.vector.Y + " z:" + cls.vector.Z);
}
public static void UnitTest_10028()
{
TestVector3 a = TestVector3.One;
float b = 1f;
TestVector3 c = new TestVector3();
a.Test(out c, out b);
}
public static void UnitTest_10029()
{
TestVector3 c = new TestVector3();
UnitTest_10029Sub2(out c);
Console.WriteLine(c.ToString());
c = new TestVector3();
UnitTest_10029Sub(out c);
Console.WriteLine(c.ToString());
}
static void UnitTest_10029Sub(out TestVector3 v3)
{
v3 = TestVector3.One;//
}
static void UnitTest_10029Sub2(out TestVector3 v3)
{
v3 = TestVector3.One2;//
}
static TestVectorClass vecCls = new TestVectorClass();
public static void UnitTest_10030()
{
vecCls.Vector2 += TestVector3.One2 * (0.456f - vecCls.Vector2.Y * 2);//这样会有
Console.WriteLine(vecCls.Vector2);
}
public static void UnitTest_10031()
{
TestVector3 pos = TestVector3.One2;
float offsetX = pos.X - 0.1f;
float offsetY = pos.Y - 0.1f;//报错行数在这里
if (offsetX > 1)
Console.WriteLine("1");
else if (offsetX < -1)
Console.WriteLine("2");
//注释下面的代码就不会出错了
else if (offsetY > 1)
Console.WriteLine("3");
else if (offsetY < -1)
Console.WriteLine("4");
}
public static void UnitTest_10032()
{
TestVectorClass VTest = new TestVectorClass();
TestVector3 value = VTest.vector;
value.Normalize();
VTest.vector.Normalize();
Console.WriteLine("Vector3BindingTest local Vector3 normalized = " + value);
Console.WriteLine("Vector3BindingTest Vector3 normalized = " + VTest.vector);
}
public static void UnitTest_10033()
{
TestVector3[] arr2 = new TestVector3[10];
arr2[0].X = 1243;
Vector3[] arr3 = new Vector3[10];
arr3[0].x = 3143;
Console.WriteLine(arr2[0].X);
Console.WriteLine(arr3[0].x);
}
public static void UnitTest_10034()
{
Dictionary<UInt32, TestValueTypeBinding> testDic = new Dictionary<uint, TestValueTypeBinding>();
testDic.Add(1, new TestValueTypeBinding());
testDic.Add(2, new TestValueTypeBinding());
foreach (var item in testDic)
{
Console.WriteLine(string.Format("dic item {0}", item.Key));
}
}
public static void UnitTest_10035()
{
TestVector3[] FuncBtnsPos1 = new TestVector3[3] { TestVector3.One, TestVector3.One, TestVector3.One };
foreach (var i in FuncBtnsPos1)
{
Console.WriteLine(i.ToString());
}
}
static TestVector3NoBinding m_curPos;
public static void UnitTest_10036()
{
TestVector3NoBinding rawPos = new TestVector3NoBinding(1, 2, 3);
TestVector3NoBinding tmpPos = rawPos;
m_curPos = rawPos;
Console.WriteLine("before raw:" + rawPos + " tmp:" + tmpPos + " cur:" + m_curPos);
ChangePosY(tmpPos);
ChangePosY(m_curPos);
Console.WriteLine("after raw:" + rawPos + " tmp:" + tmpPos + " cur:" + m_curPos);
if (tmpPos.y == 0 || m_curPos.y == 0)
throw new AccessViolationException();
}
static TestVector3 m_curPos2;
public static void UnitTest_10037()
{
TestVector3 rawPos = new TestVector3(1, 2, 3);
TestVector3 tmpPos = rawPos;
m_curPos2 = rawPos;
Console.WriteLine("before raw:" + rawPos + " tmp:" + tmpPos + " cur:" + m_curPos2);
ChangePosY2(tmpPos);
ChangePosY2(m_curPos2);
Console.WriteLine("after raw:" + rawPos + " tmp:" + tmpPos + " cur:" + m_curPos2);
if (tmpPos.Y == 0 || m_curPos2.Y == 0)
throw new AccessViolationException();
}
static void ChangePosY(TestVector3NoBinding pos)
{
pos.y = 0;
}
static void ChangePosY2(TestVector3 pos)
{
pos.Y = 0;
}
public static void UnitTest_10038()
{
TestVector3NoBinding rawPos = TestVector3NoBinding.zero;
rawPos.y = 1122333;
Console.WriteLine(rawPos.y);
if (rawPos.y != 1122333)
throw new AccessViolationException();
}
public static void UnitTest_10039()
{
Test10039 obj = new Test10039();
obj.Test();
}
class Test10039
{
TestVector3 m;
TestVector3NoBinding m2;
public void Test()
{
m = new TestVector3();
m2 = TestVector3NoBinding.zero;
UnitTest_10039Sub(m);
UnitTest_10039Sub2(m2);
}
void UnitTest_10039Sub(TestVector3 arg)
{
arg = TestVector3.One2;
if (arg.X != 1)
throw new Exception();
}
void UnitTest_10039Sub2(TestVector3NoBinding arg)
{
arg = TestVector3NoBinding.one;
if (arg.x != 1)
throw new Exception();
}
}
public static void UnitTest_10040()
{
TestVector3 dot = new TestVector3();
dot.X = 10;
dot.Y = 10;
for (int i = 0; i < 50; i++)
{
dot.X++;
}
Console.WriteLine("dot.X == " + dot.X);
if (dot.X != 60)
throw new AccessViolationException();
}
public static void UnitTest_10041()
{
TestVector3NoBinding dot = new TestVector3NoBinding();
dot.x = 10;
dot.x = 10;
for (int i = 0; i < 50; i++)
{
dot.x++;
}
Console.WriteLine("dot.X == " + dot.x);
if (dot.x != 60)
throw new AccessViolationException();
}
static TestVector3 GetVector3()
{
return new TestVector3(123, 123, 123);
}
static Func<TestVector3> GetVector3Func = GetVector3;
public static void UnitTest_10042()
{
TestVector3 pos = GetVector3Func?.Invoke() ?? TestVector3.One2;
if (pos.X != 123)
throw new Exception();
}
public static void UnitTest_10043()
{
SubTestClass test = new SubTestClass();
}
public class TestBase
{
public int a;
public TestVector3 vec = new TestVector3();//有问题
public TestBase()
{
}
}
public class TestClass : TestBase
{
private int b;
public TestClass()
{
}
}
public class SubTestClass : TestClass
{
int c;
public SubTestClass()
{
}
}
class A<T>
{
T value = default;
public A(T value)
{
this.value = value;
}
}
class IntA : A<int>
{
public IntA(int value)
: base(value)
{
}
}
public static void UnitTest_10044()
{
IntA a = new IntA(100);
}
public static void UnitTest_10045()
{
JInt i = new JInt();
if (i++ != 0)
throw new Exception();
if (++i != 2)
throw new Exception();
if (i-- != 2)
throw new Exception();
i -= 10;
if (i != -9)
throw new Exception();
--i;
Console.WriteLine(i);
for (JInt x = 20; x > 0; x--)
{
Console.WriteLine($"for内: x = {x}");
}
}
public static void UnitTest_10046()
{
TestVector3.TestDelegate2 = UnitTest_10046Sub;
TestVector3.DoTest2();
}
static void UnitTest_10046Sub(TestVector3 a)
{
a = a + TestVector3.One2;
Console.WriteLine(a);
if (a.X != 2)
throw new Exception();
}
public static void UnitTest_10047()
{
TestVector3[] arr2 = new TestVector3[10];
arr2[0].X = 1243;
arr2[0] += TestVector3.One;
if(Math.Abs(arr2[0].X - 1244)>0.001f)
throw new Exception();
}
public static void UnitTest_10048()
{
TestVectorClass cls = new TestVectorClass();
TestVectorClass cls2 = new TestVectorClass();
for (int i = 0; i < 3; i++)
{
cls.Vector2 = cls2.Vector2 = new TestVector3(3, 4, i);
Console.WriteLine(cls.Vector2);
}
if (cls.Vector2.Z != 2)
throw new Exception($"cls.Vector2.Z == {cls.Vector2.Z}");
}
static TestStructB mAttr;
public static void UnitTest_10049()
{
MinCirclePath path = new MinCirclePath();
path.Test();
}
public class MinCirclePath
{
private TestStructB mAttr;
public void Test()
{
mAttr = GetAttr();
Console.WriteLine(mAttr);
}
private TestStructB GetAttr()
{
var a = new TestStructA() { value = 5 };
//这样写不会错
//var ret = TestStructB.GetOne(a);
//return ret;
//这样直接返回就会错
return TestStructB.GetOne(a);
}
}
public static void UnitTest_10050()
{
// 热更工程使用
List<TestVector3NoBinding> structs = new List<TestVector3NoBinding>();
for (int i = 0; i < 5; i++)
{
TestVector3NoBinding t = new TestVector3NoBinding();
if (i % 2 != 0)
t.x = i;
structs.Add(t);
}
for (int i = 0; i < 5; i++)
{
var item = structs[i];
Console.WriteLine(item.x);
if (i % 2 != 0)
{
if (item.x != i)
throw new Exception();
}
else
{
if (item.x != 0)
throw new Exception();
}
}
}
public static void UnitTest_10051()
{
var trts = new TestRunTimeStack();
trts.Run();
//Debug.LogFormat("RunTest4");
}
public class BaseObj
{
private Fixed64Vector2 fv2;
public void SetPos(int x, int y)
{
fv2.x = new ILRuntimeTest.TestFramework.Fixed64(x);
}
public BaseObj()
{
int x, y;
x = 123;
y = 456;
fv2 = new Fixed64Vector2(x, y);
}
public Fixed64Vector2 V2
{
get
{
return fv2;
}
}
}
public class TestObj : BaseObj
{
private int n;
}
public class TestRunTimeStack
{
public TestRunTimeStack()
{
}
public void Run()
{
List<TestObj> list = new List<TestObj>();
for (int i = 0; i < 1000; i++)
{
var obj = new TestObj();
obj.SetPos(i, i);
list.Add(obj);
}
list.Sort((a, b) => {
if (a.V2.x < b.V2.x)
return 1;
else if (a.V2.x > b.V2.x)
return -1;
return 0;
});
if (list[0].V2.x.RawValue != 999)
throw new Exception();
}
}
}
}