Advertisement
Guest User

Untitled

a guest
May 25th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 KB | None | 0 0
  1. #include <stdarg.h>
  2. #include <stddef.h>
  3. #include <setjmp.h>
  4. #include <stdlib.h>
  5. #include <cmocka.h>
  6. #include "dictionary.h"
  7. #include "word_list.h"
  8.  
  9.  
  10. struct _state {
  11.     struct word_list wl;
  12.     struct dictionary *d;
  13. };
  14.  
  15. static int dictionary_setup(void **state)
  16. {
  17.     struct _state *s = malloc(sizeof(struct _state));
  18.     if (!s)
  19.         return -1;
  20.     word_list_init(&s->wl);
  21.     s->d = dictionary_new();
  22.     *state = (void *) s;
  23.     return 0;
  24. }
  25.  
  26. static int dictionary_teardown(void **state)
  27. {
  28.     struct _state *s = (struct _state *) (*state);
  29.     dictionary_done(s->d);
  30.     word_list_done(&s->wl);
  31.     free(s);
  32.     return 0;
  33. }
  34.  
  35. static void dictionary_empty_test(void **state)
  36. {
  37.     struct _state *s = (struct _state *) (*state);
  38.     assert_false(dictionary_find(s->d, L""));
  39.  
  40. }
  41.  
  42. #define WORD_1 L"abc"
  43.  
  44. static void dictionary_insert_remove_test(void **state)
  45. {
  46.     struct _state *s = (struct _state *) (*state);
  47.     dictionary_insert(s->d, WORD_1);
  48.     assert_true(dictionary_find(s->d, WORD_1));
  49.     dictionary_delete(s->d, WORD_1);
  50.     assert_false(dictionary_find(s->d, WORD_1));
  51. }
  52.  
  53. int main () {
  54.     const struct CMUnitTest tests[] = {
  55.             cmocka_unit_test_setup_teardown(dictionary_empty_test, dictionary_setup, dictionary_teardown),
  56.             cmocka_unit_test_setup_teardown(dictionary_insert_remove_test, dictionary_setup, dictionary_teardown)
  57.     };
  58.     return cmocka_run_group_tests(tests, NULL, NULL);
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement