Debian Codegraph @

doc/tutorial_src/words_tests3.c

raw symbols SCIP
1 #include <cgreen/cgreen.h>
2 #include <cgreen/mocks.h>
3
4 #include "words.h"
5 #include <string.h>
6
7 Describe(Words);
8 BeforeEach(Words) {}
9 AfterEach(Words) {}
10
11 Ensure(Words, returns_word_count) {
12 char *sentence = strdup("Birds of a feather");
13 int word_count = split_words(sentence);
14 assert_that(word_count, is_equal_to(4));
15 free(sentence);
16 }
17
18 Ensure(Words, converts_spaces_to_zeroes) {
19 char *sentence = strdup("Birds of a feather");
20 split_words(sentence);
21 int comparison = memcmp("Birds\0of\0a\0feather", sentence, strlen(sentence));
22 assert_that(comparison, is_equal_to(0));
23 free(sentence);
24 }
25
26
27 void mocked_callback(const char *word, void *memo) {
28 mock(word, memo);
29 }
30
31 Ensure(Words, invokes_callback_once_for_single_word_sentence) {
32 expect(mocked_callback,
33 when(word, is_equal_to_string("Word")), when(memo, is_null));
34 words("Word", &mocked_callback, NULL);
35 }
36
37 TestSuite *words_tests() {
38 TestSuite *suite = create_test_suite();
39 add_test_with_context(suite, Words, returns_word_count);
40 add_test_with_context(suite, Words, converts_spaces_to_zeroes);
41 add_test_with_context(suite, Words, invokes_callback_once_for_single_word_sentence);
42 return suite;
43 }
44