aboutsummaryrefslogtreecommitdiff
path: root/tests/base64_test.cpp
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2022-09-11 01:39:29 -0400
committerGravatar Chris Xiong <chirs241097@gmail.com> 2022-09-11 01:39:29 -0400
commitc41768dbbd50a0055298d5ec6318ae7f1d2e4ab3 (patch)
tree4fe4ec18a65424998c33c6654456b2551996ae39 /tests/base64_test.cpp
parentfd2773c2407aa475ba8aa4c8a72c91b83fd99c42 (diff)
downloaddeduper-c41768dbbd50a0055298d5ec6318ae7f1d2e4ab3.tar.xz
New testdrive using sqlite db as data storage.
Add signature serialization & deserialization. Only link what we need from OpenCV.
Diffstat (limited to 'tests/base64_test.cpp')
-rw-r--r--tests/base64_test.cpp69
1 files changed, 69 insertions, 0 deletions
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 <cstdio>
+#include <cstring>
+#include <cstdlib>
+#include <cassert>
+#include <ctime>
+
+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;
+}