Merge r1054,r1060 from libarchive.googlecode.com:

* assertEqualMem() now takes void * arguments
 * Be a little smarter about what we hexdump when assertEqualMem() fails
This commit is contained in:
Tim Kientzle 2009-04-27 18:39:55 +00:00
parent eb60d22100
commit 525ed69972
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=191581
2 changed files with 19 additions and 6 deletions

View File

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

View File

@ -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 *, ...);