brei: factor out header size for the unit tests

This commit is contained in:
Peter Hutterer 2023-02-28 14:26:27 +10:00
parent 960bb6db26
commit d686d4e281

View file

@ -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";