This source file includes following definitions.
- small_nap
- prepare_read
- ignore_done_read
- output_done_read
- pipe_filter_gi_write_string
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include "pipe-filter.h"
22
23 #include <stdio.h>
24 #include <errno.h>
25 #include <unistd.h>
26 #include <string.h>
27 #include <signal.h>
28
29 #include "full-write.h"
30 #include "macros.h"
31
32
33 static void
34 small_nap (void)
35 {
36 usleep (100000);
37 }
38
39 static char static_buf[5];
40
41 static void *
42 prepare_read (size_t *num_bytes_p, void *private_data)
43 {
44 *num_bytes_p = sizeof (static_buf);
45 return static_buf;
46 }
47
48
49
50 static void
51 ignore_done_read (void *data_read, size_t num_bytes_read, void *private_data)
52 {
53 }
54
55
56
57 static void
58 output_done_read (void *data_read, size_t num_bytes_read, void *private_data)
59 {
60 full_write (STDOUT_FILENO, data_read, num_bytes_read);
61 }
62
63 static void
64 pipe_filter_gi_write_string (struct pipe_filter_gi *f, const char *string)
65 {
66 pipe_filter_gi_write (f, string, strlen (string));
67 }
68
69 int
70 main (int argc, char **argv)
71 {
72 struct pipe_filter_gi *f;
73 const char *path[] = { NULL, NULL };
74
75 ASSERT (argc == 2);
76
77
78 {
79 int rc;
80
81 path[0] = "/nonexistent/blah";
82 f = pipe_filter_gi_create ("pipe-filter-test", path[0], path, true, false,
83 prepare_read, ignore_done_read, NULL);
84 small_nap ();
85 rc = pipe_filter_gi_write (f, "", 1);
86 ASSERT (rc == 127 || rc == -1);
87 rc = pipe_filter_gi_close (f);
88 ASSERT (rc == 127 || rc == -1);
89 printf ("Test 1 passed.\n");
90 fflush (stdout);
91 }
92
93
94 {
95 path[0] = argv[1];
96 f = pipe_filter_gi_create ("pipe-filter-test", path[0], path, false, false,
97 prepare_read, ignore_done_read, NULL);
98 pipe_filter_gi_write_string (f, "1 -1");
99 ASSERT (pipe_filter_gi_close (f) == 1);
100 printf ("Test 2 passed.\n");
101 fflush (stdout);
102 }
103
104
105 {
106 int rc;
107
108 path[0] = argv[1];
109 f = pipe_filter_gi_create ("pipe-filter-test", path[0], path, false, false,
110 prepare_read, ignore_done_read, NULL);
111 pipe_filter_gi_write_string (f, "1 -1\n");
112 small_nap ();
113 rc = pipe_filter_gi_write (f, " ", 1);
114 ASSERT (rc == -1 && errno == EPIPE);
115
116
117 rc = pipe_filter_gi_close (f);
118 ASSERT (rc == -1 && errno == EPIPE);
119 printf ("Test 3 passed.\n");
120 fflush (stdout);
121 }
122
123
124 {
125 path[0] = argv[1];
126 f = pipe_filter_gi_create ("pipe-filter-test", path[0], path, false, true,
127 prepare_read, output_done_read, NULL);
128 pipe_filter_gi_write_string (f, "1 50\n");
129 pipe_filter_gi_write_string (f, "51\n");
130 pipe_filter_gi_write_string (f, "100");
131 ASSERT (pipe_filter_gi_close (f) == 0);
132 printf ("Test 4 passed.\n");
133 fflush (stdout);
134 }
135
136 return 0;
137 }