vcpe/unit_test/uthash/utarray_test.cpp

51 lines
1.2 KiB
C++
Raw Permalink Normal View History

//
// 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;
memset(&p_combo, 0, sizeof(PCOMBO));
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;
memset(&p_combo, 0, sizeof(PCOMBO));
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);
}
}