From 8d4b43e17863bc8ef21ccf795bbe91a9f975b978 Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Sat, 11 Mar 2017 20:44:08 -0800 Subject: [PATCH] Update tests to latest changes Signed-off-by: Ralf Ramsauer [Erik Ekman: reverted login test changes] --- tests/base32.c | 21 ++++++--------------- tests/base64.c | 22 ++++++---------------- tests/dns.c | 9 ++++----- tests/encoding.c | 4 +--- 4 files changed, 17 insertions(+), 39 deletions(-) diff --git a/tests/base32.c b/tests/base32.c index 4b460e2..54ef0e2 100644 --- a/tests/base32.c +++ b/tests/base32.c @@ -22,7 +22,6 @@ #include #include "encoding.h" -#include "base32.h" #include "test.h" #define TUPLES 5 @@ -43,13 +42,11 @@ START_TEST(test_base32_encode) { size_t len; char buf[4096]; - struct encoder *b32; int val; - b32 = get_base32_encoder(); len = sizeof(buf); - val = b32->encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a)); + val = base32_ops.encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a)); fail_unless(val == strlen(testpairs[_i].b)); fail_unless(strcmp(buf, testpairs[_i].b) == 0, @@ -61,13 +58,10 @@ START_TEST(test_base32_decode) { size_t len; char buf[4096]; - struct encoder *b32; int val; - b32 = get_base32_encoder(); - len = sizeof(buf); - val = b32->decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b)); + val = base32_ops.decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b)); fail_unless(val == strlen(testpairs[_i].a)); fail_unless(strcmp(buf, testpairs[_i].a) == 0, @@ -93,14 +87,11 @@ START_TEST(test_base32_blksize) size_t enclen; char *rawbuf; char *encbuf; - struct encoder *b32; int i; int val; - b32 = get_base32_encoder(); - - rawlen = b32->blocksize_raw(); - enclen = b32->blocksize_encoded(); + rawlen = base32_ops.blocksize_raw; + enclen = base32_ops.blocksize_encoded; rawbuf = malloc(rawlen + 16); encbuf = malloc(enclen + 16); @@ -110,7 +101,7 @@ START_TEST(test_base32_blksize) } rawbuf[i] = 0; - val = b32->encode(encbuf, &enclen, rawbuf, rawlen); + val = base32_ops.encode(encbuf, &enclen, rawbuf, rawlen); fail_unless(rawlen == 5, "raw length was %d not 5", rawlen); fail_unless(enclen == 5, "encoded %d bytes, not 5", enclen); @@ -119,7 +110,7 @@ START_TEST(test_base32_blksize) memset(rawbuf, 0, rawlen + 16); enclen = val; - val = b32->decode(rawbuf, &rawlen, encbuf, enclen); + val = base32_ops.decode(rawbuf, &rawlen, encbuf, enclen); fail_unless(rawlen == 5, "raw length was %d not 5", rawlen); fail_unless(val == 5, "val was not 5 but %d", val); diff --git a/tests/base64.c b/tests/base64.c index bcefc4c..a9f0d04 100644 --- a/tests/base64.c +++ b/tests/base64.c @@ -22,7 +22,6 @@ #include #include "encoding.h" -#include "base64.h" #include "test.h" #define TUPLES 5 @@ -69,13 +68,10 @@ START_TEST(test_base64_encode) { size_t len; char buf[4096]; - struct encoder *b64; int val; - b64 = get_base64_encoder(); - len = sizeof(buf); - val = b64->encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a)); + val = base64_ops.encode(buf, &len, testpairs[_i].a, strlen(testpairs[_i].a)); fail_unless(val == strlen(testpairs[_i].b)); fail_unless(strcmp(buf, testpairs[_i].b) == 0, @@ -87,13 +83,10 @@ START_TEST(test_base64_decode) { size_t len; char buf[4096]; - struct encoder *b64; int val; - b64 = get_base64_encoder(); - len = sizeof(buf); - val = b64->decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b)); + val = base64_ops.decode(buf, &len, testpairs[_i].b, strlen(testpairs[_i].b)); fail_unless(val == strlen(testpairs[_i].a)); fail_unless(strcmp(buf, testpairs[_i].a) == 0, @@ -107,14 +100,11 @@ START_TEST(test_base64_blksize) size_t enclen; char *rawbuf; char *encbuf; - struct encoder *b64; int i; int val; - b64 = get_base64_encoder(); - - rawlen = b64->blocksize_raw(); - enclen = b64->blocksize_encoded(); + rawlen = base64_ops.blocksize_raw; + enclen = base64_ops.blocksize_encoded; rawbuf = malloc(rawlen + 16); encbuf = malloc(enclen + 16); @@ -124,7 +114,7 @@ START_TEST(test_base64_blksize) } rawbuf[i] = 0; - val = b64->encode(encbuf, &enclen, rawbuf, rawlen); + val = base64_ops.encode(encbuf, &enclen, rawbuf, rawlen); fail_unless(rawlen == 3, "raw length was %d not 3", rawlen); fail_unless(enclen == 3, "encoded %d bytes, not 3", enclen); @@ -133,7 +123,7 @@ START_TEST(test_base64_blksize) memset(rawbuf, 0, rawlen + 16); enclen = val; - val = b64->decode(rawbuf, &rawlen, encbuf, enclen); + val = base64_ops.decode(rawbuf, &rawlen, encbuf, enclen); fail_unless(rawlen == 3, "raw length was %d not 3", rawlen); fail_unless(val == 3); diff --git a/tests/dns.c b/tests/dns.c index 1f484ab..e102ce1 100644 --- a/tests/dns.c +++ b/tests/dns.c @@ -33,7 +33,6 @@ #include "common.h" #include "dns.h" #include "encoding.h" -#include "base32.h" #include "test.h" static void dump_packet(char *, size_t); @@ -70,7 +69,7 @@ START_TEST(test_encode_query) char buf[512]; char resolv[512]; struct query q; - struct encoder *enc; + const struct encoder *enc; char *d; size_t len; size_t enclen; @@ -83,7 +82,7 @@ START_TEST(test_encode_query) q.type = T_NULL; q.id = 1337; d = resolv; - enc = get_base32_encoder(); + enc = &base32_ops; *d++ = 'A'; enc->encode(d, &enclen, innerData, strlen(innerData)); @@ -111,14 +110,14 @@ START_TEST(test_decode_query) char buf[512]; char *domain; struct query q; - struct encoder *enc; + const struct encoder *enc; size_t len; memset(&q, 0, sizeof(struct query)); memset(&buf, 0, sizeof(buf)); q.id = 0; len = sizeof(query_packet) - 1; - enc = get_base32_encoder(); + enc = &base32_ops; dns_decode(buf, sizeof(buf), &q, QR_QUERY, query_packet, len); domain = strstr(q.name, topdomain); diff --git a/tests/encoding.c b/tests/encoding.c index 0d5f358..8f7bce2 100644 --- a/tests/encoding.c +++ b/tests/encoding.c @@ -22,8 +22,6 @@ #include "encoding.h" #include "test.h" -#include "base32.h" -#include "base64.h" #define TUPLES 4 @@ -87,7 +85,7 @@ START_TEST(test_build_hostname) buflen = sizeof(buf); for (i = 1; i < sizeof(data); i++) { - int len = build_hostname(buf, buflen, data, i, topdomain, get_base32_encoder(), sizeof(buf)); + int len = build_hostname(buf, buflen, data, i, topdomain, &base32_ops, sizeof(buf)); fail_if(len > i); fail_if(strstr(buf, ".."), "Found double dots when encoding data len %d! buf: %s", i, buf);