From c41768dbbd50a0055298d5ec6318ae7f1d2e4ab3 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sun, 11 Sep 2022 01:39:29 -0400 Subject: New testdrive using sqlite db as data storage. Add signature serialization & deserialization. Only link what we need from OpenCV. --- tests/base64_test.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/base64_test.cpp (limited to 'tests/base64_test.cpp') diff --git a/tests/base64_test.cpp b/tests/base64_test.cpp new file mode 100644 index 0000000..1ee6b14 --- /dev/null +++ b/tests/base64_test.cpp @@ -0,0 +1,69 @@ +#include "base64.hpp" + +#include +#include +#include +#include +#include + +char buf[32768]; +char bug[32768]; +char buh[32768]; +char bui[32768]; + +void testb64class() +{ + srand(time(NULL)); + size_t l1 = rand() % 20 + 1; + size_t l2 = rand() % 20 + 1; + for (size_t i = 0; i < l1; ++i) + buf[i] = rand() % 128; + for (size_t i = 0; i < l2; ++i) + bug[i] = rand() % 128; + Base64Encoder enc; + enc.encode_data(buf, l1); + enc.encode_data(bug, l2); + std::string s = enc.finalize(); + std::string ss = enc.finalize(); + Base64Decoder dec(std::move(s)); + assert(dec.decoded_length() == l1 + l2); + + Base64Decoder decc(std::move(s)); + size_t xx = decc.decode_data(buh, 32768); + for (size_t i = 0; i < xx; ++i) + printf("%d ", buh[i]); + printf("\n"); + size_t l3 = dec.decode_data(buh, l1); + size_t l4 = dec.decode_data(bui, l2); + assert(l1 == l3); + assert(l2 == l4); + for (size_t i = 0; i < l1 ; ++i) + printf("%d ", buf[i]); + printf("\n"); + for (size_t i = 0; i < l1 ; ++i) + printf("%d ", buh[i]); + printf("\n");fflush(stdout); + assert(!memcmp(buf, buh, l1)); + for (size_t i = 0; i < l2 ; ++i) + printf("%d ", bug[i]); + printf("\n"); + for (size_t i = 0; i < l2 ; ++i) + printf("%d ", bui[i]); + printf("\n");fflush(stdout); + assert(!memcmp(bug, bui, l2)); +} + +int main() +{ + /*freopen(NULL, "rb", stdin); + size_t s = fread(buf, 1, 32768, stdin); + std::string en = base64_encode((void*)buf, s); + puts(en.c_str()); + size_t rl = 0; + char *de = (char*)base64_decode(en, &rl); + if (rl != s) return 1; + if (memcmp(buf, de, s)) return 1; + free(de);*/ + testb64class(); + return 0; +} -- cgit v1.2.3