1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <sys/wait.h>
5 #include <gtk/gtk.h>
6 #include <ol_fork.h>
7 
8 #define BUFFER_SIZE 1024
9 
10 void
callback(void * ret_data,size_t ret_size,int status,void * data)11 callback (void *ret_data,
12           size_t ret_size,
13           int status,
14           void *data)
15 {
16   printf ("callback called\n");
17   printf ("return status: %d\n", WEXITSTATUS (status));
18   printf ("received: %s\n", (char*)ret_data);
19   if (data != NULL)
20     printf ("data: %s\n", (char *) data);
21 }
22 
23 void
test_normal()24 test_normal ()
25 {
26   static const char msg[] = "Fork Message";
27   printf ("Forking\n");
28   if (ol_fork (callback, (void*)msg, NULL) == 0)
29   {
30     sleep (2);
31     fprintf (fret, msg);
32     exit (0);
33   }
34   else
35   {
36     printf ("Fork succeeded\n");
37   }
38 }
39 
40 void
test_multiple_output()41 test_multiple_output ()
42 {
43   printf ("Forking\n");
44   if (ol_fork (callback, NULL, NULL) == 0)
45   {
46     fprintf (fret, "Before Sleep\n");
47     sleep (2);
48     fprintf (fret, "After Sleep\n");
49     exit (0);
50   }
51   else
52   {
53     printf ("Fork succeeded\n");
54   }
55 }
56 
57 void
test_no_output()58 test_no_output ()
59 {
60   printf ("Forking\n");
61   if (ol_fork (callback, NULL, NULL) == 0)
62   {
63     exit (0);
64   }
65   else
66   {
67     printf ("Fork succeeded\n");
68   }
69 }
70 
71 void
test_exit_status()72 test_exit_status ()
73 {
74   printf ("Forking\n");
75   if (ol_fork (callback, NULL, NULL) == 0)
76   {
77     exit (10);
78   }
79   else
80   {
81     printf ("Fork succeeded\n");
82   }
83 }
84 
85 int
main(int argc,char ** argv)86 main (int argc, char **argv)
87 {
88   GMainLoop *loop = g_main_loop_new (NULL, FALSE);
89   test_normal ();
90   test_multiple_output ();
91   test_no_output ();
92   test_exit_status ();
93   g_main_loop_run (loop);
94   return 0;
95 }
96