Random fixes and additions. Progress with xlib
This commit is contained in:
32
tests/main.c
32
tests/main.c
@@ -63,6 +63,24 @@ void test_DynString_equal_c_str(void** state) {
|
||||
DynString_free(&s1);
|
||||
}
|
||||
|
||||
void test_DynString_equal_next_chars_c_str(void** state) {
|
||||
DynString dstr = DynString_alloc("Hello", strlen("Hello"));
|
||||
char* str = "ll";
|
||||
size_t str_len = strlen(str);
|
||||
assert_true(DynString_equal_next_chars_c_str(&dstr, str, str_len, 2));
|
||||
assert_false(DynString_equal_next_chars_c_str(&dstr, str, str_len, 1));
|
||||
DynString_free(&dstr);
|
||||
}
|
||||
|
||||
void test_DynString_reserve(void** state) {
|
||||
char* str = "aa";
|
||||
size_t str_len = strlen(str);
|
||||
DynString dstr = DynString_alloc(str, str_len);
|
||||
assert_true(dstr.len == str_len);
|
||||
assert_true(dstr.capacity == str_len + 1);
|
||||
assert_memory_equal(dstr.data, (void*) str, str_len + 1);
|
||||
}
|
||||
|
||||
void test_DynString_concat_c_str(void** state) {
|
||||
const char* dstr_c_str = "Hello";
|
||||
const char* c_str = " World";
|
||||
@@ -71,7 +89,7 @@ void test_DynString_concat_c_str(void** state) {
|
||||
DynString dstr = DynString_alloc(dstr_c_str, strlen("Hello"));
|
||||
DynString_concat_c_str(&dstr, c_str, strlen(c_str));
|
||||
|
||||
assert_memory_equal(dstr.data, "Hello World", strlen("Hello World"));
|
||||
assert_memory_equal(dstr.data, (void*) "Hello World\0", strlen("Hello World") + 1);
|
||||
assert_true(dstr.len == combined_length);
|
||||
assert_true(dstr.capacity == combined_length + 1);
|
||||
|
||||
@@ -89,14 +107,26 @@ void test_DynString_c_str(void** state) {
|
||||
assert_string_equal("Hello World", DynString_c_str(&dstr));
|
||||
}
|
||||
|
||||
void test_DynString_split(void** state) {
|
||||
DynString dstr = DynString_alloc("Hello World", strlen("Hello World"));
|
||||
size_t arr_len = 0;
|
||||
DynString* arr = DynString_split(&dstr, " ", &arr_len);
|
||||
assert_true(arr_len == 2);
|
||||
assert_string_equal(DynString_c_str(arr), "Hello");
|
||||
assert_string_equal(DynString_c_str(arr + 1), "World");
|
||||
}
|
||||
|
||||
int main() {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_DynString_alloc),
|
||||
cmocka_unit_test(test_DynString_free),
|
||||
cmocka_unit_test(test_DynString_equal),
|
||||
cmocka_unit_test(test_DynString_equal_c_str),
|
||||
cmocka_unit_test(test_DynString_equal_next_chars_c_str),
|
||||
cmocka_unit_test(test_DynString_reserve),
|
||||
cmocka_unit_test(test_DynString_concat_c_str),
|
||||
cmocka_unit_test(test_DynString_c_str),
|
||||
cmocka_unit_test(test_DynString_split),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
|
||||
Reference in New Issue
Block a user