2024-10-10 16:09:25 -04:00
|
|
|
#include "../src/include/dstr.h"
|
|
|
|
#include "unity/unity.h"
|
|
|
|
#include "registry.h"
|
|
|
|
|
|
|
|
void test_dstr_init() {
|
|
|
|
Dstr* dstr = dstr_init();
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL_INT(DSTR_INITSZ, dstr->bufsz);
|
|
|
|
TEST_ASSERT_EQUAL_STRING(malloc(DSTR_INITSZ), dstr->buf);
|
|
|
|
TEST_ASSERT_EQUAL_size_t(0, dstr->ln);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_dstr_append() {
|
|
|
|
char* str1 = malloc(2);
|
2024-10-13 23:46:03 -04:00
|
|
|
str1[0] = 'h';
|
|
|
|
str1[1] = '\0';
|
2024-10-10 16:09:25 -04:00
|
|
|
|
|
|
|
char* str2 = malloc(DSTR_INITSZ);
|
2024-10-13 23:46:03 -04:00
|
|
|
str2[0] = 'h';
|
|
|
|
str2[1] = '\0';
|
2024-10-10 16:09:25 -04:00
|
|
|
|
|
|
|
|
|
|
|
Dstr* dstr = dstr_init();
|
2024-10-13 23:46:03 -04:00
|
|
|
dstr_append(dstr, str1, 1);
|
2024-10-10 16:09:25 -04:00
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL_STRING(str2, dstr->buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_dstr() {
|
|
|
|
UNITY_BEGIN();
|
|
|
|
RUN_TEST(test_dstr_init);
|
|
|
|
RUN_TEST(test_dstr_append);
|
|
|
|
UNITY_END();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((constructor)) void register_dstr() {
|
|
|
|
register_test(test_dstr);
|
|
|
|
}
|