private static extern void Internal_UT3_ApplyDiff(UT_DiffObj obj);
private static extern void Internal_UT3_GenerateDiff(UT_DiffObj oldObj, UT_DiffObj newObj);
/// <summary> /// Tests managed diff creation used by prefabs. /// </summary> static void UnitTest3_ManagedDiff() { UT_DiffObj original = new UT_DiffObj(); UT_DiffObj modified = new UT_DiffObj(); modified.plain2 = "banana"; modified.complex = new UT_DiffChildObj(); modified.complex2 = null; modified.complex3.plain2 = "tomato"; modified.arrPlain1 = new[] { -1, -2, -3, -4 }; modified.arrPlain2[2] = "cherry"; modified.arrComplex = new UT_DiffChildObj[3]; modified.arrComplex2[0].plain1 = -10; modified.listPlain1[0] = -20; modified.listPlain2 = new List <string>(); modified.listComplex = new List <UT_DiffChildObj>(); modified.listComplex.Add(new UT_DiffChildObj()); modified.listComplex2[1].plain2 = "orange"; modified.dictPlain1.Remove(20); modified.dictPlain1[-30] = -30; modified.dictComplex = new Dictionary <int, UT_DiffChildObj>(); modified.dictComplex[-40] = new UT_DiffChildObj(); modified.dictComplex2[31].plain1 = -50; Internal_UT3_GenerateDiff(original, modified); Internal_UT3_ApplyDiff(original); DebugUnit.Assert(original.plain1 == modified.plain1); DebugUnit.Assert(original.plain2 == modified.plain2); DebugUnit.Assert(original.complex.plain2 == modified.complex.plain2); DebugUnit.Assert(original.complex2 == modified.complex2); DebugUnit.Assert(original.complex3.plain2 == modified.complex3.plain2); DebugUnit.Assert(original.arrPlain1.Length == modified.arrPlain1.Length); for (int i = 0; i < original.arrPlain1.Length; i++) { DebugUnit.Assert(original.arrPlain1[i] == modified.arrPlain1[i]); } for (int i = 0; i < original.arrPlain2.Length; i++) { DebugUnit.Assert(original.arrPlain2[i] == modified.arrPlain2[i]); } for (int i = 0; i < original.arrComplex.Length; i++) { DebugUnit.Assert(original.arrComplex[i] == modified.arrComplex[i]); } DebugUnit.Assert(original.arrComplex2[0].plain1 == modified.arrComplex2[0].plain1); for (int i = 0; i < original.listPlain1.Count; i++) { DebugUnit.Assert(original.listPlain1[i] == modified.listPlain1[i]); } DebugUnit.Assert(original.listPlain2.Count == modified.listPlain2.Count); for (int i = 0; i < original.listComplex.Count; i++) { DebugUnit.Assert(original.listComplex[i].plain1 == modified.listComplex[i].plain1); } DebugUnit.Assert(original.listComplex2[1].plain2 == modified.listComplex2[1].plain2); foreach (var entry in modified.dictPlain1) { if (!original.dictPlain1.ContainsKey(entry.Key)) { DebugUnit.Assert(false); } DebugUnit.Assert(entry.Value == original.dictPlain1[entry.Key]); } foreach (var entry in modified.dictPlain2) { if (!original.dictPlain2.ContainsKey(entry.Key)) { DebugUnit.Assert(false); } DebugUnit.Assert(entry.Value == original.dictPlain2[entry.Key]); } foreach (var entry in modified.dictComplex) { if (!original.dictComplex.ContainsKey(entry.Key)) { DebugUnit.Assert(false); } DebugUnit.Assert(entry.Value.plain1 == original.dictComplex[entry.Key].plain1); } foreach (var entry in modified.dictComplex2) { if (!original.dictComplex2.ContainsKey(entry.Key)) { DebugUnit.Assert(false); } DebugUnit.Assert(entry.Value.plain1 == original.dictComplex2[entry.Key].plain1); } }
/// <summary> /// Tests managed diff creation used by prefabs. /// </summary> static void UnitTest3_ManagedDiff() { UT_DiffObj original = new UT_DiffObj(); UT_DiffObj modified = new UT_DiffObj(); modified.plain2 = "banana"; modified.complex = new UT_DiffChildObj(); modified.complex2 = null; modified.complex3.plain2 = "tomato"; modified.arrPlain1 = new[] {-1, -2, -3, -4}; modified.arrPlain2[2] = "cherry"; modified.arrComplex = new UT_DiffChildObj[3]; modified.arrComplex2[0].plain1 = -10; modified.listPlain1[0] = -20; modified.listPlain2 = new List<string>(); modified.listComplex = new List<UT_DiffChildObj>(); modified.listComplex.Add(new UT_DiffChildObj()); modified.listComplex2[1].plain2 = "orange"; modified.dictPlain1.Remove(20); modified.dictPlain1[-30] = -30; modified.dictComplex = new Dictionary<int, UT_DiffChildObj>(); modified.dictComplex[-40] = new UT_DiffChildObj(); modified.dictComplex2[31].plain1 = -50; Internal_UT3_GenerateDiff(original, modified); Internal_UT3_ApplyDiff(original); DebugUnit.Assert(original.plain1 == modified.plain1); DebugUnit.Assert(original.plain2 == modified.plain2); DebugUnit.Assert(original.complex.plain2 == modified.complex.plain2); DebugUnit.Assert(original.complex2 == modified.complex2); DebugUnit.Assert(original.complex3.plain2 == modified.complex3.plain2); DebugUnit.Assert(original.arrPlain1.Length == modified.arrPlain1.Length); for (int i = 0; i < original.arrPlain1.Length; i++) DebugUnit.Assert(original.arrPlain1[i] == modified.arrPlain1[i]); for (int i = 0; i < original.arrPlain2.Length; i++) DebugUnit.Assert(original.arrPlain2[i] == modified.arrPlain2[i]); for (int i = 0; i < original.arrComplex.Length; i++) DebugUnit.Assert(original.arrComplex[i] == modified.arrComplex[i]); DebugUnit.Assert(original.arrComplex2[0].plain1 == modified.arrComplex2[0].plain1); for (int i = 0; i < original.listPlain1.Count; i++) DebugUnit.Assert(original.listPlain1[i] == modified.listPlain1[i]); DebugUnit.Assert(original.listPlain2.Count == modified.listPlain2.Count); for (int i = 0; i < original.listComplex.Count; i++) DebugUnit.Assert(original.listComplex[i].plain1 == modified.listComplex[i].plain1); DebugUnit.Assert(original.listComplex2[1].plain2 == modified.listComplex2[1].plain2); foreach (var entry in modified.dictPlain1) { if (!original.dictPlain1.ContainsKey(entry.Key)) DebugUnit.Assert(false); DebugUnit.Assert(entry.Value == original.dictPlain1[entry.Key]); } foreach (var entry in modified.dictPlain2) { if (!original.dictPlain2.ContainsKey(entry.Key)) DebugUnit.Assert(false); DebugUnit.Assert(entry.Value == original.dictPlain2[entry.Key]); } foreach (var entry in modified.dictComplex) { if (!original.dictComplex.ContainsKey(entry.Key)) DebugUnit.Assert(false); DebugUnit.Assert(entry.Value.plain1 == original.dictComplex[entry.Key].plain1); } foreach (var entry in modified.dictComplex2) { if (!original.dictComplex2.ContainsKey(entry.Key)) DebugUnit.Assert(false); DebugUnit.Assert(entry.Value.plain1 == original.dictComplex2[entry.Key].plain1); } }