First public contribution.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 #undef G_DISABLE_ASSERT
34 #include "mrt2_glib2_test.h"
37 /* The following test function returns 1 only when the any one of the g_spawn_async tests fails. *
38 * For pass of all the test the function returns 0. */
40 int g_spawn_async_test()
42 gchar *working_directory = NULL;
44 gpointer user_data = "123";
47 GSpawnChildSetupFunc child_setup = NULL;
52 char **argv = NULL; // argv is NULL. should cause g_spawn_async to fail.
54 argv = (char **)malloc(3*sizeof(char *));
55 argv[0] = "Helloworld1.exe"; // wrong exe name. Should cause g_spawn_async to fail
59 if (g_spawn_async(working_directory,argv,envp,flags,child_setup,user_data,&child_pid,&error))
68 argv[0] = "Helloworld.exe"; // set the correct value of argv so that g_spawn_sync is sucessful
70 if (g_spawn_async(working_directory,argv,envp,flags,child_setup,user_data,&child_pid,&error))
78 g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message);
84 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
91 flags = G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH;
93 if (g_spawn_async(working_directory,argv,envp,flags,child_setup,user_data,&child_pid,&error))
95 g_spawn_close_pid(child_pid);
101 g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message);
107 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
113 flags = G_SPAWN_FILE_AND_ARGV_ZERO;
114 if (g_spawn_async(working_directory,argv,envp,flags,child_setup,user_data,&child_pid,&error))
122 g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message);
128 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
133 working_directory = "c:\\sys\\bin";
134 envp = (char **)malloc(2*sizeof(char *));
135 envp[0] = "path = c:\\sys\\bin";
137 if (g_spawn_async(working_directory,argv,envp,flags,child_setup,user_data,&child_pid,&error))
145 g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message);
151 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
165 /* The following test function returns 1 only when the any one of the g_spawn_async_with_pipes *
166 tests fails.For pass of all the test the function returns 0. */
167 int g_spawn_async_with_pipes_test()
169 gchar *working_directory = NULL;
171 gpointer user_data = "123";
172 GError *error = NULL;
174 GSpawnChildSetupFunc child_setup = NULL;
179 int standard_input, standard_output,standard_error;
181 char **argv = (char **)malloc(3*sizeof(char *));
182 argv[0] = "Helloworld.exe"; // wrong exe name. Should cause g_spawn_async to fail
187 if(g_spawn_async_with_pipes(working_directory,argv,envp,flags,child_setup,user_data,&child_pid,NULL,NULL,NULL,&error))
195 g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message);
201 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
206 flags = G_SPAWN_FILE_AND_ARGV_ZERO;
208 if(g_spawn_async_with_pipes(working_directory,argv,envp,flags,child_setup,user_data,&child_pid,&standard_input,&standard_output,&standard_error,&error))
210 if(standard_input != -1 || standard_output != -1 || standard_error != -1)
212 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
220 g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message);
226 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
233 /* The following test function returns 1 only when the any one of the g_spawn_sync *
234 tests fails.For pass of all the test the function returns 0. */
235 int g_spawn_sync_test()
237 gchar *working_directory = NULL;
239 gpointer user_data = "123";
240 GError *error = NULL;
243 GSpawnChildSetupFunc child_setup = NULL;
248 gchar *standard_output = NULL, *standard_error = NULL;
250 char **argv = (char **)malloc(3*sizeof(char *));
251 argv[0] = "Helloworld.exe";
255 flags = G_SPAWN_FILE_AND_ARGV_ZERO;
257 if(g_spawn_sync(working_directory,argv,envp,flags,NULL,user_data,NULL,NULL,&exit_status,&error))
261 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
269 g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message);
275 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
280 if(g_spawn_sync(working_directory,argv,envp,flags,NULL,user_data,&standard_output,&standard_error,NULL,&error))
288 g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message);
294 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
305 /* The following test function returns 1 only when the any one of the g_spawn_command_line_async *
306 tests fails.For pass of all the test the function returns 0. */
307 int g_spawn_command_line_async_tests()
309 GError *error = NULL;
312 if(g_spawn_command_line_async("helloworld.exe 1 2 3",&error))
320 g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message);
326 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
335 /* The following test function returns 1 only when the any one of the g_spawn_command_line_sync *
336 tests fails.For pass of all the test the function returns 0. */
337 int g_spawn_command_line_sync_tests()
339 GError *error = NULL;
342 gchar *standard_output, *standard_error;
344 if(g_spawn_command_line_sync("helloworld.exe 10 11 12",NULL,NULL,&exit_status,&error))
348 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
356 g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message);
362 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
368 if(g_spawn_command_line_sync("helloworld.exe 10 11 12",&standard_output,&standard_error,&exit_status,&error))
370 if(exit_status != 0 || standard_output != NULL || standard_error != NULL)
372 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
380 g_log(NULL,G_LOG_LEVEL_CRITICAL,"file %s: line %d Error Message:%s",__FILE__, __LINE__, error->message);
386 g_log(NULL,G_LOG_LEVEL_CRITICAL,"Error in file %s: at line %d",__FILE__, __LINE__);
400 #if defined(SYMBIAN) && (defined(__WINS__) || defined(__WINSCW__))
402 testResultXml("spawn_test");
409 g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
412 // calling g_spawn_close_pid() with some invalid handle. Should not cause panic.
413 // Instead the API should return without any problems.
414 g_spawn_close_pid(146545);
416 if(g_spawn_async_test() || g_spawn_async_with_pipes_test() || g_spawn_sync_test() || g_spawn_command_line_async_tests() || g_spawn_command_line_sync_tests())
421 assert_failed = retval;
424 testResultXml("spawn_test");
425 #endif /* EMULATOR */