summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorkientzle <kientzle@FreeBSD.org>2009-04-27 18:39:55 +0000
committerkientzle <kientzle@FreeBSD.org>2009-04-27 18:39:55 +0000
commitf5c80120f0ce6ffb0b908a9590f1a170522f2830 (patch)
treeb8898810e9ed5c3c6a47cecf57af8154777f45a0 /lib
parent875e2c2c82ace9db64bd80128263b32d4bb73aba (diff)
downloadFreeBSD-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')
-rw-r--r--lib/libarchive/test/main.c23
-rw-r--r--lib/libarchive/test/test.h2
2 files changed, 19 insertions, 6 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);
diff --git a/lib/libarchive/test/test.h b/lib/libarchive/test/test.h
index 539c826..ac3ad4f 100644
--- a/lib/libarchive/test/test.h
+++ b/lib/libarchive/test/test.h
@@ -147,7 +147,7 @@ int test_assert_equal_file(const char *, const char *, ...);
int test_assert_equal_int(const char *, int, int, const char *, int, const char *, void *);
int test_assert_equal_string(const char *, int, const char *v1, const char *, const char *v2, const char *, void *);
int test_assert_equal_wstring(const char *, int, const wchar_t *v1, const char *, const wchar_t *v2, const char *, void *);
-int test_assert_equal_mem(const char *, int, const char *, const char *, const char *, const char *, size_t, const char *, void *);
+int test_assert_equal_mem(const char *, int, const void *, const char *, const void *, const char *, size_t, const char *, void *);
int test_assert_file_contents(const void *, int, const char *, ...);
int test_assert_file_exists(const char *, ...);
int test_assert_file_not_exists(const char *, ...);
OpenPOWER on IntegriCloud