public void EmptyPacketSpecifyingBuffer() { byte[] buffer = new byte[Ssm2Packet.PacketSizeMax]; // Constructor for initializing packet object by // providing own (empty) buffer // For parsing existing content use instance method .FromBytes (buffer) or // static method Ssm2Packet.NewFromBytes (buffer) instead! Ssm2Packet p = new Ssm2Packet(buffer); // packet buffer mostly contains zeroes // undefined, don't check: // Size, CheckSum, etc. //Assert.AreEqual (0, p.Size, "Size"); Assert.AreEqual((Ssm2Command)0, p.Command, "Command"); // Assert.AreEqual (0, p.ChecksumCalculated, "ChecksumCalculated"); Assert.AreEqual(false, p.Check(), "Check"); // not useful, just demonstrating that packet is invalid // byte[] buf = p.ToBytesCopy (); //Assert.AreEqual (0, buf.Length, "buf.Length"); }
public void Parse1() { byte[] expected = TestPacket1; // Static method NewFromBytes () analyzes packet type, // and returns a specific packet object. // Based on given data in this case we know upfront, // it'll be an read-addresses-request. Ssm2ReadAddressesRequest p; p = (Ssm2ReadAddressesRequest)Ssm2Packet.NewFromBytes(expected); // check standard properties Assert.AreEqual(expected.Length, p.Size, "Size"); Assert.AreEqual(true, p.Check(), "Check()"); Assert.AreEqual(Ssm2Device.Engine10, p.Destination, "Destination"); Assert.AreEqual(Ssm2Device.DiagnosticToolF0, p.Source, "Source"); Assert.AreEqual(Ssm2Command.ReadAddressesRequestA8, p.Command, "Command"); // check packet type specifics IList <int> addresses = p.Addresses; Assert.AreEqual(1, addresses.Count, "addrList.Count"); Assert.AreEqual(1, p.AddressesCount, "AddressesCount"); Assert.AreEqual(0x123456, addresses[0], "adr[0]"); }
public bool Equals(Ssm2Packet p) { if (p == null) { return(false); } return(this.GetHashCode() == p.GetHashCode()); }
public void EqualsDefaultPacket() { Ssm2Packet p1, p2; p1 = new Ssm2Packet(); p2 = new Ssm2Packet(); Assert.AreEqual(true, p1.Equals(p2), "Equals1"); Assert.AreEqual(true, p1.Equals((object)p2), "Equals2"); }
public void NewFromBytes() { // best for parsing as it does not allocate anything var p = (Ssm2ReadBlockRequest)Ssm2Packet.NewFromBytes(TestPacket1); // Same static method can also be accessed like this: // Ssm2InitRequest.NewFromBytes (...) AssertData1(p); }
public void NewFromBytes() { byte[] packetData = EcuInit1; // best for parsing as it does not allocate anything Ssm2InitRequest p = (Ssm2InitRequest)Ssm2Packet.NewFromBytes(packetData); // Same static method can also be accessed like this: // Ssm2InitRequest.NewFromBytes (...) AssertProperties1(p); }
// overriding Equals, GetHashCode etc. not necessary // but provide much better performance if used public override bool Equals(object obj) { if (obj == null) { return(false); } Ssm2Packet p = obj as Ssm2Packet; if (p == null) { return(false); } // Return true if the data matches: return(this.GetHashCode() == p.GetHashCode()); }
static void AssertProperties1(Ssm2Packet p) { byte[] expectedPacketData = EcuInit1; Assert.IsInstanceOfType(typeof(Ssm2InitRequest), p, "type"); Assert.IsInstanceOfType(typeof(Ssm2Packet), p, "base type"); Assert.AreEqual(expectedPacketData.Length, p.Size, "Size"); Assert.AreEqual(true, p.Check(), "Check()"); Assert.AreEqual(Ssm2Device.Engine10, p.Destination, "Destination"); Assert.AreEqual(Ssm2Device.DiagnosticToolF0, p.Source, "Source"); Assert.AreEqual(Ssm2Command.InitRequestBF, p.Command, "Command"); byte[] bytes = p.ToBytesCopy(); for (int i = 0; i < expectedPacketData.Length; i++) { Assert.AreEqual(expectedPacketData[i], bytes[i], "bytes[]"); } }
public void DefaultPacket() { Ssm2Packet p = new Ssm2Packet(); Assert.AreEqual(false, p.Check(), "Check"); // Following tests are very implementation specific // and rather for debugging purposes! // Real code should not depend on most packet properties // except Check(), Capacity, Size. // packet is almost empty since no properties haven't been set yet Assert.AreEqual(Ssm2Packet.PacketSizeMin, p.Size, "Size"); // only 1st byte is set to 128, all other bytes are 0, // therefore checksum is 128, too. Assert.AreEqual(128, p.ChecksumCalculated, "ChecksumCalculated"); // not useful, just demonstrating that packet is invalid byte[] buf = p.ToBytesCopy(); // generic packet type has minimum size Assert.AreEqual(Ssm2Packet.PacketSizeMin, buf.Length, "buf.Length"); }
public bool Equals(Ssm2Packet p) { if (p == null) return false; return (this.GetHashCode () == p.GetHashCode ()); }
static void AssertProperties1(Ssm2Packet p) { byte[] expectedPacketData = EcuInit1; Assert.IsInstanceOfType (typeof(Ssm2InitRequest), p, "type"); Assert.IsInstanceOfType (typeof(Ssm2Packet), p, "base type"); Assert.AreEqual (expectedPacketData.Length, p.Size, "Size"); Assert.AreEqual (true, p.Check (), "Check()"); Assert.AreEqual (Ssm2Device.Engine10, p.Destination, "Destination"); Assert.AreEqual (Ssm2Device.DiagnosticToolF0, p.Source, "Source"); Assert.AreEqual (Ssm2Command.InitRequestBF, p.Command, "Command"); byte[] bytes = p.ToBytesCopy (); for (int i = 0; i < expectedPacketData.Length; i++) { Assert.AreEqual (expectedPacketData[i], bytes[i], "bytes[]"); } }