Packet (unit tests)

- Added a unit test which tests the encoding
- So far it just checks that the version is encoded correctly
This commit is contained in:
Tristan B. Velloza Kildaire 2023-09-12 10:33:11 +02:00
parent 3a3febc61e
commit 8e8d1d2ba1

View File

@ -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);
}