The first function in the plugin must return a pointer to the plugin_table.
[AROS.git] / test / clib / pipe.c
blobb869ddbef4c393abea3cc553c3c4f260cdd31e23
1 #include <unistd.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include "test.h"
6 #define BUFLEN 100
8 int filedes[2] = { 0, 0 };
9 int dupfiledes[2] = { 0, 0 };
11 int main()
13 char source[BUFLEN];
14 char destination[BUFLEN];
15 char *str = "foo";
16 char *str2 = "bar";
17 int i;
19 for(i = 0; i < BUFLEN; i++)
20 source[i] = str[i % strlen(str)];
22 TEST((pipe(filedes) == 0));
23 TEST((write(filedes[1], source, BUFLEN) == BUFLEN));
24 TEST((read(filedes[0], destination, BUFLEN) == BUFLEN));
25 TEST((memcmp(source, destination, BUFLEN) == 0));
27 for(i = 0; i < BUFLEN; i++)
28 source[i] = str2[i % strlen(str2)];
30 TEST((write(filedes[1], source, BUFLEN) == BUFLEN));
31 TEST((read(filedes[0], destination, BUFLEN) == BUFLEN));
32 TEST((memcmp(source, destination, BUFLEN) == 0));
34 for(i = 0; i < 10000; i++)
36 char src = i % 256;
37 char dst;
38 TEST((write(filedes[1], &src, 1) == 1));
39 TEST((read(filedes[0], &dst, 1) == 1));
40 TEST((src == dst));
43 dupfiledes[0] = dup(filedes[0]);
44 TEST((dupfiledes[0] != -1));
46 TEST((write(filedes[1], source, BUFLEN) == BUFLEN));
47 TEST((read(dupfiledes[0], destination, BUFLEN) == BUFLEN));
48 TEST((memcmp(source, destination, BUFLEN) == 0));
50 for(i = 0; i < 10000; i++)
52 char src = i % 256;
53 char dst;
54 TEST((write(filedes[1], &src, 1) == 1));
55 TEST((read(dupfiledes[0], &dst, 1) == 1));
56 TEST((src == dst));
59 dupfiledes[1] = dup(filedes[1]);
60 TEST((dupfiledes[1] != -1));
62 TEST((write(dupfiledes[1], source, BUFLEN) == BUFLEN));
63 TEST((read(filedes[0], destination, BUFLEN) == BUFLEN));
64 TEST((memcmp(source, destination, BUFLEN) == 0));
66 for(i = 0; i < 10000; i++)
68 char src = i % 256;
69 char dst;
70 TEST((write(dupfiledes[1], &src, 1) == 1));
71 TEST((read(filedes[0], &dst, 1) == 1));
72 TEST((src == dst));
75 TEST((write(dupfiledes[1], source, BUFLEN) == BUFLEN));
76 TEST((read(dupfiledes[0], destination, BUFLEN) == BUFLEN));
77 TEST((memcmp(source, destination, BUFLEN) == 0));
79 for(i = 0; i < 10000; i++)
81 char src = i % 256;
82 char dst;
83 TEST((write(dupfiledes[1], &src, 1) == 1));
84 TEST((read(dupfiledes[0], &dst, 1) == 1));
85 TEST((src == dst));
88 TEST((close(dupfiledes[0]) != -1));
89 dupfiledes[0] = 0;
90 TEST((close(dupfiledes[1]) != -1));
91 dupfiledes[1] = 0;
93 TEST((write(filedes[1], source, BUFLEN) == BUFLEN));
94 TEST((read(filedes[0], destination, BUFLEN) == BUFLEN));
95 TEST((memcmp(source, destination, BUFLEN) == 0));
97 for(i = 0; i < 10000; i++)
99 char src = i % 256;
100 char dst;
101 TEST((write(filedes[1], &src, 1) == 1));
102 TEST((read(filedes[0], &dst, 1) == 1));
103 TEST((src == dst));
106 cleanup();
107 return OK;
110 void cleanup()
112 if(filedes[0])
113 close(filedes[0]);
114 if(filedes[1])
115 close(filedes[1]);
116 if(dupfiledes[0])
117 close(dupfiledes[0]);
118 if(dupfiledes[1])
119 close(dupfiledes[1]);