Merge branch 'aw/git-p4-deletion'
[git/kirr.git] / test-line-buffer.c
blobc11bf7f96708c90c992423fc27b2eba73d0c34a0
1 /*
2 * test-line-buffer.c: code to exercise the svn importer's input helper
4 * Input format:
5 * number NL
6 * (number bytes) NL
7 * number NL
8 * ...
9 */
11 #include "git-compat-util.h"
12 #include "vcs-svn/line_buffer.h"
14 static uint32_t strtouint32(const char *s)
16 char *end;
17 uintmax_t n = strtoumax(s, &end, 10);
18 if (*s == '\0' || *end != '\0')
19 die("invalid count: %s", s);
20 return (uint32_t) n;
23 int main(int argc, char *argv[])
25 char *s;
27 if (argc != 1)
28 usage("test-line-buffer < input.txt");
29 if (buffer_init(NULL))
30 die_errno("open error");
31 while ((s = buffer_read_line())) {
32 s = buffer_read_string(strtouint32(s));
33 fputs(s, stdout);
34 fputc('\n', stdout);
35 buffer_skip_bytes(1);
36 if (!(s = buffer_read_line()))
37 break;
38 buffer_copy_bytes(strtouint32(s) + 1);
40 if (buffer_deinit())
41 die("input error");
42 if (ferror(stdout))
43 die("output error");
44 buffer_reset();
45 return 0;