diff --git a/unit_test/crypto/crypto_test.cpp b/unit_test/crypto/crypto_test.cpp new file mode 100644 index 0000000..6455b18 --- /dev/null +++ b/unit_test/crypto/crypto_test.cpp @@ -0,0 +1,41 @@ +// +// Created by dongwenzhe on 2023/3/14. +// +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "doctest.h" +#include "crypto.h" + +TEST_SUITE("Crypto functions") { + TEST_CASE("BASE64") { + auto *pSrc = (unsigned char *)"HELLOWORLD"; + const char *encode; + + encode = base64_encode(pSrc, 16); + INFO("BASE64_ENCODING:", encode); + + unsigned char *decode; + unsigned int outputSize = 0; + decode = base64_decode(encode, &outputSize); + INFO("BASE64_DECODING:", decode); + + for(int i = 0; ichild->valueint, 3); + for(i = 0; i < strlen(origin_Server.name); i++) { + CHECK_EQ(origin_Server.name[i], testServer->child->next->valuestring[i]); + } + for(i = 0; i < strlen(origin_Server.msg.info); i++) { + CHECK_EQ(origin_Server.msg.info[i], testServer->child->next->next->child->valuestring[i]); + } + } + + TEST_CASE("J2S") { + char originServer[] = R"({"id":3, "name":"dhcpServer", "message":{"info":"opendhcpd"}})"; + cJSON *testServer = cJSON_Parse(originServer); + + s2j_create_struct_obj(pServer, Service); + s2j_struct_get_basic_element(pServer, testServer, int, id); + s2j_struct_get_basic_element(pServer, testServer, string, name); + s2j_struct_get_struct_element(pMsg, pServer, testInfo, testServer, Message, msg); + s2j_struct_get_basic_element(pMsg, testInfo, string, info); + + CHECK_EQ(pServer->id, 3); + } +}