public void Deserialize_bytes_CorrectlyDeserializes() { FrameSectionPackage expectedPackage = new FrameSectionPackage() { FrameSequenceIndex = 100, Index = 10, pixelInstructions = new List <PixelInstruction> { new PixelInstruction(10, 20, 30), new PixelInstruction(40, 50, 60) } }; int header_bytes_needed = sizeof(int) + sizeof(int) + sizeof(int); int pixelInstructions_bytes_needed = PixelInstructionProtocol.BYTES_NEEDED * 2; byte[] expectedBytes = new byte[header_bytes_needed + pixelInstructions_bytes_needed]; BitConverter.GetBytes(expectedPackage.FrameSequenceIndex).CopyTo(expectedBytes, 0); BitConverter.GetBytes(expectedPackage.Index).CopyTo(expectedBytes, 4); BitConverter.GetBytes(expectedPackage.pixelInstructions.Count).CopyTo(expectedBytes, 8); PixelInstructionProtocol.Serialize(expectedPackage.pixelInstructions[0], expectedBytes, 12); PixelInstructionProtocol.Serialize(expectedPackage.pixelInstructions[1], expectedBytes, 12 + PixelInstructionProtocol.BYTES_NEEDED); FrameSectionPackage package = FrameSectionProtocol.Deserialize(expectedBytes, 0); Assert.AreEqual(expectedPackage.FrameSequenceIndex, package.FrameSequenceIndex); Assert.AreEqual(expectedPackage.Index, package.Index); Assert.AreEqual(expectedPackage.NumberOfPixelInstructions, package.NumberOfPixelInstructions); Assert.AreEqual(expectedPackage.pixelInstructions[0], package.pixelInstructions[0]); Assert.AreEqual(expectedPackage.pixelInstructions[1], package.pixelInstructions[1]); }
public void Serialize_FrameSectionPackage_CorrectlySerialized() { FrameSectionPackage package = new FrameSectionPackage() { FrameSequenceIndex = 100, Index = 10, pixelInstructions = new List <PixelInstruction> { new PixelInstruction(10, 20, 30), new PixelInstruction(40, 50, 60) } }; int header_bytes_needed = sizeof(int) + sizeof(int) + sizeof(int); int pixelInstructions_bytes_needed = PixelInstructionProtocol.BYTES_NEEDED * 2; byte[] expectedBytes = new byte[header_bytes_needed + pixelInstructions_bytes_needed]; BitConverter.GetBytes(package.FrameSequenceIndex).CopyTo(expectedBytes, 0); BitConverter.GetBytes(package.Index).CopyTo(expectedBytes, 4); BitConverter.GetBytes(package.pixelInstructions.Count).CopyTo(expectedBytes, 8); PixelInstructionProtocol.Serialize(package.pixelInstructions[0], expectedBytes, 12); PixelInstructionProtocol.Serialize(package.pixelInstructions[1], expectedBytes, 12 + PixelInstructionProtocol.BYTES_NEEDED); byte[] returnBytes = new byte[FrameSectionProtocol.HEADER_BYTES_NEEDED + pixelInstructions_bytes_needed]; FrameSectionProtocol.Serialize(package, returnBytes, 0); Assert.AreEqual(expectedBytes, returnBytes); }
public void Serialize_PixelInStructionWithoutDelta_CorrectlyConvertedToByteArray() { PixelInstruction pi = new PixelInstruction(1, 2, 3); byte[] expectedBytes = new byte[1 + 1 + 1]; // Red, green , blue expectedBytes[0] = pi.R; expectedBytes[1] = pi.G; expectedBytes[2] = pi.B; byte[] buffer = new byte[PixelInstructionProtocol.BYTES_NEEDED]; PixelInstructionProtocol.Serialize(pi, buffer, 0); Assert.AreEqual(expectedBytes, buffer); }