Debian Codegraph @

doc/tutorial_src/stream_tests2.c

raw symbols SCIP
1 #include <cgreen/cgreen.h>
2 #include <cgreen/mocks.h>
3
4 char *read_paragraph(int (*read)(void *), void *stream);
5
6 static int stream_stub(void *stream) {
7 return (int)mock(stream);
8 }
9
10 Describe(ParagraphReader);
11 BeforeEach(ParagraphReader) {}
12 AfterEach(ParagraphReader) {}
13
14 Ensure(ParagraphReader, gives_null_when_reading_empty_stream) {
15 always_expect(stream_stub, will_return(EOF)); // <1>
16 assert_that(read_paragraph(&stream_stub, NULL), is_null);
17 }
18
19 Ensure(ParagraphReader, gives_one_character_line_for_one_character_stream) {
20 expect(stream_stub, will_return('a'));
21 expect(stream_stub, will_return(EOF));
22 char *line = read_paragraph(&stream_stub, NULL);
23 assert_that(line, is_equal_to_string("a"));
24 free(line);
25 }