chiark / gitweb /
Disobedience: basic support for required/prohibited tags.
[disorder] / libtests / t-sink.c
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 #include "test.h"
19
20 static void test_sink(void) {
21   struct sink *s;
22   struct dynstr d[1];
23   FILE *fp;
24   char *l;
25
26   fp = tmpfile();
27   assert(fp != 0);
28   s = sink_stdio("tmpfile", fp);
29   insist(sink_printf(s, "test: %d\n", 999) == 10);
30   insist(sink_printf(s, "wibble: %s\n", "foobar") == 15);
31   rewind(fp);
32   insist(inputline("tmpfile", fp, &l, '\n') == 0);
33   check_string(l, "test: 999");
34   insist(inputline("tmpfile", fp, &l, '\n') == 0);
35   check_string(l, "wibble: foobar");
36   insist(inputline("tmpfile", fp, &l, '\n') == -1);
37
38   fp = tmpfile();
39   assert(fp != 0);
40   fprintf(fp, "foo\rbar\nwibble\r\n");
41   fprintf(fp, "second\n\rspong\r\n");
42   rewind(fp);
43   insist(inputline("tmpfile", fp, &l, CRLF) == 0);
44   check_string(l, "foo\rbar\nwibble");
45   insist(inputline("tmpfile", fp, &l, CRLF) == 0);
46   check_string(l, "second\n\rspong");
47   insist(inputline("tmpfile", fp, &l, CRLF) == -1);
48   
49   dynstr_init(d);
50   s = sink_dynstr(d);
51   insist(sink_printf(s, "test: %d\n", 999) == 10);
52   insist(sink_printf(s, "wibble: %s\n", "foobar") == 15);
53   dynstr_terminate(d);
54   check_string(d->vec, "test: 999\nwibble: foobar\n");
55 }
56
57 TEST(sink);
58
59 /*
60 Local Variables:
61 c-basic-offset:2
62 comment-column:40
63 fill-column:79
64 indent-tabs-mode:nil
65 End:
66 */