diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2019-09-02 23:38:48 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2019-09-02 23:51:15 +0200 |
commit | 4763814c683c50f8a3697b74e764f19c3dacccd5 (patch) | |
tree | 386ff43f024705a32310b882f2161b5f86d8820a /tests/common/check_sort.c | |
parent | c12bdb94ecdc44f200a8030dfde4a5ec46053ea6 (diff) | |
download | blogc-4763814c683c50f8a3697b74e764f19c3dacccd5.tar.gz blogc-4763814c683c50f8a3697b74e764f19c3dacccd5.tar.bz2 blogc-4763814c683c50f8a3697b74e764f19c3dacccd5.zip |
migrate codebase to use squareball. again :)feature/squareball
Diffstat (limited to 'tests/common/check_sort.c')
-rw-r--r-- | tests/common/check_sort.c | 148 |
1 files changed, 0 insertions, 148 deletions
diff --git a/tests/common/check_sort.c b/tests/common/check_sort.c deleted file mode 100644 index f49710c..0000000 --- a/tests/common/check_sort.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * blogc: A blog compiler. - * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br> - * - * This program can be distributed under the terms of the BSD License. - * See the file LICENSE. - */ - -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> -#include <stdlib.h> -#include <string.h> -#include "../../src/common/utils.h" -#include "../../src/common/sort.h" - - -static int -sort_func(void *a, void *b) -{ - return strcmp((char*) a, (char*) b); -} - - -static void -test_slist_sort_empty(void **state) -{ - bc_slist_t *l = NULL; - assert_null(bc_slist_sort(l, (bc_sort_func_t) sort_func)); -} - - -static void -test_slist_sort_single(void **state) -{ - bc_slist_t *l = NULL; - l = bc_slist_append(l, bc_strdup("a")); - - l = bc_slist_sort(l, (bc_sort_func_t) sort_func); - - assert_non_null(l); - assert_string_equal(l->data, "a"); - assert_null(l->next); - - bc_slist_free_full(l, free); -} - - -static void -test_slist_sort_sorted(void **state) -{ - bc_slist_t *l = NULL; - l = bc_slist_append(l, bc_strdup("a")); - l = bc_slist_append(l, bc_strdup("b")); - l = bc_slist_append(l, bc_strdup("c")); - - l = bc_slist_sort(l, (bc_sort_func_t) sort_func); - - assert_non_null(l); - assert_string_equal(l->data, "a"); - assert_string_equal(l->next->data, "b"); - assert_string_equal(l->next->next->data, "c"); - assert_null(l->next->next->next); - - bc_slist_free_full(l, free); -} - - -static void -test_slist_sort_reverse(void **state) -{ - bc_slist_t *l = NULL; - l = bc_slist_append(l, bc_strdup("d")); - l = bc_slist_append(l, bc_strdup("c")); - l = bc_slist_append(l, bc_strdup("b")); - l = bc_slist_append(l, bc_strdup("a")); - - l = bc_slist_sort(l, (bc_sort_func_t) sort_func); - - assert_non_null(l); - assert_string_equal(l->data, "a"); - assert_string_equal(l->next->data, "b"); - assert_string_equal(l->next->next->data, "c"); - assert_string_equal(l->next->next->next->data, "d"); - assert_null(l->next->next->next->next); - - bc_slist_free_full(l, free); -} - - -static void -test_slist_sort_mixed1(void **state) -{ - bc_slist_t *l = NULL; - l = bc_slist_append(l, bc_strdup("a")); - l = bc_slist_append(l, bc_strdup("d")); - l = bc_slist_append(l, bc_strdup("c")); - l = bc_slist_append(l, bc_strdup("b")); - - l = bc_slist_sort(l, (bc_sort_func_t) sort_func); - - assert_non_null(l); - assert_string_equal(l->data, "a"); - assert_string_equal(l->next->data, "b"); - assert_string_equal(l->next->next->data, "c"); - assert_string_equal(l->next->next->next->data, "d"); - assert_null(l->next->next->next->next); - - bc_slist_free_full(l, free); -} - - -static void -test_slist_sort_mixed2(void **state) -{ - bc_slist_t *l = NULL; - l = bc_slist_append(l, bc_strdup("c")); - l = bc_slist_append(l, bc_strdup("b")); - l = bc_slist_append(l, bc_strdup("a")); - l = bc_slist_append(l, bc_strdup("d")); - - l = bc_slist_sort(l, (bc_sort_func_t) sort_func); - - assert_non_null(l); - assert_string_equal(l->data, "a"); - assert_string_equal(l->next->data, "b"); - assert_string_equal(l->next->next->data, "c"); - assert_string_equal(l->next->next->next->data, "d"); - assert_null(l->next->next->next->next); - - bc_slist_free_full(l, free); -} - - -int -main(void) -{ - const UnitTest tests[] = { - unit_test(test_slist_sort_empty), - unit_test(test_slist_sort_single), - unit_test(test_slist_sort_sorted), - unit_test(test_slist_sort_reverse), - unit_test(test_slist_sort_mixed1), - unit_test(test_slist_sort_mixed2), - }; - return run_tests(tests); -} |