]> sigrok.org Git - libsigrok.git/commitdiff
tests: extend endianess conversion tests to also cover the 48bit writer
authorGerhard Sittig <redacted>
Sat, 27 Feb 2021 13:35:54 +0000 (14:35 +0100)
committerGerhard Sittig <redacted>
Tue, 16 Mar 2021 20:26:35 +0000 (21:26 +0100)
Cover the recently added writer for 48bit little endian data. Prepare a
large bytes pattern buffer that can also serve for future 64bit tests.

tests/conv.c

index ecbe56190f32359556ce4a751a5b1862058103ab..f126c470e5b56beae6401dcd7ff13fc483920710 100644 (file)
@@ -34,6 +34,16 @@ static const uint8_t buff8125fb[] = {
 static const uint8_t buff8125fl[] = {
        0x00, 0x00, 0x02, 0x41, 0x00, 0x00, 0x00, 0x00,
 };
+static const uint8_t buff1234large[] = {
+       0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+       0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
+       0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
+       0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
+       0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
+       0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
+       0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
+       0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40,
+};
 
 START_TEST(test_endian_macro)
 {
@@ -201,6 +211,7 @@ START_TEST(test_endian_write_inc)
        size_t l;
 
        memset(buff, 0, sizeof(buff));
+
        p = &buff[0];
        write_u8_inc(&p, 0x11);
        write_u16be_inc(&p, 0x2233);
@@ -208,6 +219,15 @@ START_TEST(test_endian_write_inc)
        l = p - &buff[0];
        fail_unless(l == sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint32_t));
        fail_unless(memcmp(&buff[0], &buff1234[0], l) == 0);
+
+       p = &buff[0];
+       write_u48le_inc(&p, 0x060504030201);
+       write_u48le_inc(&p, 0x0c0b0a090807);
+       write_u48le_inc(&p, 0x1211100f0e0d);
+       write_u48le_inc(&p, 0x181716151413);
+       l = p - &buff[0];
+       fail_unless(l == 4 * 48 / 8 * sizeof(uint8_t));
+       fail_unless(memcmp(&buff[0], &buff1234large[0], l) == 0);
 }
 END_TEST