From f1524656e4a2ba7c19c089c4ac7d9a8413a17642 Mon Sep 17 00:00:00 2001 From: dongwenze Date: Mon, 20 Mar 2023 15:43:33 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=E5=AF=B9=E9=83=A8=E5=88=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E8=BF=9B=E8=A1=8C=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unit_test/crypto/crypto_test.cpp | 41 ++++++++++++++++++++++++ unit_test/s2j/s2j_test.cpp | 54 ++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 unit_test/crypto/crypto_test.cpp create mode 100644 unit_test/s2j/s2j_test.cpp 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); + } +}