Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdarg.h>
- #include <stddef.h>
- #include <setjmp.h>
- #include <stdlib.h>
- #include <cmocka.h>
- #include "dictionary.h"
- #include "word_list.h"
- struct _state {
- struct word_list wl;
- struct dictionary *d;
- };
- static int dictionary_setup(void **state)
- {
- struct _state *s = malloc(sizeof(struct _state));
- if (!s)
- return -1;
- word_list_init(&s->wl);
- s->d = dictionary_new();
- *state = (void *) s;
- return 0;
- }
- static int dictionary_teardown(void **state)
- {
- struct _state *s = (struct _state *) (*state);
- dictionary_done(s->d);
- word_list_done(&s->wl);
- free(s);
- return 0;
- }
- static void dictionary_empty_test(void **state)
- {
- struct _state *s = (struct _state *) (*state);
- assert_false(dictionary_find(s->d, L""));
- }
- #define WORD_1 L"abc"
- static void dictionary_insert_remove_test(void **state)
- {
- struct _state *s = (struct _state *) (*state);
- dictionary_insert(s->d, WORD_1);
- assert_true(dictionary_find(s->d, WORD_1));
- dictionary_delete(s->d, WORD_1);
- assert_false(dictionary_find(s->d, WORD_1));
- }
- int main () {
- const struct CMUnitTest tests[] = {
- cmocka_unit_test_setup_teardown(dictionary_empty_test, dictionary_setup, dictionary_teardown),
- cmocka_unit_test_setup_teardown(dictionary_insert_remove_test, dictionary_setup, dictionary_teardown)
- };
- return cmocka_run_group_tests(tests, NULL, NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement