diff --git a/unit_test/hardware/hardware_test.cpp b/unit_test/hardware/hardware_test.cpp new file mode 100644 index 0000000..612c2fc --- /dev/null +++ b/unit_test/hardware/hardware_test.cpp @@ -0,0 +1,20 @@ +// +// Created by dongwenzhe on 2023/3/16. +// +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "hardware.h" +#include "doctest.h" + +TEST_SUITE("Hardware functions") { + TEST_CASE("CPU") { + PCPU_INFO cpuInfo; + memset(cpuInfo, 0, sizeof(CPU_INFO)); + + cpu_watch_init(); + + get_cpu_info(cpuInfo); + CHECK_NE(cpuInfo->nCores, 0); + CHECK_NE(cpuInfo->cpuUsed, 0); + CHECK_NE(cpuInfo->cpuCoreDesc.cpuName, nullptr); + } +} diff --git a/unit_test/uthash/utarray_test.cpp b/unit_test/uthash/utarray_test.cpp new file mode 100644 index 0000000..89e358a --- /dev/null +++ b/unit_test/uthash/utarray_test.cpp @@ -0,0 +1,49 @@ +// +// Created by dongwenzhe on 2023/3/21. +// +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "uthash/utarray.h" +#include "doctest.h" + +typedef struct { + int a; + char *b; +} COMBO,*PCOMBO; + +UT_icd ut_combo_icd = {sizeof(COMBO), nullptr, nullptr, nullptr}; + +TEST_SUITE("UTArray") { + UT_array *nums; + COMBO t_combo; + + TEST_CASE("PUSH") { + PCOMBO p_combo; + + utarray_new(nums, &ut_combo_icd); + + t_combo.a = 1; + t_combo.b = "hello "; + utarray_push_back(nums, &t_combo); + t_combo.a = 2; + t_combo.b = "world"; + utarray_push_back(nums, &t_combo); + + while((PCOMBO)utarray_next(nums, p_combo) != nullptr) { + p_combo = (PCOMBO)utarray_next(nums, p_combo); + MESSAGE("COMBO:", p_combo->a); + MESSAGE(doctest::String(p_combo->b)); + } + } + + TEST_CASE("POP") { + PCOMBO p_combo; + MESSAGE("original len: ", utarray_len(nums)); + while(utarray_len(nums) != 0) { + p_combo = (PCOMBO)utarray_next(nums, p_combo); + utarray_pop_back(nums); + MESSAGE("len: ", utarray_len(nums)); + } + + utarray_free(nums); + } +} \ No newline at end of file diff --git a/unit_test/uthash/utstring_test.cpp b/unit_test/uthash/utstring_test.cpp new file mode 100644 index 0000000..3a789ee --- /dev/null +++ b/unit_test/uthash/utstring_test.cpp @@ -0,0 +1,46 @@ +// +// Created by dongwenzhe on 2023/3/21. +// + +//#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "uthash/utstring.h" +#include "doctest.h" + +TEST_SUITE("UTString") { + + TEST_CASE("Append") { + UT_string *s; + UT_string *t; + + utstring_new(s); + utstring_new(t); + utstring_printf(s, "hello "); + utstring_printf(t, "world"); + + utstring_concat(s, t); + char *body = utstring_body(s); + + MESSAGE(doctest::String(body)); + CHECK(doctest::String(body) == "hello world"); + + utstring_free(s); + utstring_free(t); + } + + TEST_CASE("Binary") { + UT_string *s; + utstring_new(s); + utstring_printf(s, "hello world"); + MESSAGE(utstring_len(s)); + + char binary[] = "\xff\xff"; + utstring_bincpy(s, binary, sizeof(binary)); + MESSAGE(utstring_len(s)); + char *body = utstring_body(s); + MESSAGE(doctest::String(body)); + + utstring_clear(s); + + utstring_free(s); + } +} \ No newline at end of file