public void Msg_Serialize_Guids() { Msg msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); msgOut = new Msg(); Assert.AreEqual(Guid.Empty, msgOut._MsgID); Assert.AreEqual(Guid.Empty, msgOut._SessionID); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = Msg.Load(es); Assert.AreEqual(Guid.Empty, msgIn._MsgID); Assert.AreEqual(Guid.Empty, msgIn._SessionID); msgOut._MsgID = Helper.NewGuid(); msgOut._SessionID = Helper.NewGuid(); es.SetLength(0); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = Msg.Load(es); Assert.AreEqual(msgOut._MsgID, msgIn._MsgID); Assert.AreEqual(msgOut._SessionID, msgIn._SessionID); }
public void EnhancedMemoryStream_Bytes32() { var es = new EnhancedMemoryStream(); byte[] read, write; es.WriteBytes32(null); es.Seek(0, SeekOrigin.Begin); read = es.ReadBytes32(); Assert.IsNull(read); write = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; es.Seek(0, SeekOrigin.Begin); es.WriteBytes32(write); es.Seek(0, SeekOrigin.Begin); read = es.ReadBytes32(); CollectionAssert.AreEqual(write, read); write = new byte[40000]; for (int i = 0; i < write.Length; i++) { write[i] = (byte)i; } es.Seek(0, SeekOrigin.Begin); es.WriteBytes32(write); es.Seek(0, SeekOrigin.Begin); read = es.ReadBytes32(); CollectionAssert.AreEqual(write, read); }
public void Msg_Serialize_SecurityToken() { Msg msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); msgOut = new Msg(); Assert.IsNull(msgOut._SecurityToken); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = Msg.Load(es); Assert.IsNull(msgOut._SecurityToken); msgOut._SecurityToken = new byte[] { 0, 1, 2, 3, 4 }; es.SetLength(0); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = Msg.Load(es); CollectionAssert.AreEqual(msgOut._SecurityToken, msgIn._SecurityToken); }
public void Msg_Serialize_BaseMsg() { Msg msg; EnhancedStream es = new EnhancedMemoryStream(); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); msg = new Msg(); msg._Version = 77; msg._Flags |= MsgFlag.Broadcast; es.SetLength(0); Msg.Save(es, msg); es.Seek(0, SeekOrigin.Begin); msg = (Msg)Msg.Load(es); Assert.IsNotNull(msg); Assert.AreEqual(77, msg._Version); Assert.AreEqual(MsgFlag.Broadcast, msg._Flags); msg = new Msg(); msg._Version = 77; msg._Flags |= MsgFlag.Broadcast | MsgFlag.OpenSession; es.SetLength(0); Msg.Save(es, msg); es.Seek(0, SeekOrigin.Begin); msg = (Msg)Msg.Load(es); Assert.IsNotNull(msg); Assert.AreEqual(77, msg._Version); Assert.AreEqual(MsgFlag.Broadcast | MsgFlag.OpenSession, msg._Flags); }
public void ReliableMessengerMsgs_DeliveryMsg_Serialize() { DeliveryMsg msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); DateTime now = Helper.UtcNowRounded; Guid id = Helper.NewGuid(); PropertyMsg query; PropertyMsg response; Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); query = new PropertyMsg(); query["hello"] = "world"; response = new PropertyMsg(); response["foo"] = "bar"; msgOut = new DeliveryMsg(DeliveryOperation.Attempt, now, "logical://foo", "logical://bar", query, id, "clusterInfo", "clusterParam", new TimeoutException("Timeout"), response); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (DeliveryMsg)Msg.Load(es); Assert.IsNotNull(msgIn); Assert.AreEqual(DeliveryOperation.Attempt, msgIn.Operation); Assert.AreEqual(now, msgIn.Timestamp); Assert.AreEqual(MsgEP.Parse("logical://foo"), msgIn.TargetEP); Assert.AreEqual(MsgEP.Parse("logical://bar"), msgIn.ConfirmEP); Assert.IsInstanceOfType(msgIn.Query, typeof(PropertyMsg)); Assert.AreEqual("world", ((PropertyMsg)msgIn.Query)["hello"]); Assert.AreEqual(id, msgIn.TopologyID); Assert.AreEqual("clusterInfo", msgIn.TopologyInfo); Assert.AreEqual("clusterParam", msgIn.TopologyParam); Assert.IsInstanceOfType(msgIn.Exception, typeof(TimeoutException)); Assert.AreEqual("Timeout", msgIn.Exception.Message); Assert.IsInstanceOfType(msgIn.Response, typeof(PropertyMsg)); Assert.AreEqual("bar", ((PropertyMsg)msgIn.Response)["foo"]); msgOut = new DeliveryMsg(DeliveryOperation.Confirmation, now, "logical://foo", null, query, id, null, null, new ArgumentException("Test"), null); es.SetLength(0); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (DeliveryMsg)Msg.Load(es); Assert.IsNotNull(msgIn); Assert.AreEqual(DeliveryOperation.Confirmation, msgIn.Operation); Assert.AreEqual(now, msgIn.Timestamp); Assert.AreEqual(MsgEP.Parse("logical://foo"), msgIn.TargetEP); Assert.IsNull(msgIn.ConfirmEP); Assert.IsInstanceOfType(msgIn.Query, typeof(PropertyMsg)); Assert.AreEqual("world", ((PropertyMsg)msgIn.Query)["hello"]); Assert.AreEqual(id, msgIn.TopologyID); Assert.IsNull(msgIn.TopologyInfo); Assert.IsNull(msgIn.TopologyParam); Assert.IsInstanceOfType(msgIn.Exception, typeof(SessionException)); Assert.AreEqual("Test", msgIn.Exception.Message); Assert.IsNull(msgIn.Response); }
public void Hashers_MD5() { EnhancedMemoryStream ms; byte[] data; byte[] digest1, digest2; digest1 = MD5Hasher.Compute(new byte[] { 0, 1, 2, 3 }, 0, 4); Assert.AreEqual(16, digest1.Length); Assert.AreEqual(16, MD5Hasher.DigestSize); digest2 = MD5Hasher.Compute(new byte[] { 1, 1, 2, 3 }, 0, 4); Assert.AreNotEqual(digest1, digest2); digest1 = MD5Hasher.Compute(new byte[0]); Assert.AreEqual(16, digest1.Length); Assert.AreEqual(16, MD5Hasher.DigestSize); digest1 = MD5Hasher.Compute(new byte[] { 0, 1, 2, 3 }); ms = new EnhancedMemoryStream(); ms.Seek(0, SeekOrigin.Begin); ms.Write(new byte[] { 0, 1, 2, 3 }, 0, 4); ms.Seek(0, SeekOrigin.Begin); digest2 = MD5Hasher.Compute(ms, 4); CollectionAssert.AreEqual(digest1, digest2); Assert.AreEqual(16, digest2.Length); Assert.AreEqual(0, ms.Position); data = new byte[2048]; for (int i = 0; i < data.Length; i++) { data[i] = (byte)i; } digest1 = MD5Hasher.Compute(data); ms.Seek(0, SeekOrigin.Begin); ms.Write(data, 0, data.Length); ms.Seek(0, SeekOrigin.Begin); digest2 = MD5Hasher.Compute(ms, data.Length); CollectionAssert.AreEqual(digest1, digest2); Assert.AreEqual(16, digest2.Length); Assert.AreEqual(0, ms.Position); digest1 = MD5Hasher.Compute("hello"); digest2 = MD5Hasher.Compute("world"); CollectionAssert.AreNotEqual(digest1, digest2); CollectionAssert.AreEqual(digest1, MD5Hasher.Compute("hello")); // These really aren't very good tests for folding but // at least they'll verify that it doesn't crash Assert.AreEqual(MD5Hasher.FoldOnce(new byte[] { 0, 1, 2, 3 }), MD5Hasher.FoldOnce(new byte[] { 0, 1, 2, 3 })); Assert.AreNotEqual((object)MD5Hasher.FoldOnce(new byte[] { 1, 1, 2, 3 }), (object)MD5Hasher.FoldOnce(new byte[] { 0, 1, 2, 3 })); Assert.AreEqual(MD5Hasher.FoldTwice(new byte[] { 0, 1, 2, 3 }), MD5Hasher.FoldTwice(new byte[] { 0, 1, 2, 3 })); Assert.AreNotEqual(MD5Hasher.FoldTwice(new byte[] { 1, 1, 2, 3 }), MD5Hasher.FoldTwice(new byte[] { 0, 1, 2, 3 })); }
public void ObjectGraphAck_Serialize() { ObjectGraphAck msgOut, msgIn; EnhancedMemoryStream ms = new EnhancedMemoryStream(); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); msgOut = new ObjectGraphAck("hello world", Compress.Always); Msg.Save(ms, msgOut); ms.Seek(0, SeekOrigin.Begin); msgIn = (ObjectGraphAck)Msg.Load(ms); Assert.AreEqual("hello world", msgIn.Graph); //----------------------------------- ms.SetLength(0); msgOut = new ObjectGraphAck(new string[] { "a", "b", "c" }, Compress.Always); Msg.Save(ms, msgOut); ms.Seek(0, SeekOrigin.Begin); msgIn = (ObjectGraphAck)Msg.Load(ms); CollectionAssert.AreEqual(new string[] { "a", "b", "c" }, (string[])msgIn.Graph); //----------------------------------- ms.SetLength(0); msgOut = new ObjectGraphAck(new TimeoutException("timeout")); Msg.Save(ms, msgOut); ms.Seek(0, SeekOrigin.Begin); msgIn = (ObjectGraphAck)Msg.Load(ms); Assert.AreEqual("timeout", msgIn.Exception); //----------------------------------- ms.SetLength(0); msgOut = new ObjectGraphAck(null, Compress.Always); Msg.Save(ms, msgOut); ms.Seek(0, SeekOrigin.Begin); msgIn = (ObjectGraphAck)Msg.Load(ms); Assert.IsNull(msgIn.Graph); }
public void Hashers_SHA512() { EnhancedMemoryStream ms; byte[] data; byte[] digest1, digest2; digest1 = SHA512Hasher.Compute(new byte[] { 0, 1, 2, 3 }, 0, 4); Assert.AreEqual(64, digest1.Length); Assert.AreEqual(64, SHA512Hasher.DigestSize); digest2 = SHA512Hasher.Compute(new byte[] { 1, 1, 2, 3 }, 0, 4); CollectionAssert.AreNotEqual(digest1, digest2); digest1 = SHA512Hasher.Compute(new byte[0]); Assert.AreEqual(64, digest1.Length); Assert.AreEqual(64, SHA512Hasher.DigestSize); digest1 = SHA512Hasher.Compute(new byte[] { 0, 1, 2, 3 }); ms = new EnhancedMemoryStream(); ms.Seek(0, SeekOrigin.Begin); ms.Write(new byte[] { 0, 1, 2, 3 }, 0, 4); ms.Seek(0, SeekOrigin.Begin); digest2 = SHA512Hasher.Compute(ms, 4); CollectionAssert.AreEqual(digest1, digest2); Assert.AreEqual(64, digest2.Length); Assert.AreEqual(0, ms.Position); data = new byte[2048]; for (int i = 0; i < data.Length; i++) { data[i] = (byte)i; } digest1 = SHA512Hasher.Compute(data); ms.Seek(0, SeekOrigin.Begin); ms.Write(data, 0, data.Length); ms.Seek(0, SeekOrigin.Begin); digest2 = SHA512Hasher.Compute(ms, data.Length); CollectionAssert.AreEqual(digest1, digest2); Assert.AreEqual(64, digest2.Length); Assert.AreEqual(0, ms.Position); digest1 = SHA512Hasher.Compute("hello"); digest2 = SHA512Hasher.Compute("world"); CollectionAssert.AreNotEqual(digest1, digest2); CollectionAssert.AreEqual(digest1, SHA512Hasher.Compute("hello")); }
public void Msg_Serialize_RouteAdvertiseMsg() { RouterAdvertiseMsg msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); msgOut = new RouterAdvertiseMsg(MsgEP.Parse("physical://root.com:80/hub/leaf"), "appname", "appdescription", new MsgRouterInfo(new Version(1000, 0)), 10, 20, Helper.NewGuid(), false, true); msgOut._FromEP = MsgEP.Parse("physical://root.com:80/hub/leaf?c=mcast://1.2.3.4:57"); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (RouterAdvertiseMsg)Msg.Load(es); Assert.AreEqual("physical://root.com:80/hub/leaf", msgIn.RouterEP.ToString()); Assert.AreEqual("appname", msgIn.AppName); Assert.AreEqual("appdescription", msgIn.AppDescription); Assert.AreEqual(new Version(1000, 0), msgIn.RouterInfo.ProtocolVersion); Assert.AreEqual(IPAddress.Parse("1.2.3.4"), msgIn.IPAddress); Assert.AreEqual(10, msgIn.UdpPort); Assert.AreEqual(20, msgIn.TcpPort); Assert.AreEqual(msgOut.LogicalEndpointSetID, msgIn.LogicalEndpointSetID); Assert.IsFalse(msgIn.ReplyAdvertise); Assert.IsTrue(msgIn.DiscoverLogical); Assert.IsTrue(msgIn.RouterInfo.IsP2P); }
public void SentinelServiceMsgs_LogEventMsg_Serialize() { LogEventMsg msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); EventLog log = new EventLog("Application"); EventLogEntry entry; // Clear the log and then add an entry so we can retrieve it right // away (hopefully getting the same entry back). log.Source = "Application"; log.Clear(); log.WriteEntry("Test entry", EventLogEntryType.Information, 0, 0, new byte[] { 0, 1, 2, 3 }); entry = log.Entries[0]; msgOut = new LogEventMsg("Application", entry); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (LogEventMsg)Msg.Load(es); Assert.AreEqual("Application", msgIn.LogName); Assert.AreEqual(entry.EntryType, msgIn.EntryType); Assert.AreEqual(entry.TimeGenerated.ToUniversalTime(), msgIn.Time); Assert.AreEqual(entry.MachineName, msgIn.MachineName); Assert.AreEqual(entry.Message, msgIn.Message); CollectionAssert.AreEqual(new byte[] { 0, 1, 2, 3 }, msgIn.Data); }
public void PropertyMsg_Serialize() { PropertyMsg msgOut, msgIn; EnhancedMemoryStream ms = new EnhancedMemoryStream(); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); msgOut = new PropertyMsg(); msgOut._Set("string", "hello"); msgOut._Set("bool", true); msgOut._Set("int", 10); msgOut._Set("timespan", new TimeSpan(0, 0, 0, 0, 55)); msgOut._Set("endpoint", new IPEndPoint(IPAddress.Parse("127.0.0.1"), 56)); msgOut._Set("bytes", new byte[] { 5, 6, 7, 8 }); msgOut._Set("address", IPAddress.Parse("10.20.30.40")); Msg.Save(ms, msgOut); ms.Seek(0, SeekOrigin.Begin); msgIn = (PropertyMsg)Msg.Load(ms); Assert.AreEqual(msgOut["string"], msgIn["string"]); Assert.AreEqual(msgOut["bool"], msgIn["bool"]); Assert.AreEqual(msgOut["int"], msgIn["int"]); Assert.AreEqual(msgOut["timespan"], msgIn["timespan"]); Assert.AreEqual(msgOut["endpoint"], msgIn["endpoint"]); Assert.AreEqual(msgOut["bytes"], msgIn["bytes"]); Assert.AreEqual(msgOut["address"], msgIn["address"]); }
public void Msg_Serialize_TestMsg() { _TestMsg2 msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); msgOut = new _TestMsg2(); msgOut.BoolValue = false; msgOut.ByteValue = 0xAA; msgOut.BytesValue = new byte[] { 0, 1, 2, 3 }; msgOut.FloatValue = 10.77F; msgOut.Int16Value = 32000; msgOut.Int32Value = 100000; msgOut.Int64Value = 8000000000; msgOut.StringValue = "Hello World!"; Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (_TestMsg2)Msg.Load(es); Assert.AreEqual(msgOut.BoolValue, msgIn.BoolValue); Assert.AreEqual(msgOut.ByteValue, msgIn.ByteValue); CollectionAssert.AreEqual(msgOut.BytesValue, msgIn.BytesValue); Assert.AreEqual(msgOut.FloatValue, msgIn.FloatValue); Assert.AreEqual(msgOut.Int16Value, msgIn.Int16Value); Assert.AreEqual(msgOut.Int32Value, msgIn.Int32Value); Assert.AreEqual(msgOut.Int64Value, msgIn.Int64Value); Assert.AreEqual(msgOut.StringValue, msgIn.StringValue); Assert.AreEqual(0, msgIn._Version); Assert.IsNull(msgIn._ToEP); Assert.IsNull(msgIn._FromEP); }
public void BlobPropertyMsg_SerializeBase() { _BlobPropMsg msgOut, msgIn; EnhancedMemoryStream ms = new EnhancedMemoryStream(); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); msgOut = new _BlobPropMsg(); msgOut._Set("string", "hello"); msgOut._Set("bool", true); msgOut._Set("int", 10); msgOut._Set("timespan", new TimeSpan(0, 0, 0, 0, 55)); msgOut._Set("endpoint", new IPEndPoint(IPAddress.Parse("127.0.0.1"), 56)); msgOut._Set("bytes", new byte[] { 5, 6, 7, 8 }); msgOut._Data = new byte[] { 0, 1, 2 }; msgOut.Value = "foobar"; Msg.Save(ms, msgOut); ms.Seek(0, SeekOrigin.Begin); msgIn = (_BlobPropMsg)Msg.Load(ms); Assert.AreEqual(msgOut["string"], msgIn["string"]); Assert.AreEqual(msgOut["bool"], msgIn["bool"]); Assert.AreEqual(msgOut["int"], msgIn["int"]); Assert.AreEqual(msgOut["timespan"], msgIn["timespan"]); Assert.AreEqual(msgOut["endpoint"], msgIn["endpoint"]); Assert.AreEqual(msgOut["bytes"], msgIn["bytes"]); CollectionAssert.AreEqual(msgOut._Data, msgIn._Data); Assert.AreEqual("foobar", msgIn.Value); }
public void EnhancedMemoryStream_ReadWriteBytesNoLen() { var es = new EnhancedMemoryStream(); es.WriteBytesNoLen(new byte[] { 0, 1, 2, 3 }); es.Seek(0, SeekOrigin.Begin); CollectionAssert.AreEqual(new byte[] { 0, 1, 2, 3 }, es.ReadBytes(4)); }
public void EnhancedMemoryStream_VerifyBufLength() { var es = new EnhancedMemoryStream(); es.WriteInt16(5000); es.Seek(0, SeekOrigin.Begin); try { es.ReadBytes16(); Assert.Fail(); } catch { } es.Seek(0, SeekOrigin.Begin); try { es.ReadString16(); Assert.Fail(); } catch { } es.Seek(0, SeekOrigin.Begin); es.WriteInt32(500000); try { es.ReadBytes32(); Assert.Fail(); } catch { } es.Seek(0, SeekOrigin.Begin); try { es.ReadString32(); Assert.Fail(); } catch { } }
public void EnhancedMemoryStream_Float() { var es = new EnhancedMemoryStream(); float f; es.WriteFloat((float)123.456); es.Seek(0, SeekOrigin.Begin); f = es.ReadFloat(); Assert.AreEqual((float)123.456, f); }
public void EnhancedMemoryStream_ReadStringCb() { var es = new EnhancedMemoryStream(); int cb; es.WriteStringNoLen("Hello World!"); cb = (int)es.Position; es.Seek(0, SeekOrigin.Begin); Assert.AreEqual("Hello World!", es.ReadString(cb)); }
public void SentinelServiceMsgs_ConnectAck_Serialize() { ConnectAck msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); msgOut = new ConnectAck("logical://foo"); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (ConnectAck)Msg.Load(es); Assert.AreEqual(MsgEP.Parse("logical://foo"), msgIn.InstanceEP); }
public void SentinelServiceMsgs_LogEventAck_Serialize() { LogEventAck msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); msgOut = new LogEventAck(); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (LogEventAck)Msg.Load(es); Assert.IsNotNull(msgIn); }
public void SentinelServiceMsgs_ConnectMsg_Serialize() { ConnectMsg msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); msgOut = new ConnectMsg(); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (ConnectMsg)Msg.Load(es); Assert.IsNotNull(msgIn); }
public void EnhancedMemoryStream_Byte() { var es = new EnhancedMemoryStream(); es.WriteByte(77); es.WriteByte(99); es.Seek(0, SeekOrigin.Begin); Assert.AreEqual(77, es.ReadByte()); Assert.AreEqual(99, es.ReadByte()); }
public void EnhancedMemoryStream_Bool() { var es = new EnhancedMemoryStream(); es.WriteBool(true); es.WriteBool(false); es.Seek(0, SeekOrigin.Begin); Assert.IsTrue(es.ReadBool()); Assert.IsFalse(es.ReadBool()); }
public void Msg_Serialize_EnvelopeMsg() { EnvelopeTestMsg evMsgOut, evMsgIn; EnvelopeMsg envelopeMsg; EnhancedStream es = new EnhancedMemoryStream(); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); // EnvelopeTestMsg is tagged with [MsgIgnore] so it won't loaded // into the map by Msg.LoadTypes(). This means that Msg.Load() // should return a EnvelopeMsg instance. evMsgOut = new EnvelopeTestMsg(); evMsgOut.Value = "The hills are alive, with the sound of music. ahhhhhhhhh"; Msg.LoadType(typeof(EnvelopeTestMsg)); Msg.Save(es, evMsgOut); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); es.Seek(0, SeekOrigin.Begin); envelopeMsg = (EnvelopeMsg)Msg.Load(es); Assert.IsNotNull(envelopeMsg); Assert.AreEqual(EnvelopeTestMsg.GetTypeID(), envelopeMsg.TypeID); // Serialize the EnvelopeMsg instance and then call Msg.LoadType() to // force the mapping of EnvelopeTestMsg and then make sure that // Msg.Load() was able to deserialize if properly. es.SetLength(0); Msg.Save(es, envelopeMsg); Msg.LoadType(typeof(EnvelopeTestMsg)); es.Seek(0, SeekOrigin.Begin); evMsgIn = (EnvelopeTestMsg)Msg.Load(es); Assert.AreEqual(evMsgOut.Value, evMsgIn.Value); }
public void EnhancedMemoryStream_String32() { var es = new EnhancedMemoryStream(); es.WriteString32(null); es.WriteString32("Hello World!"); es.WriteString32(new String('a', 45000)); es.Seek(0, SeekOrigin.Begin); Assert.IsNull(es.ReadString32()); Assert.AreEqual("Hello World!", es.ReadString32()); Assert.AreEqual(new String('a', 45000), es.ReadString32()); }
public void Package_HashVerify() { Package package; EnhancedBlockStream bs = new EnhancedBlockStream(); EnhancedMemoryStream es = new EnhancedMemoryStream(); PackageEntry entry; byte[] buf; byte v; buf = new byte[37000]; for (int i = 0; i < buf.Length; i++) { buf[i] = (byte)i; } //------------------------- package = new Package(); package.Create(es); bs.WriteBytes32(buf); bs.Position = 0; entry = package.AddFile("/Foo/Bar/Test1.dat", bs, (int)bs.Length); Assert.IsTrue(bs.Eof); Assert.IsTrue(entry.IsFile); Assert.IsTrue(package["/Foo"].IsFolder); Assert.IsTrue(package["/Foo/Bar"].IsFolder); Assert.IsTrue(package["/Foo/Bar/Test1.dat"].IsFile); package.Close(true); es.Position = es.Length / 2; // Corrupt a byte in the middle of the stream // to verify that the MD5 hash comparision // catches it. v = (byte)es.ReadByte(); es.Seek(-1, SeekOrigin.Current); es.WriteByte((byte)~v); es.Position = 0; try { package = new Package(es); Assert.Fail(); } catch (PackageException) { } }
public void EnhancedMemoryStream_Int16() { var es = new EnhancedMemoryStream(); es.WriteInt16(0); es.WriteInt16(55); es.WriteInt16(0x1234); es.Seek(0, SeekOrigin.Begin); Assert.AreEqual(0, es.ReadInt16()); Assert.AreEqual(55, es.ReadInt16()); Assert.AreEqual(0x1234, es.ReadInt16()); }
public void Msg_Serialize_GetConfigAck() { GetConfigAck msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); msgOut = new GetConfigAck(new Exception("Test exception")); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (GetConfigAck)Msg.Load(es); Assert.AreEqual("Test exception", msgIn.Exception); Assert.IsNull(msgIn.ConfigText); msgOut = new GetConfigAck("config info"); es.SetLength(0); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (GetConfigAck)Msg.Load(es); Assert.IsNull(msgIn.Exception); Assert.AreEqual("config info", msgIn.ConfigText); }
public void EnhancedMemoryStream_Int32() { var es = new EnhancedMemoryStream(); es.WriteInt32(0); es.WriteInt32(65121); es.WriteInt32(0x12345678); es.Seek(0, SeekOrigin.Begin); Assert.AreEqual(0, es.ReadInt32()); Assert.AreEqual(65121, es.ReadInt32()); Assert.AreEqual(0x12345678, es.ReadInt32()); }
public void ReliableMessengerMsgs_DeliveryAck_Serialize() { DeliveryAck msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); msgOut = new DeliveryAck(); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (DeliveryAck)Msg.Load(es); Assert.IsNotNull(msgIn); }
public void Msg_Serialize_RouterStopMsg() { RouterStopMsg msgIn, msgOut; EnhancedStream es = new EnhancedMemoryStream(); Msg.ClearTypes(); Msg.LoadTypes(Assembly.GetExecutingAssembly()); msgOut = new RouterStopMsg(MsgEP.Parse("physical://root.com:80/hub/leaf")); Msg.Save(es, msgOut); es.Seek(0, SeekOrigin.Begin); msgIn = (RouterStopMsg)Msg.Load(es); Assert.AreEqual("physical://root.com:80/hub/leaf", msgIn.RouterEP.ToString()); }