diff options
author | kientzle <kientzle@FreeBSD.org> | 2009-04-27 18:39:55 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2009-04-27 18:39:55 +0000 |
commit | f5c80120f0ce6ffb0b908a9590f1a170522f2830 (patch) | |
tree | b8898810e9ed5c3c6a47cecf57af8154777f45a0 /lib/libarchive/test/main.c | |
parent | 875e2c2c82ace9db64bd80128263b32d4bb73aba (diff) | |
download | FreeBSD-src-f5c80120f0ce6ffb0b908a9590f1a170522f2830.zip FreeBSD-src-f5c80120f0ce6ffb0b908a9590f1a170522f2830.tar.gz |
Merge r1054,r1060 from libarchive.googlecode.com:
* assertEqualMem() now takes void * arguments
* Be a little smarter about what we hexdump when assertEqualMem() fails
Diffstat (limited to 'lib/libarchive/test/main.c')
-rw-r--r-- | lib/libarchive/test/main.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/libarchive/test/main.c b/lib/libarchive/test/main.c index 4022370..0d16c81 100644 --- a/lib/libarchive/test/main.c +++ b/lib/libarchive/test/main.c @@ -463,13 +463,16 @@ hexdump(const char *p, const char *ref, size_t l, size_t offset) } /* assertEqualMem() displays the values of the two memory blocks. */ -/* TODO: For long blocks, hexdump the first bytes that actually differ. */ int test_assert_equal_mem(const char *file, int line, - const char *v1, const char *e1, - const char *v2, const char *e2, + const void *_v1, const char *e1, + const void *_v2, const char *e2, size_t l, const char *ld, void *extra) { + const char *v1 = (const char *)_v1; + const char *v2 = (const char *)_v2; + size_t offset; + count_assertion(file, line); if (v1 == NULL || v2 == NULL) { if (v1 == v2) { @@ -486,10 +489,20 @@ test_assert_equal_mem(const char *file, int line, fprintf(stderr, "%s:%d: Assertion failed: memory not equal\n", file, line); fprintf(stderr, " size %s = %d\n", ld, (int)l); + /* Dump 48 bytes (3 lines) so that the first difference is + * in the second line. */ + offset = 0; + while (l > 64 && memcmp(v1, v2, 32) == 0) { + /* The first two lines agree, so step forward one line. */ + v1 += 16; + v2 += 16; + l -= 16; + offset += 16; + } fprintf(stderr, " Dump of %s\n", e1); - hexdump(v1, v2, l < 32 ? l : 32, 0); + hexdump(v1, v2, l < 64 ? l : 64, offset); fprintf(stderr, " Dump of %s\n", e2); - hexdump(v2, v1, l < 32 ? l : 32, 0); + hexdump(v2, v1, l < 64 ? l : 64, offset); fprintf(stderr, "\n"); report_failure(extra); return (0); |