Update contrib.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Test code for pipes, using dubious WINS extension for multiple processes...
25 #include <unistd.h> /* for MAXPATHLEN */
26 #include <sys/errno.h>
27 #include <sys/ioctl.h>
34 @SYMTestCaseID SYSLIB-STDLIB-CT-1092
35 @SYMTestCaseDesc Tests for operations on pipes
37 @SYMTestActions Tests for command line arguments,directory operations,environment variables.
38 @SYMTestExpectedResults Test must not fail
41 int do_main(int argc, wchar_t* argv[])
47 wchar_t cwd[MAXPATHLEN];
53 test_Next("Command line arguments");
56 printf(" argc=%d\r\n", argc);
57 for (i=0; i<argc; i++)
60 test(-1 != wcstombs(buf, argv[i], sizeof(buf)));
61 printf(" argv[%d]=\"%s\" length %d\r\n", i, buf, strlen(buf));
65 test_Next("Current working directory");
66 var=wgetcwd(cwd,sizeof(cwd)/2);
68 test(-1 != wcstombs(buf, cwd, sizeof(buf)));
69 printf(" %s\r\n\n", buf);
71 test_Next("Change directory");
72 i=wchdir((wchar_t*)L"z:/system");
74 var=wgetcwd(cwd,sizeof(cwd)/2);
76 test(-1 != wcstombs(buf, cwd, sizeof(buf)));
77 printf(" %s\r\n\n", buf);
79 test_Next("Environment variables");
81 varname=(wchar_t*)L"CLASSPATH";
84 test(-1 != wcstombs(buf, var, sizeof(buf)));
85 test(-1 != wcstombs(buf1, varname, sizeof(buf1)));
86 printf(" %s=%s\r\n", buf1, buf);
88 varname=(wchar_t*)"VARIABLE2";
92 test(-1 != wcstombs(buf, var, sizeof(buf)));
93 test(-1 != wcstombs(buf1, varname, sizeof(buf1)));
94 printf(" %s=%s\r\n", buf1, buf);
95 wunsetenv((wchar_t*)"VARIABLE2");
98 varname=(wchar_t*)L"USER";
101 test(-1 != wcstombs(buf, var, sizeof(buf)));
102 test(-1 != wcstombs(buf1, varname, sizeof(buf1)));
103 printf(" %s=%s\r\n", buf1, buf);
111 /* bodge up two pretend processes */
115 wchar_t* argv[] = { (wchar_t*)L"twpipe.exe", (wchar_t*)L"A" };
117 wsetenv((wchar_t*)L"CLASSPATH",(wchar_t*)L".;classes;?:/classes;?:/system/java/lib/classes.zip",0);
118 wsetenv((wchar_t*)L"VARIABLE2",(wchar_t*)L"value2",0);
119 wsetenv((wchar_t*)L"USER",(wchar_t*)L"Tumblin' Wide Boy - Go fer yer guns!",0);
125 @SYMTestCaseID SYSLIB-STDLIB-CT-1093
126 @SYMTestCaseDesc Tests for operations on a child pipe
127 @SYMTestPriority High
128 @SYMTestActions Tests for reading from a pipe in the child process
129 @SYMTestExpectedResults Test must not fail
135 wchar_t* argv[] = {(wchar_t*) L"twpipe.exe", (wchar_t*)L"B" };
140 /* Don't use test_* because it involves fflush and will cause deadlock */
141 printf("PIPE Child");
143 printf("Child reads from STDIN\n");
147 printf("Child calls read of fid=0\n");
148 nbytes=read(0,buf,sizeof(buf));
149 printf("Child got %d bytes\n", nbytes);
154 /* We hope that there is still stuff to read */
155 printf("Child calls E32IOSELECT(WRITE) on STDIN\n");
156 mask=E32SELECT_WRITE;
157 err=ioctl(0,E32IOSELECT,(void*)&mask);
160 printf("Child calls E32IOSELECT(READ) on STDIN\n");
161 mask=E32SELECT_READ+E32SELECT_WRITE;
162 err=ioctl(0,E32IOSELECT,(void*)&mask);
164 test(mask==E32SELECT_READ);
167 printf(" %02d >%.*s<\n", nbytes, nbytes, buf);
171 printf(" %d (errno=%d)\n", nbytes, errno);
174 printf("Child calls E32IOSELECT on STDOUT");
175 mask=E32SELECT_READ+E32SELECT_WRITE;
176 err=ioctl(1,E32IOSELECT,(void*)&mask);
178 test(mask==E32SELECT_WRITE);
187 @SYMTestCaseID SYSLIB-STDLIB-CT-1094
188 @SYMTestCaseDesc Tests for pipe file descriptors
189 @SYMTestPriority High
190 @SYMTestActions Tests for writing to the pipe file descriptors
191 @SYMTestExpectedResults Test must not fail
202 test_Next("Pipe file descriptors");
203 printf(" fids= %d, %d, %d\n", fids[0], fids[1], fids[2]);
210 const char* buf="test data 18 bytes";
212 test_Next("E32IOSELECT(READ) on Child STDIN");
214 err=ioctl(fids[0],E32IOSELECT,(void*)&mask);
217 test_Next("E32IOSELECT(WRITE) on Child STDIN");
218 mask=E32SELECT_READ+E32SELECT_WRITE;
219 err=ioctl(fids[0],E32IOSELECT,(void*)&mask);
221 test(mask==E32SELECT_WRITE);
223 test_Next("Child STDIN");
224 remainder=strlen(buf);
227 int length=(remainder<7)?remainder:7;
228 nbytes=write(fids[0],buf,length);
229 printf(" >%.*s<",nbytes,buf);
233 test(nbytes<=length);
245 test_Next("Child STDOUT");
246 cout=wfdopen(fids[1],(wchar_t*)L"r");
251 s=fgets(buf,sizeof(buf),cout);
257 test_Next("\nE32IOSELECT(WRITE) on Child STDOUT");
258 mask=E32SELECT_WRITE;
259 err=ioctl(fids[1],E32IOSELECT,(void*)&mask);
262 test_Next("E32IOSELECT(READ) on Child STDOUT");
263 mask=E32SELECT_READ+E32SELECT_WRITE;
264 err=ioctl(fids[1],E32IOSELECT,(void*)&mask);
266 test(mask==E32SELECT_READ);
278 /* Linked with mcrt0.o, so that the exe starts the CPosixServer automatically as per the
282 int wmain(int argc, wchar_t* argv[])
286 start_redirection_server();
292 proc2 = create_process(do_mainB, "B", "rw", fids);
294 start_process(proc2);
296 perror("Failed to start processB: ");
302 exit=wait_for_process(proc2);
303 printf("wait_for_process returned %d\r\n", exit);