From 8e8d1d2ba1874349251563cf4704e9d90e99ce68 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Tue, 12 Sep 2023 10:33:11 +0200 Subject: [PATCH] Packet (unit tests) - Added a unit test which tests the encoding - So far it just checks that the version is encoded correctly --- source/doap/packet.d | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/source/doap/packet.d b/source/doap/packet.d index c740d9f..71a2d17 100644 --- a/source/doap/packet.d +++ b/source/doap/packet.d @@ -34,7 +34,37 @@ public class CoapPacket // Set the request/response code encoded ~= code; + // Set the message ID + + return encoded; } + // public ubyte getVersion() + // { + + // } + +} + +/** + * Encoding tests + * + * These set high level parameters and then + * we call `getBytes()` and analyse the components + * of the encoded wire format by hand to ensure + * they are set in place correctly + */ +unittest +{ + CoapPacket packet = new CoapPacket(); + ubyte[] encoded = packet.getBytes(); + + ubyte firstByte = encoded[0]; + + // Ensure the version is set to 1 + ubyte versionField = cast(ubyte)(firstByte & 192) >> 6; + assert(versionField == 1); + + } \ No newline at end of file