mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
gspawn, tests: extend spawn_test, run it on win32
The spawn_test is enabled on win32 meson build, both msys and msvc. Some modifications to make it useful for auto-testing on win32: - use own argv0 to find helper win32-specific subprogram - helper subprogram and conditions changed, so testing is fully automated instead of manually checking contents of some MessageBoxes Redirection test checks "sort" output for locale-independent string instead of relying on "netstat" locale-dependent string. Also with "sort" it become usable on unix, so enabled there too. Currently this fails on win32 with coverage since some coverage-realted error output from gpawn-win32-helper is unexpectedly treated as executed subprocess output. Added test checking "sort" with error-only redirection. This also fails on win32 by now, due to a typo in gspawn-win32.c (checks for stdout redirection instead of stderr)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -19,24 +20,15 @@ WinMain (struct HINSTANCE__ *hInstance,
|
||||
char *lpszCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
char buf[100];
|
||||
|
||||
if (__argc >= 2 && strcmp (__argv[1], "nop") == 0)
|
||||
if (__argc >= 2 && strcmp (__argv[1], "print_argv0") == 0)
|
||||
{
|
||||
sprintf (buf, "spawn-test-win32-gui: argv[0]=\"%s\"", __argv[0]);
|
||||
MessageBox (NULL, buf, lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
||||
printf ("%s", __argv[0]);
|
||||
}
|
||||
else if (__argc <= 2)
|
||||
{
|
||||
MessageBox (NULL, "spawn-test-win32-gui: Will write to stdout",
|
||||
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
||||
|
||||
printf ("This is stdout\n");
|
||||
fflush (stdout);
|
||||
|
||||
MessageBox (NULL, "spawn-test-win32-gui: Will write to stderr",
|
||||
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
||||
|
||||
fprintf (stderr, "This is stderr\n");
|
||||
fflush (stderr);
|
||||
}
|
||||
@@ -45,70 +37,52 @@ WinMain (struct HINSTANCE__ *hInstance,
|
||||
int infd = atoi (__argv[2]);
|
||||
int outfd = atoi (__argv[3]);
|
||||
int k, n;
|
||||
char buf[100] = {0};
|
||||
|
||||
if (infd < 0 || outfd < 0)
|
||||
{
|
||||
MessageBox (NULL, "spawn-test-win32-gui: illegal fds on command line",
|
||||
lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
||||
printf ("spawn-test-win32-gui: illegal fds on command line %s",
|
||||
lpszCmdLine);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
MessageBox (NULL, "spawn-test-win32-gui: Will write to parent",
|
||||
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
||||
|
||||
n = strlen ("Hello there");
|
||||
if (write (outfd, &n, sizeof (n)) == -1 ||
|
||||
write (outfd, "Hello there", n) == -1)
|
||||
{
|
||||
int errsv = errno;
|
||||
sprintf (buf, "spawn-test-win32-gui: Write: %s", strerror (errsv));
|
||||
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
||||
printf ("spawn-test-win32-gui: Write error: %s", strerror (errsv));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
MessageBox (NULL, "spawn-test-win32-gui: Will read from parent",
|
||||
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
||||
|
||||
if ((k = read (infd, &n, sizeof (n))) != sizeof (n))
|
||||
{
|
||||
sprintf (buf, "spawn-test-win32-gui: Got only %d bytes, wanted %d",
|
||||
k, sizeof (n));
|
||||
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
||||
printf ("spawn-test-win32-gui: Got only %d bytes, wanted %d",
|
||||
k, (int)sizeof (n));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
sprintf (buf, "spawn-test-win32-gui: Parent says %d bytes to read", n);
|
||||
MessageBox (NULL, buf, lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
||||
printf ("spawn-test-win32-gui: Parent says %d bytes to read", n);
|
||||
|
||||
if ((k = read (infd, buf, n)) != n)
|
||||
{
|
||||
int errsv = errno;
|
||||
if (k == -1)
|
||||
sprintf (buf, "spawn-test-win32-gui: Read: %s", strerror (errsv));
|
||||
printf ("spawn-test-win32-gui: Read error: %s", strerror (errsv));
|
||||
else
|
||||
sprintf (buf, "spawn-test-win32-gui: Got only %d bytes", k);
|
||||
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
||||
printf ("spawn-test-win32-gui: Got only %d bytes", k);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
MessageBox (NULL, "spawn-test-win32-gui: Will write more to parent",
|
||||
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
||||
|
||||
n = strlen ("See ya");
|
||||
if (write (outfd, &n, sizeof (n)) == -1 ||
|
||||
write (outfd, "See ya", n) == -1)
|
||||
{
|
||||
int errsv = errno;
|
||||
sprintf (buf, "spawn-test-win32-gui: Write: %s", strerror (errsv));
|
||||
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
||||
printf ("spawn-test-win32-gui: Write error: %s", strerror (errsv));
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
Sleep (2000);
|
||||
|
||||
MessageBox (NULL, "spawn-test-win32-gui: Done, exiting.",
|
||||
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user