1 /*
2  * DO NOT EDIT THIS FILE. Generated by checkmk.
3  * Edit the original source file "src/test-inputbuf.cm" instead.
4  */
5 
6 #include <check.h>
7 
8 #line 1 "src/test-inputbuf.cm"
9 /* -*- c -*- */
10 /* test-inputbuf.cm: tests for inputbuf.c. */
11 
12 /*
13     Copyright (C) 2008 Micah Cowan
14 
15     This file is part of GNU teseq.
16 
17     GNU teseq is free software: you can redistribute it and/or modify
18     it under the terms of the GNU General Public License as published by
19     the Free Software Foundation, either version 3 of the License, or
20     (at your option) any later version.
21 
22     GNU teseq is distributed in the hope that it will be useful,
23     but WITHOUT ANY WARRANTY; without even the implied warranty of
24     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25     GNU General Public License for more details.
26 
27     You should have received a copy of the GNU General Public License
28     along with this program.  If not, see <http://www.gnu.org/licenses/>.
29 */
30 
31 #include "teseq.h"
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 
36 #include "inputbuf.h"
37 
38 struct inputbuf *the_buffer;
39 
40 void
initfile(void)41 initfile (void)
42 {
43   FILE *f = fopen ("src/test-inputbuf.inf", "r");
44   fail_if (f == NULL);
45   the_buffer = inputbuf_new (f, 10);
46 }
47 
START_TEST(basic)48 START_TEST(basic)
49 {
50 #line 41
51         /* Reading from the file. */
52         fail_unless (inputbuf_get (the_buffer) == 'a');
53         fail_unless (inputbuf_get (the_buffer) == 'b');
54         fail_unless (inputbuf_get_count (the_buffer) == 2);
55         fail_unless (inputbuf_saving (the_buffer) == 0);
56         /* Reading from the file, and filling the buffer. */
57         fail_unless (inputbuf_get (the_buffer) == 'c');
58         fail_unless (inputbuf_get (the_buffer) == 'd');
59         fail_unless (inputbuf_get (the_buffer) == 'e');
60         /* Count doesn't increment during a save; still 2. */
61         fail_unless (inputbuf_get_count (the_buffer) == 2);
62         fail_unless (inputbuf_rewind (the_buffer) == 0);
63         /* Consuming the save buffer. */
64         fail_unless (inputbuf_get (the_buffer) == 'c');
65         fail_unless (inputbuf_get (the_buffer) == 'd');
66         fail_unless (inputbuf_get_count (the_buffer) == 4);
67         fail_unless (inputbuf_saving (the_buffer) == 0);
68         /* Reading from the buffer, but not consuming. */
69         fail_unless (inputbuf_get (the_buffer) == 'e');
70         fail_unless (inputbuf_get_count (the_buffer) == 4);
71         fail_unless (inputbuf_forget (the_buffer) == 0);
72         /* Count is incremented to the total read characters upon
73            inputbuf_forget. */
74         fail_unless (inputbuf_get_count (the_buffer) == 5);
75         inputbuf_reset_count (the_buffer);
76         fail_unless (inputbuf_get_count (the_buffer) == 0);
77         /* Reading from the file. */
78         fail_unless (inputbuf_get (the_buffer) == 'f');
79         fail_unless (inputbuf_get (the_buffer) == 'g');
80         fail_unless (inputbuf_get (the_buffer) == 'h');
81         /* Reading at EOF. (A saved EOF should give EOF on re-read.) */
82         fail_unless (inputbuf_saving (the_buffer) == 0);
83         fail_unless (inputbuf_get (the_buffer) == EOF);
84         fail_unless (inputbuf_rewind (the_buffer) == 0);
85         fail_unless (inputbuf_get (the_buffer) == EOF);
86 
87 }
88 END_TEST
89 
START_TEST(avail)90 START_TEST(avail)
91 {
92 #line 78
93         fail_unless (inputbuf_avail (the_buffer) == 0);
94         fail_unless (inputbuf_get (the_buffer) == 'a');
95         fail_unless (inputbuf_get (the_buffer) == 'b');
96         fail_unless (inputbuf_get (the_buffer) == 'c');
97         /* Haven't buffered anything, so nothing avail: */
98         fail_unless (inputbuf_avail (the_buffer) == 0);
99         fail_unless (inputbuf_saving (the_buffer) == 0);
100         fail_unless (inputbuf_get (the_buffer) == 'd');
101         fail_unless (inputbuf_get (the_buffer) == 'e');
102         fail_unless (inputbuf_rewind (the_buffer) == 0);
103         fail_unless (inputbuf_avail (the_buffer) != 0);
104         fail_unless (inputbuf_get (the_buffer) == 'd');
105         fail_unless (inputbuf_get (the_buffer) == 'e');
106         fail_unless (inputbuf_avail (the_buffer) == 0);
107 
108 }
109 END_TEST
110 
START_TEST(limits)111 START_TEST(limits)
112 {
113 #line 96
114         FILE *f = fopen ("src/test-inputbuf.inf", "r");
115         fail_if (f == NULL);
116         the_buffer = inputbuf_new (f, 3);
117         fail_unless (inputbuf_saving (the_buffer) == 0);
118         fail_unless (inputbuf_get (the_buffer) == 'a');
119         fail_unless (inputbuf_get (the_buffer) == 'b');
120         fail_unless (inputbuf_get (the_buffer) == 'c');
121         fail_unless (inputbuf_get (the_buffer) == -1);
122 
123 }
124 END_TEST
125 
main(void)126 int main(void)
127 {
128     Suite *s1 = suite_create("Core");
129     TCase *tc1_1 = tcase_create("Core");
130     TCase *tc1_2 = tcase_create("bounds");
131     SRunner *sr = srunner_create(s1);
132     int nf;
133 
134     /* User-specified pre-run code */
135 #line 106
136         tcase_add_checked_fixture (tc1_1, initfile, NULL);
137 
138     suite_add_tcase(s1, tc1_1);
139     tcase_add_test(tc1_1, basic);
140     tcase_add_test(tc1_1, avail);
141     suite_add_tcase(s1, tc1_2);
142     tcase_add_test(tc1_2, limits);
143 
144     srunner_run_all(sr, CK_ENV);
145     nf = srunner_ntests_failed(sr);
146     srunner_free(sr);
147 
148     return nf == 0 ? 0 : 1;
149 }
150