1 /* 2 * PROJECT: ReactOS CRT 3 * LICENSE: MIT (https://spdx.org/licenses/MIT) 4 * PURPOSE: Tests for system() 5 * COPYRIGHT: Copyright 2023 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com> 6 */ 7 8 #include <apitest.h> 9 #include <apitest_guard.h> 10 11 START_TEST(system) 12 { 13 int ret; 14 CHAR szCmdExe[MAX_PATH]; 15 16 GetSystemDirectoryA(szCmdExe, _countof(szCmdExe)); 17 lstrcatA(szCmdExe, "\\cmd.exe"); 18 19 SetEnvironmentVariableA("COMSPEC", NULL); 20 errno = 0xDEADBEEF; 21 ret = system(NULL); 22 ok_int(errno, 0xDEADBEEF); 23 ok_int(ret, 1); 24 25 SetEnvironmentVariableA("COMSPEC", "InvalidComSpec"); 26 errno = 0xDEADBEEF; 27 ret = system(NULL); 28 ok_int(errno, 0xDEADBEEF); 29 ok_int(ret, 1); 30 31 SetEnvironmentVariableA("COMSPEC", szCmdExe); 32 errno = 0xDEADBEEF; 33 ret = system(NULL); 34 ok_int(errno, 0xDEADBEEF); 35 ok_int(ret, 1); 36 37 SetEnvironmentVariableA("COMSPEC", NULL); 38 errno = 0xDEADBEEF; 39 ret = system("echo This is a test"); 40 ok_int(errno, 0); 41 ok_int(ret, 0); 42 43 SetEnvironmentVariableA("COMSPEC", "InvalidComSpec"); 44 errno = 0xDEADBEEF; 45 ret = system("echo This is a test"); 46 ok_int(errno, 0); 47 ok_int(ret, 0); 48 49 SetEnvironmentVariableA("COMSPEC", szCmdExe); 50 errno = 0xDEADBEEF; 51 ret = system("echo This is a test"); 52 ok_int(errno, 0); 53 ok_int(ret, 0); 54 55 SetEnvironmentVariableA("COMSPEC", NULL); 56 errno = 0xDEADBEEF; 57 ret = system("InvalidCommandLine"); 58 ok_int(errno, 0); 59 ok_int(ret, 1); 60 61 SetEnvironmentVariableA("COMSPEC", "InvalidComSpec"); 62 errno = 0xDEADBEEF; 63 ret = system("InvalidCommandLine"); 64 ok_int(errno, 0); 65 ok_int(ret, 1); 66 67 SetEnvironmentVariableA("COMSPEC", szCmdExe); 68 errno = 0xDEADBEEF; 69 ret = system("InvalidCommandLine"); 70 ok_int(errno, 0); 71 ok_int(ret, 1); 72 } 73