Move tree tests to the test framework
[platform/upstream/glib.git] / tests / spawn-test.c
index cfd4e0e..1bc360a 100644 (file)
@@ -35,6 +35,7 @@
 #ifdef G_OS_WIN32
 #include <fcntl.h>
 #include <io.h>
+#define pipe(fds) _pipe(fds, 4096, _O_BINARY)
 #endif
 
 
@@ -49,27 +50,31 @@ run_tests (void)
   gchar **argv = 0;
 #endif
   
-  printf ("The following errors are supposed to occur:\n");
-
   err = NULL;
   if (!g_spawn_command_line_sync ("nonexistent_application foo 'bar baz' blah blah",
                                   NULL, NULL, NULL,
                                   &err))
     {
-      fprintf (stderr, "Error (normal, supposed to happen): %s\n", err->message);
       g_error_free (err);
     }
+  else
+    {
+      g_warning ("no error for sync spawn of nonexistent application");
+      exit (1);
+    }
 
   err = NULL;
   if (!g_spawn_command_line_async ("nonexistent_application foo bar baz \"blah blah\"",
                                    &err))
     {
-      fprintf (stderr, "Error (normal, supposed to happen): %s\n", err->message);
       g_error_free (err);
     }
+  else
+    {
+      g_warning ("no error for async spawn of nonexistent application");
+      exit (1);
+    }
 
-  printf ("Errors after this are not supposed to happen:\n");
-  
   err = NULL;
 #ifdef G_OS_UNIX
   if (!g_spawn_command_line_sync ("/bin/sh -c 'echo hello'",
@@ -96,9 +101,9 @@ run_tests (void)
     }
 #else
 #ifdef G_OS_WIN32
-  printf ("Running ipconfig synchronously, collecting its output\n");
+  printf ("Running netstat synchronously, collecting its output\n");
 
-  if (!g_spawn_command_line_sync ("ipconfig /all",
+  if (!g_spawn_command_line_sync ("netstat -n",
                                   &output, &erroutput, NULL,
                                   &err))
     {
@@ -111,9 +116,9 @@ run_tests (void)
       g_assert (output != NULL);
       g_assert (erroutput != NULL);
       
-      if (strstr (output, "IP Configuration") == 0)
+      if (strstr (output, "Active Connections") == 0)
         {
-          printf ("output was '%s', should have contained 'IP Configuration'\n",
+          printf ("output was '%s', should have contained 'Active Connections'\n",
                   output);
 
           exit (1);
@@ -131,8 +136,9 @@ run_tests (void)
       erroutput = NULL;
     }
 
-  printf ("Starting spawn-test-win32-gui asynchronously (without wait).\n"
-         "Click on the OK buttons.\n");
+  printf ("Running spawn-test-win32-gui in various ways. Click on the OK buttons.\n");
+
+  printf ("First asynchronously (without wait).\n");
 
   if (!g_spawn_command_line_async ("'.\\spawn-test-win32-gui.exe' 1", &err))
     {
@@ -141,8 +147,7 @@ run_tests (void)
       exit (1);
     }
 
-  printf ("Running spawn-test-win32-gui synchronously,\n"
-         "collecting its output. Click on the OK buttons.\n");
+  printf ("Now synchronously, collecting its output.\n");
   if (!g_spawn_command_line_sync ("'.\\spawn-test-win32-gui.exe' 2",
                                  &output, &erroutput, NULL,
                                  &err))
@@ -174,8 +179,26 @@ run_tests (void)
       g_free (erroutput);
     }
 
-  printf ("Running spawn-test-win32-gui asynchronously again.\n"
-         "This time talking to it through pipes. Click on the OK buttons.\n");
+  printf ("Now with G_SPAWN_FILE_AND_ARGV_ZERO.\n");
+
+  if (!g_shell_parse_argv ("'.\\spawn-test-win32-gui.exe' this-should-be-argv-zero nop", NULL, &argv, &err))
+    {
+      fprintf (stderr, "Error parsing command line? %s\n", err->message);
+      g_error_free (err);
+      exit (1);
+    }
+
+  if (!g_spawn_async (NULL, argv, NULL,
+                     G_SPAWN_FILE_AND_ARGV_ZERO,
+                     NULL, NULL, NULL,
+                     &err))
+    {
+      fprintf (stderr, "Error: %s\n", err->message);
+      g_error_free (err);
+      exit (1);
+    }
+
+  printf ("Now talking to it through pipes.\n");
 
   if (pipe (pipedown) < 0 ||
       pipe (pipeup) < 0)