OCT 1.对部分功能进行单元测试

This commit is contained in:
dongwenze 2023-03-28 14:21:35 +08:00
parent f1524656e4
commit b256424f71
3 changed files with 115 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}