Add some more cases to the app-id unit tests
[glib.git] / tests / spawn-test-win32-gui.c
blob45529d01142fda15a1ae77e169a23f4adad9a2fd
1 #include <windows.h>
2 #include <errno.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <fcntl.h>
8 #ifdef __CYGWIN__
9 /* For read() and write() */
10 #include <unistd.h>
11 /* Cygwin does not prototype __argc and __argv in stdlib.h */
12 extern int __argc;
13 extern char** __argv;
14 #endif
16 int _stdcall
17 WinMain (struct HINSTANCE__ *hInstance,
18 struct HINSTANCE__ *hPrevInstance,
19 char *lpszCmdLine,
20 int nCmdShow)
22 char buf[100];
24 if (__argc >= 2 && strcmp (__argv[1], "nop") == 0)
26 sprintf (buf, "spawn-test-win32-gui: argv[0]=\"%s\"", __argv[0]);
27 MessageBox (NULL, buf, lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
29 else if (__argc <= 2)
31 MessageBox (NULL, "spawn-test-win32-gui: Will write to stdout",
32 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
34 printf ("This is stdout\n");
35 fflush (stdout);
37 MessageBox (NULL, "spawn-test-win32-gui: Will write to stderr",
38 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
40 fprintf (stderr, "This is stderr\n");
41 fflush (stderr);
43 else if (__argc == 4 && strcmp (__argv[1], "pipes") == 0)
45 int infd = atoi (__argv[2]);
46 int outfd = atoi (__argv[3]);
47 int k, n;
49 if (infd < 0 || outfd < 0)
51 MessageBox (NULL, "spawn-test-win32-gui: illegal fds on command line",
52 lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
53 exit (1);
56 MessageBox (NULL, "spawn-test-win32-gui: Will write to parent",
57 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
59 n = strlen ("Hello there");
60 if (write (outfd, &n, sizeof (n)) == -1 ||
61 write (outfd, "Hello there", n) == -1)
63 sprintf (buf, "spawn-test-win32-gui: Write: %s", strerror (errno));
64 MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
65 exit (1);
68 MessageBox (NULL, "spawn-test-win32-gui: Will read from parent",
69 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
71 if ((k = read (infd, &n, sizeof (n))) != sizeof (n))
73 sprintf (buf, "spawn-test-win32-gui: Got only %d bytes, wanted %d",
74 k, sizeof (n));
75 MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
76 exit (1);
79 sprintf (buf, "spawn-test-win32-gui: Parent says %d bytes to read", n);
80 MessageBox (NULL, buf, lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
82 if ((k = read (infd, buf, n)) != n)
84 if (k == -1)
85 sprintf (buf, "spawn-test-win32-gui: Read: %s", strerror (errno));
86 else
87 sprintf (buf, "spawn-test-win32-gui: Got only %d bytes", k);
88 MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
89 exit (1);
92 MessageBox (NULL, "spawn-test-win32-gui: Will write more to parent",
93 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
95 n = strlen ("See ya");
96 if (write (outfd, &n, sizeof (n)) == -1 ||
97 write (outfd, "See ya", n) == -1)
99 sprintf (buf, "spawn-test-win32-gui: Write: %s", strerror (errno));
100 MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
101 exit (1);
105 Sleep (2000);
107 MessageBox (NULL, "spawn-test-win32-gui: Done, exiting.",
108 lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
110 return 0;