test: use ASSERT_MEMEQ_BYTE()/ASSERT_MEMEQ_ZERO()

Replace ASSERT_TRUE(memeqbyte(...)) and ASSERT_TRUE(memeqzero(...)) with
the new dedicated macros, which show which bytes diverge on assertion
failure.
This commit is contained in:
Yu Watanabe committed 2026-11-05 03:21:31 +09:00
1 parent fe2987979b
commit df7f23cc2c
5 files changed
+15 -18

No files matched your search

+1 -2
View File
@@ -3,7 +3,6 @@
#include "dns-answer.h"
#include "dns-packet.h"
#include "dns-rr.h"
#include "memory-util.h"
#include "resolved-dns-stub.h"
#include "string-util.h"
#include "tests.h"
@@ -136,7 +135,7 @@ static void parse_reply(DnsPacket *reply, DnsPacket **ret_parsed, char **ret_lay
ASSERT_EQ(rr->key->type, DNS_TYPE_DNSKEY);
ASSERT_EQ(rr->dnskey.key_size, DNSKEY_KEY_SIZE);
fill = *(uint8_t*) rr->dnskey.key;
ASSERT_TRUE(memeqbyte(fill, rr->dnskey.key, rr->dnskey.key_size));
ASSERT_MEMEQ_BYTE(fill, rr->dnskey.key, rr->dnskey.key_size);
ASSERT_OK(strextendf(&layout, "%c", fill));
}
}
+8 -9
View File
@@ -20,7 +20,6 @@
#include "io-util.h"
#include "log.h"
#include "memfd-util.h"
#include "memory-util.h"
#include "mkdir.h"
#include "path-util.h"
#include "rm-rf.h"
@@ -610,9 +609,9 @@ TEST(copy_bytes_offset_reflink) {
ASSERT_EQ(toffset, 2 * bs);
ASSERT_OK_EQ_ERRNO(pread(dst, buf, 3 * bs, 0), (ssize_t) (3 * bs));
ASSERT_TRUE(memeqbyte('b', buf, bs));
ASSERT_TRUE(memeqbyte('c', buf + bs, bs));
ASSERT_TRUE(memeqbyte('b', buf + 2 * bs, bs));
ASSERT_MEMEQ_BYTE('b', buf, bs);
ASSERT_MEMEQ_BYTE('c', buf + bs, bs);
ASSERT_MEMEQ_BYTE('b', buf + 2 * bs, bs);
ASSERT_OK_EQ_ERRNO(lseek(src, 0, SEEK_CUR), (off_t) 5);
ASSERT_OK_EQ_ERRNO(lseek(dst, 0, SEEK_CUR), (off_t) 7);
}
@@ -652,11 +651,11 @@ TEST_RET(copy_bytes_offset_holes) {
ASSERT_EQ(toffset, 4 * bs + 1);
ASSERT_OK_EQ_ERRNO(pread(dst, buf, 5 * bs, 0), (ssize_t) (5 * bs));
ASSERT_TRUE(memeqbyte('X', buf, bs + 1));
ASSERT_TRUE(memeqzero(buf + bs + 1, bs));
ASSERT_TRUE(memeqbyte('D', buf + 2 * bs + 1, bs));
ASSERT_TRUE(memeqzero(buf + 3 * bs + 1, bs));
ASSERT_TRUE(memeqbyte('X', buf + 4 * bs + 1, bs - 1));
ASSERT_MEMEQ_BYTE('X', buf, bs + 1);
ASSERT_MEMEQ_ZERO(buf + bs + 1, bs);
ASSERT_MEMEQ_BYTE('D', buf + 2 * bs + 1, bs);
ASSERT_MEMEQ_ZERO(buf + 3 * bs + 1, bs);
ASSERT_MEMEQ_BYTE('X', buf + 4 * bs + 1, bs - 1);
ASSERT_OK_EQ_ERRNO(lseek(src, 0, SEEK_CUR), (off_t) 5);
ASSERT_OK_EQ_ERRNO(lseek(dst, 0, SEEK_CUR), (off_t) 7);
+3 -3
View File
@@ -36,18 +36,18 @@ TEST(cleanup_array) {
saved_n = n;
{
ASSERT_TRUE(memeqbyte('x', saved_iov, sizeof(struct iovec) * saved_n));
ASSERT_MEMEQ_BYTE('x', saved_iov, sizeof(struct iovec) * saved_n);
ASSERT_NOT_NULL(iov);
ASSERT_GT(n, 0U);
CLEANUP_ARRAY(iov, n, my_destructor);
ASSERT_TRUE(memeqbyte('x', saved_iov, sizeof(struct iovec) * saved_n));
ASSERT_MEMEQ_BYTE('x', saved_iov, sizeof(struct iovec) * saved_n);
ASSERT_NOT_NULL(iov);
ASSERT_GT(n, 0U);
}
ASSERT_TRUE(memeqbyte('y', saved_iov, sizeof(struct iovec) * saved_n));
ASSERT_MEMEQ_BYTE('y', saved_iov, sizeof(struct iovec) * saved_n);
ASSERT_NULL(iov);
ASSERT_EQ(n, 0U);
+2 -3
View File
@@ -15,7 +15,6 @@
#include "local-addresses.h"
#include "log.h"
#include "main-func.h"
#include "memory-util.h"
#include "nss-test-util.h"
#include "nss-util.h"
#include "parse-util.h"
@@ -72,9 +71,9 @@ static void assert_myhostname_gaih_addrtuples(const struct gaih_addrtuple *tuple
for (const struct gaih_addrtuple *it = tuples; it; it = it->next)
if (it->family == AF_INET)
ASSERT_TRUE(memeqzero(
ASSERT_MEMEQ_ZERO(
(const uint8_t*) it->addr + sizeof(struct in_addr),
sizeof(it->addr) - sizeof(struct in_addr)));
sizeof(it->addr) - sizeof(struct in_addr));
}
static void print_struct_hostent(struct hostent *host, const char *canon) {
+1 -1
View File
@@ -97,7 +97,7 @@ static void assert_zero(int fd, uint64_t offset, size_t size) {
_cleanup_free_ uint8_t *buf = ASSERT_NOT_NULL(new(uint8_t, size));
ASSERT_OK_EQ_ERRNO(pread(fd, buf, size, offset), (ssize_t) size);
ASSERT_TRUE(memeqzero(buf, size));
ASSERT_MEMEQ_ZERO(buf, size);
}
TEST(add_sections) {