diff options
author | Nick Mathewson <nickm@torproject.org> | 2008-03-25 16:16:05 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2008-03-25 16:16:05 +0000 |
commit | 41deb5cd7bb472bba94d2612a9ebcab910e9a0e0 (patch) | |
tree | ab0f13def8ba3d0e5301536b40b27ddb12c8c2ee /src/common/test.h | |
parent | 0e86cd06feb37236979e38249c57f30853c816d3 (diff) | |
download | tor-41deb5cd7bb472bba94d2612a9ebcab910e9a0e0.tar.gz tor-41deb5cd7bb472bba94d2612a9ebcab910e9a0e0.zip |
r19039@catbus: nickm | 2008-03-25 12:15:58 -0400
Add some unit tests, particularly for AES counter mode.
svn:r14180
Diffstat (limited to 'src/common/test.h')
-rw-r--r-- | src/common/test.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/common/test.h b/src/common/test.h index ead2bfadd3..c07d34351f 100644 --- a/src/common/test.h +++ b/src/common/test.h @@ -142,6 +142,29 @@ extern int have_failed; return; \ } STMT_END +#define test_memeq_hex(expr1, hex) \ + STMT_BEGIN \ + const void *_test_v1 = (expr1); \ + const char *_test_v2 = (hex); \ + size_t _len_v2 = strlen(_test_v2); \ + char *mem2 = tor_malloc(_len_v2/2); \ + tor_assert((_len_v2 & 1) == 0); \ + base16_decode(mem2, _len_v2/2, _test_v2, _len_v2); \ + if (!memcmp(mem2, _test_v1, _len_v2/2)) { \ + printf("."); fflush(stdout); } else { \ + char *mem1 = tor_malloc(_len_v2)+1; \ + base16_encode(mem1, _len_v2+1, _test_v1, _len_v2/2); \ + printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n" \ + " %s != %s\n", \ + _SHORT_FILE_, \ + __LINE__, \ + PRETTY_FUNCTION, \ + #expr1, _test_v2, mem1, _test_v2); \ + return; \ + } \ + tor_free(mem2); \ + STMT_END + #define test_memneq(expr1, expr2, len) \ STMT_BEGIN \ void *_test_v1=(expr1), *_test_v2=(expr2); \ |