private static extern void Internal_UT3_GenerateDiff(UT_DiffObj oldObj, UT_DiffObj newObj);
private static extern void Internal_UT3_ApplyDiff(UT_DiffObj obj);
/// <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); Assert(original.plain1 == modified.plain1); Assert(original.plain2 == modified.plain2); Assert(original.complex.plain2 == modified.complex.plain2); Assert(original.complex2 == modified.complex2); Assert(original.complex3.plain2 == modified.complex3.plain2); Assert(original.arrPlain1.Length == modified.arrPlain1.Length); for (int i = 0; i < original.arrPlain1.Length; i++) { Assert(original.arrPlain1[i] == modified.arrPlain1[i]); } for (int i = 0; i < original.arrPlain2.Length; i++) { Assert(original.arrPlain2[i] == modified.arrPlain2[i]); } for (int i = 0; i < original.arrComplex.Length; i++) { Assert(original.arrComplex[i] == modified.arrComplex[i]); } Assert(original.arrComplex2[0].plain1 == modified.arrComplex2[0].plain1); for (int i = 0; i < original.listPlain1.Count; i++) { Assert(original.listPlain1[i] == modified.listPlain1[i]); } Assert(original.listPlain2.Count == modified.listPlain2.Count); for (int i = 0; i < original.listComplex.Count; i++) { Assert(original.listComplex[i].plain1 == modified.listComplex[i].plain1); } Assert(original.listComplex2[1].plain2 == modified.listComplex2[1].plain2); foreach (var entry in modified.dictPlain1) { if (!original.dictPlain1.ContainsKey(entry.Key)) { Assert(false); } Assert(entry.Value == original.dictPlain1[entry.Key]); } foreach (var entry in modified.dictPlain2) { if (!original.dictPlain2.ContainsKey(entry.Key)) { Assert(false); } Assert(entry.Value == original.dictPlain2[entry.Key]); } foreach (var entry in modified.dictComplex) { if (!original.dictComplex.ContainsKey(entry.Key)) { Assert(false); } Assert(entry.Value.plain1 == original.dictComplex[entry.Key].plain1); } foreach (var entry in modified.dictComplex2) { if (!original.dictComplex2.ContainsKey(entry.Key)) { Assert(false); } Assert(entry.Value.plain1 == original.dictComplex2[entry.Key].plain1); } }