public void ConstructByPropertiesAndModify1() { byte[] packetData = TestPacket1; // will allocate full buffer since number of addresses is unknown Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest(); p.Source = Ssm2Device.DiagnosticToolF0; p.Destination = Ssm2Device.Engine10; p.Addresses = new int[] { 0x123456 }; // should be ok after setting Data Assert.AreEqual(packetData.Length, p.Size, "Size before Construct"); // necessary to create checksum, making packet complete p.Finish(); byte[] actual = p.ToBytesCopy(); for (int i = 0; i < packetData.Length; i++) { Assert.AreEqual(packetData[i], actual[i], "actual[" + i.ToString() + "]"); } Assert.AreEqual(packetData.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"); 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]"); // change properties that don't affect packet length p.Source = Ssm2Device.Engine10; p.Destination = Ssm2Device.DiagnosticToolF0; p.Addresses = new[] { 1, 2, 3 }; p.Finish(); Assert.AreEqual(true, p.Check(), "Check2"); Assert.AreEqual(Ssm2Device.DiagnosticToolF0, p.Destination, "Destination2"); Assert.AreEqual(Ssm2Device.Engine10, p.Source, "Source2"); Assert.AreEqual(Ssm2Command.ReadAddressesRequestA8, p.Command, "Command2"); Assert.AreEqual(3, p.AddressesCount, "AddressesCount2"); addresses = p.Addresses; Assert.AreEqual(3, addresses.Count, "addrList.Count2"); Assert.AreEqual(1, addresses[0], "adr2[0]"); Assert.AreEqual(2, addresses[1], "adr2[1]"); Assert.AreEqual(3, addresses[2], "adr2[2]"); }
public void ConstructByPropertiesAndModify1() { byte[] packetData = TestPacket1; // will allocate full buffer since number of addresses is unknown Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest (); p.Source = Ssm2Device.DiagnosticToolF0; p.Destination = Ssm2Device.Engine10; p.Addresses = new int[] { 0x123456 }; // should be ok after setting Data Assert.AreEqual (packetData.Length, p.Size, "Size before Construct"); // necessary to create checksum, making packet complete p.Finish (); byte[] actual = p.ToBytesCopy (); for (int i = 0; i < packetData.Length; i++) { Assert.AreEqual (packetData[i], actual[i], "actual[" + i.ToString () + "]"); } Assert.AreEqual (packetData.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"); 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]"); // change properties that don't affect packet length p.Source = Ssm2Device.Engine10; p.Destination = Ssm2Device.DiagnosticToolF0; p.Addresses = new[] { 1, 2, 3 }; p.Finish (); Assert.AreEqual (true, p.Check (), "Check2"); Assert.AreEqual (Ssm2Device.DiagnosticToolF0, p.Destination, "Destination2"); Assert.AreEqual (Ssm2Device.Engine10, p.Source, "Source2"); Assert.AreEqual (Ssm2Command.ReadAddressesRequestA8, p.Command, "Command2"); Assert.AreEqual (3, p.AddressesCount, "AddressesCount2"); addresses = p.Addresses; Assert.AreEqual (3, addresses.Count, "addrList.Count2"); Assert.AreEqual (1, addresses[0], "adr2[0]"); Assert.AreEqual (2, addresses[1], "adr2[1]"); Assert.AreEqual (3, addresses[2], "adr2[2]"); }
public void ConstructorComplete1() { // Create a ReadAddressesRequest, requesting one address. // This constructor takes all needed information, // allocates optimal buffer size and constructs a complete packet. Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest( Ssm2Device.Engine10, Ssm2Device.DiagnosticToolF0, new[] { 0x123456 } ); // Predetermined packet bytes to compare with. byte[] expected = TestPacket1; // 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> addrList = p.Addresses; Assert.AreEqual(1, addrList.Count, "addrList.Count"); Assert.AreEqual(1, p.AddressesCount, "AddressesCount"); Assert.AreEqual(0x123456, addrList[0], "adr[0]"); // take raw packet bytes byte[] buffer = p.ToBytesCopy(); // compare raw packet bytes for (int i = 0; i < expected.Length; i++) { Assert.AreEqual(expected[i], buffer[i], "buffer[" + i.ToString() + "]"); } }
public void ConstructorComplete1() { // Create a ReadAddressesRequest, requesting one address. // This constructor takes all needed information, // allocates optimal buffer size and constructs a complete packet. Ssm2ReadAddressesRequest p = new Ssm2ReadAddressesRequest ( Ssm2Device.Engine10, Ssm2Device.DiagnosticToolF0, new[] { 0x123456 } ); // Predetermined packet bytes to compare with. byte[] expected = TestPacket1; // 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> addrList = p.Addresses; Assert.AreEqual (1, addrList.Count, "addrList.Count"); Assert.AreEqual (1, p.AddressesCount, "AddressesCount"); Assert.AreEqual (0x123456, addrList[0], "adr[0]"); // take raw packet bytes byte[] buffer = p.ToBytesCopy (); // compare raw packet bytes for (int i = 0; i < expected.Length; i++) { Assert.AreEqual (expected[i], buffer[i], "buffer[" + i.ToString () + "]"); } }