// Verify for single object private static void VerifyInternal(object expectedObject, Obj dsObject, string dsVariable, List <int> indices) { if (expectedObject == null) { if (!dsObject.DsasmValue.IsNull) { Assert.Fail(String.Format("\t{0}{1} is expected to be null, but it isn't.\n{2}", dsVariable, TestFrameWork.BuildIndicesString(indices), TestFrameWork.mErrorMessage)); } return; } Type expectedType = expectedObject.GetType(); if (dsObject.DsasmValue.IsNull && expectedObject != null) { Assert.Fail(String.Format("\tThe value of {0} was null, but wasn't expected to be.\n{1}", dsVariable, mErrorMessage)); } else if (expectedObject is Int32 || expectedObject is Int64) { Int64 expectedValue = Convert.ToInt64(expectedObject); if (!(dsObject.Payload is long)) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is not an integer. \n{2}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } else { TestFrameWork.VerifyPodType(expectedValue, dsObject, dsVariable, indices); } } else if (expectedObject is Double) { Double expectedValue = Convert.ToDouble(expectedObject); if (!(dsObject.Payload is Double)) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is not a double. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } else { try { Double dsValue = Convert.ToDouble(dsObject.Payload); if (!MathUtils.Equals(expectedValue, dsValue)) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is {3}. \n{4}", dsVariable, BuildIndicesString(indices), expectedValue, dsValue, mErrorMessage)); } } catch (System.InvalidCastException) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value can't be converted to Double. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } } } else if (expectedObject is Boolean) { Boolean expectedValue = Convert.ToBoolean(expectedObject); if (!(dsObject.Payload is Boolean)) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual type is not bool. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } else { TestFrameWork.VerifyPodType(expectedValue, dsObject, dsVariable, indices); } } else if (expectedObject is Char) { Char expectedValue = Convert.ToChar(expectedObject); if (!(dsObject.Payload is long)) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual type is not char. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } else { try { Int64 utf8Encoding = Convert.ToInt64(dsObject.Payload); Char dsValue = Convert.ToChar(utf8Encoding); if (!expectedObject.Equals(dsValue)) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is {3}. \n{4}", dsVariable, BuildIndicesString(indices), expectedValue, dsValue, mErrorMessage)); } } catch (System.InvalidCastException) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value can't be converted to Char. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } } } else if (expectedObject is String) { string stringValue = dsObject.Payload as string; if (stringValue == null) { Assert.Fail(String.Format("\t{0}{1} is expected to be a string, but its actual value is not a string\n{2}", dsVariable, BuildIndicesString(indices), mErrorMessage)); } else if (!expectedObject.Equals(stringValue)) { Assert.Fail(String.Format("\t{0}{1} is expected to be a string \"{2}\", but its actual value is \"{3}\".\n{4}", dsVariable, BuildIndicesString(indices), expectedObject, stringValue, mErrorMessage)); } } else if (typeof(IEnumerable).IsAssignableFrom(expectedType)) { IEnumerable collection = expectedObject as IEnumerable; int index = 0; ProtoCore.DSASM.Mirror.DsasmArray dsArray = dsObject.Payload as ProtoCore.DSASM.Mirror.DsasmArray; if (dsArray == null) { Assert.Fail(String.Format("{0}{1} is expected to be an array, but its actual value isn't an array.\n{2}", dsVariable, BuildIndicesString(indices), mErrorMessage)); } foreach (var item in collection) { indices.Add(index); VerifyInternal(item, dsArray.members[index], dsVariable, indices); indices.RemoveAt(indices.Count - 1); ++index; } } else { Assert.Fail(string.Format("\tUnexpected object type.\n{0}", mErrorMessage)); } }
// Verify for single object private static void VerifyInternal(object expectedObject, Obj dsObject, string dsVariable, List <int> indices) { if (expectedObject == null) { if (dsObject.DsasmValue.optype != ProtoCore.DSASM.AddressType.Null) { Assert.Fail(String.Format("\t{0}{1} is expected to be null, but it isn't.\n{2}", dsVariable, TestFrameWork.BuildIndicesString(indices), TestFrameWork.mErrorMessage)); } } else if (dsObject.DsasmValue.optype == ProtoCore.DSASM.AddressType.Null && expectedObject != null) { Assert.Fail(String.Format("\tThe value of {0} was null, but wasn't expected to be.\n{1}", dsVariable, mErrorMessage)); } else if (expectedObject is Int32 || expectedObject is Int64) { Int64 expectedValue = Convert.ToInt64(expectedObject); if (dsObject.Type.UID != (int)ProtoCore.PrimitiveType.kTypeInt) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is not an integer. \n{2}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } else { TestFrameWork.VerifyPodType(expectedValue, dsObject, dsVariable, indices); } } else if (expectedObject is Double) { Double expectedValue = Convert.ToDouble(expectedObject); if (dsObject.Type.UID != (int)ProtoCore.PrimitiveType.kTypeDouble) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is not a double. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } else { try { Double dsValue = Convert.ToDouble(dsObject.Payload); if (!MathUtils.Equals(expectedValue, dsValue)) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is {3}. \n{4}", dsVariable, BuildIndicesString(indices), expectedValue, dsValue, mErrorMessage)); } } catch (System.InvalidCastException) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value can't be converted to Double. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } } } else if (expectedObject is Boolean) { Boolean expectedValue = Convert.ToBoolean(expectedObject); if (dsObject.Type.UID != (int)ProtoCore.PrimitiveType.kTypeBool) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual type is not bool. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } else { TestFrameWork.VerifyPodType(expectedValue, dsObject, dsVariable, indices); } } else if (expectedObject is Char) { Char expectedValue = Convert.ToChar(expectedObject); if (dsObject.Type.UID != (int)ProtoCore.PrimitiveType.kTypeChar) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual type is not char. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } else { try { Int64 utf8Encoding = Convert.ToInt64(dsObject.Payload); Char dsValue = EncodingUtils.ConvertInt64ToCharacter(utf8Encoding); if (!expectedObject.Equals(dsValue)) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value is {3}. \n{4}", dsVariable, BuildIndicesString(indices), expectedValue, dsValue, mErrorMessage)); } } catch (System.InvalidCastException) { Assert.Fail(String.Format("\t{0}{1} is expected to be {2}, but its actual value can't be converted to Char. \n{3}", dsVariable, BuildIndicesString(indices), expectedValue, mErrorMessage)); } } } else if (expectedObject is String) { char[] chars = (expectedObject as String).ToCharArray(); object[] objs = new object[chars.Length]; Array.Copy(chars, objs, chars.Length); ProtoCore.DSASM.Mirror.DsasmArray dsArray = dsObject.Payload as ProtoCore.DSASM.Mirror.DsasmArray; if (dsArray == null) { Assert.Fail(String.Format("\t{0}{1} is expected to be a string, but its actual value is not a string\n{2}", dsVariable, BuildIndicesString(indices), mErrorMessage)); } else if (chars.Count() != dsArray.members.Count()) { Assert.Fail(String.Format("\t{0}{1} is expected to be a string of length {2}, but its actual length is {3}.\n{4}", dsVariable, BuildIndicesString(indices), objs.Count(), dsArray.members.Count(), mErrorMessage)); } else { for (int i = 0; i < objs.Count(); ++i) { indices.Add(i); TestFrameWork.VerifyInternal(objs[i], dsArray.members[i], dsVariable, indices); indices.RemoveAt(indices.Count - 1); } } // VerifyInternal(objs, dsObject, dsVariable, indices); } else if (expectedObject.GetType().IsArray) { object[] expectedArray = expectedObject as object[]; ProtoCore.DSASM.Mirror.DsasmArray dsArray = dsObject.Payload as ProtoCore.DSASM.Mirror.DsasmArray; if (dsArray == null) { Assert.Fail(String.Format("{0}{1} is expected to be an array, but its actual value isn't an array.\n{2}", dsVariable, BuildIndicesString(indices), mErrorMessage)); } else if (expectedArray.Count() != dsArray.members.Count()) { Assert.Fail(String.Format("{0}{1} is expected to be an array of length {2}, but its actual length is {3}.\n{4}", dsVariable, BuildIndicesString(indices), expectedArray.Count(), dsArray.members.Count(), mErrorMessage)); } else { for (int i = 0; i < expectedArray.Count(); ++i) { indices.Add(i); VerifyInternal(expectedArray[i], dsArray.members[i], dsVariable, indices); indices.RemoveAt(indices.Count - 1); } } } else { Assert.Fail(string.Format("\tUnexpected object type.\n{0}", mErrorMessage)); } }