public void TestGetSingleTypes() { var emptyIpcData = new IpcData(); emptyIpcData.Add( "Hello" ); emptyIpcData.Add( "World" ); // check the values. Assert.AreEqual( "Hello", emptyIpcData.Get<string>(0)); Assert.AreEqual( "World", emptyIpcData.Get<string>(1)); }
public void TestGetDifferentTypes() { var emptyIpcData = new IpcData(); emptyIpcData.Add("Hello"); emptyIpcData.Add("World"); emptyIpcData.Add( 42 ); emptyIpcData.Add( "Something", false ); // check the values. Assert.AreEqual("Hello", emptyIpcData.Get<string>(0)); Assert.AreEqual("World", emptyIpcData.Get<string>(1)); Assert.AreEqual(42, emptyIpcData.Get<int>(2)); Assert.AreEqual("Something", emptyIpcData.Get<string>(3)); }
public void TestFromInt32ToPtrAndBack() { var ipc = new IpcData(); var uuid = ipc.Guid; var random = new Random(); var n = (Int32)random.Next(0, Int32.MaxValue); ipc.Add(Int32.MaxValue); ipc.Add(n); var payload = ipc.GetPtr(); var dataBlockSize = ipc.GetSize(); var byteArray = new byte[dataBlockSize]; System.Runtime.InteropServices.Marshal.Copy(payload, byteArray, 0, dataBlockSize); var ipc2 = new IpcData(byteArray); Assert.AreEqual(uuid, ipc2.Guid); Assert.AreEqual(Int32.MaxValue, ipc2.Get<Int32>(0)); Assert.AreEqual(n, ipc2.Get<Int32>(1)); }
public void TestGetBooleanNeitherTrueNorFalseString() { var emptyIpcData = new IpcData(); emptyIpcData.Add("NotAValidString"); emptyIpcData.Get<bool>(0); }
public void TestGetBooleanFalseString() { var emptyIpcData = new IpcData(); emptyIpcData.Add("False"); Assert.IsFalse(emptyIpcData.Get<bool>(0)); }
public void TestGetBooleanTrueString() { var emptyIpcData = new IpcData(); emptyIpcData.Add("True"); Assert.IsTrue(emptyIpcData.Get<bool>(0)); }
public void TestGetBooleanFromIntegerNotEqualOne() { var random = new Random(); var r = random.Next(2, Int32.MaxValue); if(random.Next(0, 1) == 1) { r *= -1; } var emptyIpcData = new IpcData(); emptyIpcData.Add(1); Assert.IsTrue(emptyIpcData.Get<bool>(0)); }
public void TestTryingToGetAnEmptyItemOutOfRange() { var emptyIpcData = new IpcData(); emptyIpcData.Get<object>(0); }
public void TestIsNumericPastGuidAndStrings() { var random = new Random(); var r1 = random.Next(0, int.MaxValue); var r2 = random.Next(0, int.MaxValue); var emptyIpcData = new IpcData(); emptyIpcData.Add(r1); emptyIpcData.Add("Hello"); emptyIpcData.Add(r2); Assert.IsTrue(emptyIpcData.IsInt(0)); Assert.IsFalse(emptyIpcData.IsInt(1)); Assert.IsTrue(emptyIpcData.IsInt(2)); Assert.AreEqual(r1, emptyIpcData.Get<int>(0)); Assert.AreEqual(r2, emptyIpcData.Get<int>(2)); }
public void TestAsciiStringIsString() { // give a data type of int32, but no data to read var emptyIpcData = new IpcData(new byte[] { 100, 0, 0, 0, // version (byte) ExpectedIpcDataType.StringAscii, 0, // data type string 5, 0, 0,0, // the len (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o', }); Assert.IsTrue(emptyIpcData.IsString(0)); Assert.AreEqual("hello", emptyIpcData.Get<string>(0)); }
public void TestByteArraySetsIntFourBytes() { var random = new Random(); var r1 = (byte)random.Next(0, 255); var r2 = (byte)random.Next(0, 255); var r3 = (byte)random.Next(0, 255); var r4 = (byte)random.Next(0, 255); // give a data type of int32, but no data to read var emptyIpcData = new IpcData(new byte[] { 100, 0, 0, 0, // version (byte) ExpectedIpcDataType.Int32, 0, // data type int r1, r2, r3,r4 // int value }); Assert.AreEqual((r1 + r2 * 256 + r3 * 256 * 256 + r4 * 256 * 256*256), emptyIpcData.Get<int>(0)); }
public void TestByteArraySetsIntOneByte() { var random = new Random(); var r1 = (byte)random.Next(0, 255); // give a data type of int32, but no data to read var emptyIpcData = new IpcData(new byte[] { 100, 0, 0, 0, // version (byte) ExpectedIpcDataType.Int32, 0, // data type int r1, 0, 0,0 // int value }); Assert.AreEqual(r1 , emptyIpcData.Get<int>(0)); }
public void TestANumberCanBeCastToAString() { var emptyIpcData = new IpcData(); emptyIpcData.Add( 12 ); // we can cast the number to a string. Assert.AreEqual( "12", emptyIpcData.Get<string>(0) ); }
public void TestTryingtogetANumberWhenTheArgumentIsAString() { var emptyIpcData = new IpcData(); emptyIpcData.Add("Hello"); // this is not a number. emptyIpcData.Get<long>(0); }
public void TestFromInt64And32ToPtrAndBack() { var ipc = new IpcData(); var random = new Random(); var m = (int)(random.NextDouble() * int.MaxValue); var n = (long)(random.NextDouble() * long.MaxValue); var uuid = ipc.Guid; ipc.Add(m); ipc.Add(n); var payload = ipc.GetPtr(); var dataBlockSize = ipc.GetSize(); var byteArray = new byte[dataBlockSize]; System.Runtime.InteropServices.Marshal.Copy(payload, byteArray, 0, dataBlockSize); var ipc2 = new IpcData(byteArray); Assert.AreEqual(uuid, ipc2.Guid); Assert.AreEqual(m, ipc2.Get<int>(0)); Assert.AreEqual(n, ipc2.Get<long>(1)); }
public void TestIsNumericPastGuidAndInteger() { var random = new Random(); var r1 = random.Next(0, Int32.MaxValue); var emptyIpcData = new IpcData(); emptyIpcData.Add("Hello1"); emptyIpcData.Add(r1); emptyIpcData.Add("Hello2"); Assert.IsTrue(emptyIpcData.IsString(0)); Assert.IsFalse(emptyIpcData.IsString(1)); Assert.IsTrue(emptyIpcData.IsString(2)); Assert.AreEqual("Hello1", emptyIpcData.Get<string>(0)); Assert.AreEqual("Hello2", emptyIpcData.Get<string>(2)); }
public void TestFromInt32CanBeConvertedToInt64() { var ipc = new IpcData(); var random = new Random(); var m = (int)(random.NextDouble() * int.MaxValue); var n = (long)(random.NextDouble() * long.MaxValue); ipc.Add(m); ipc.Add(n); Assert.AreEqual(m, ipc.Get<int>(0)); Assert.AreEqual(m, ipc.Get<long>(0)); // as a long Assert.AreEqual(n, ipc.Get<long>(1)); }
public void TestGetBooleanFromIntegerEqualOne() { var emptyIpcData = new IpcData(); emptyIpcData.Add(1); Assert.IsTrue(emptyIpcData.Get<bool>(0)); }
public void TestTryingToGetANonEmptyItemOutOfRange() { var emptyIpcData = new IpcData(); emptyIpcData.Add(42); Assert.AreEqual(42, emptyIpcData.Get<int>(0)); // out of range emptyIpcData.Get<object>(1); }
public void TestCastingToDifferentNumbers() { var emptyIpcData = new IpcData(); emptyIpcData.Add(42); emptyIpcData.Add(52); emptyIpcData.Add(67); // check the values. Assert.AreEqual((long)42, emptyIpcData.Get<long>(0)); Assert.AreEqual((uint)52, emptyIpcData.Get<uint>(1)); Assert.AreEqual((int)67, emptyIpcData.Get<int>(2)); Assert.AreEqual((short)67, emptyIpcData.Get<short>(2)); Assert.AreEqual((double)67, emptyIpcData.Get<double>(2)); Assert.AreEqual((float)67, emptyIpcData.Get<float>(2)); }