From d686d4e281be46554e4a21717d15668710a7d850 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 28 Feb 2023 14:26:27 +1000 Subject: [PATCH] brei: factor out header size for the unit tests --- src/brei-shared.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/brei-shared.c b/src/brei-shared.c index 6522069..edf07bb 100644 --- a/src/brei-shared.c +++ b/src/brei-shared.c @@ -532,8 +532,10 @@ MUNIT_TEST(test_brei_send_message) int sock_read = sv[0]; int sock_write = sv[1]; + const int header_size = 8; + { - const int msglen = 16; /* 8 header + 2 * 4 bytes */ + const int msglen = header_size + 8; /* 2 * 4 bytes */ object_id_t id = 1; uint32_t opcode = 2; const char *signature = "uu"; @@ -549,7 +551,7 @@ MUNIT_TEST(test_brei_send_message) munit_assert_int(buf[3], ==, 0xdddd); } { - const int msglen = 16; /* 8 header + 2 * 4 bytes */ + const int msglen = header_size + 8; /* 2 * 4 bytes */ object_id_t id = 1; uint32_t opcode = 2; const char *signature = "fi"; @@ -575,7 +577,7 @@ MUNIT_TEST(test_brei_send_message) int slen = bytes_to_int32(strlen(string) + 1) * 4; munit_assert_int(slen, ==, sizeof(string)); - const int msglen = 24 + slen; /* 8 header + 3 * 4 bytes + 4 bytes slen + string length */ + const int msglen = header_size + 16 + slen; /* 3 * 4 bytes + 4 bytes slen + string length */ object_id_t id = 2; uint32_t opcode = 3; const char *signature = "ison"; @@ -601,7 +603,7 @@ MUNIT_TEST(test_brei_send_message) const char string1[12] = "hello wor"; /* tests padding too */ const char string2[8] = "barba"; /* tests padding too */ - const int msglen = 16 + sizeof(string1) + sizeof(string2); /* 8 header + 2 * 4 bytes slen + string lengths */ + const int msglen = header_size + 8 + sizeof(string1) + sizeof(string2); /* 8 header + 2 * 4 bytes slen + string lengths */ object_id_t id = 2; uint32_t opcode = 3; const char *signature = "ss"; @@ -629,7 +631,7 @@ MUNIT_TEST(test_brei_send_message) /* actual message data to be sent */ char data[] = "some data\n"; - const int msglen = 16; /* 8 header, 2 unsigned, fd is not in data */ + const int msglen = header_size + 8; /* 2 unsigned, fd is not in data */ object_id_t id = 2; uint32_t opcode = 3; const char *signature = "uhu";