process.c
来自「Wine-20031016」· C语言 代码 · 共 1,201 行 · 第 1/4 页
C
1,201 行
char buffer[MAX_PATH]; PROCESS_INFORMATION info; STARTUPINFOA startup; DWORD exit_status; /* let's start simplistic */ memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); startup.dwFlags = STARTF_USESHOWWINDOW; startup.wShowWindow = SW_SHOWNORMAL; get_file_name(resfile); sprintf(buffer, "%s tests/process.c %s", selfname, resfile); ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, NULL, &startup, &info), "CreateProcess"); ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running"); Sleep(8000); ok(GetExitCodeThread(info.hThread, &exit_status) && exit_status == STILL_ACTIVE, "thread still running"); ok(ResumeThread(info.hThread) == 1, "Resuming thread"); /* wait for child to terminate */ ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination"); /* child process has changed result file, so let profile functions know about it */ WritePrivateProfileStringA(NULL, NULL, NULL, resfile); okChildInt("StartupInfoA", "cb", startup.cb); okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop); okChildString("StartupInfoA", "lpTitle", startup.lpTitle); okChildInt("StartupInfoA", "dwX", startup.dwX); okChildInt("StartupInfoA", "dwY", startup.dwY); okChildInt("StartupInfoA", "dwXSize", startup.dwXSize); okChildInt("StartupInfoA", "dwYSize", startup.dwYSize); okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars); okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars); okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute); okChildInt("StartupInfoA", "dwFlags", startup.dwFlags); okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow); release_memory(); assert(DeleteFileA(resfile) != 0);}static void test_DebuggingFlag(void){ char buffer[MAX_PATH]; PROCESS_INFORMATION info; STARTUPINFOA startup; DEBUG_EVENT de; unsigned dbg = 0; /* let's start simplistic */ memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); startup.dwFlags = STARTF_USESHOWWINDOW; startup.wShowWindow = SW_SHOWNORMAL; get_file_name(resfile); sprintf(buffer, "%s tests/process.c %s", selfname, resfile); ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &startup, &info), "CreateProcess"); /* get all startup events up to the entry point break exception */ do { ok(WaitForDebugEvent(&de, INFINITE), "reading debug event"); ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE); if (de.dwDebugEventCode != EXCEPTION_DEBUG_EVENT) dbg++; } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT); ok(dbg, "I have seen a debug event"); /* wait for child to terminate */ ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination"); /* child process has changed result file, so let profile functions know about it */ WritePrivateProfileStringA(NULL, NULL, NULL, resfile); okChildInt("StartupInfoA", "cb", startup.cb); okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop); okChildString("StartupInfoA", "lpTitle", startup.lpTitle); okChildInt("StartupInfoA", "dwX", startup.dwX); okChildInt("StartupInfoA", "dwY", startup.dwY); okChildInt("StartupInfoA", "dwXSize", startup.dwXSize); okChildInt("StartupInfoA", "dwYSize", startup.dwYSize); okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars); okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars); okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute); okChildInt("StartupInfoA", "dwFlags", startup.dwFlags); okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow); release_memory(); assert(DeleteFileA(resfile) != 0);}static void test_Console(void){ char buffer[MAX_PATH]; PROCESS_INFORMATION info; STARTUPINFOA startup; SECURITY_ATTRIBUTES sa; CONSOLE_SCREEN_BUFFER_INFO sbi, sbiC; DWORD modeIn, modeOut, modeInC, modeOutC; DWORD cpIn, cpOut, cpInC, cpOutC; DWORD w; HANDLE hChildIn, hChildInInh, hChildOut, hChildOutInh, hParentIn, hParentOut; const char* msg = "This is a std-handle inheritance test."; unsigned msg_len; memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES; startup.wShowWindow = SW_SHOWNORMAL; sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0); startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0); /* first, we need to be sure we're attached to a console */ if (startup.hStdInput == INVALID_HANDLE_VALUE || startup.hStdOutput == INVALID_HANDLE_VALUE) { /* we're not attached to a console, let's do it */ AllocConsole(); startup.hStdInput = CreateFileA("CONIN$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0); startup.hStdOutput = CreateFileA("CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, &sa, OPEN_EXISTING, 0, 0); } /* now verify everything's ok */ ok(startup.hStdInput != INVALID_HANDLE_VALUE, "Opening ConIn"); ok(startup.hStdOutput != INVALID_HANDLE_VALUE, "Opening ConOut"); startup.hStdError = startup.hStdOutput; ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbi), "Getting sb info"); ok(GetConsoleMode(startup.hStdInput, &modeIn) && GetConsoleMode(startup.hStdOutput, &modeOut), "Getting console modes"); cpIn = GetConsoleCP(); cpOut = GetConsoleOutputCP(); get_file_name(resfile); sprintf(buffer, "%s tests/process.c %s console", selfname, resfile); ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, 0, NULL, NULL, &startup, &info), "CreateProcess"); /* wait for child to terminate */ ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination"); /* child process has changed result file, so let profile functions know about it */ WritePrivateProfileStringA(NULL, NULL, NULL, resfile); /* now get the modification the child has made, and resets parents expected values */ ok(GetConsoleScreenBufferInfo(startup.hStdOutput, &sbiC), "Getting sb info"); ok(GetConsoleMode(startup.hStdInput, &modeInC) && GetConsoleMode(startup.hStdOutput, &modeOutC), "Getting console modes"); SetConsoleMode(startup.hStdInput, modeIn); SetConsoleMode(startup.hStdOutput, modeOut); cpInC = GetConsoleCP(); cpOutC = GetConsoleOutputCP(); SetConsoleCP(cpIn); SetConsoleOutputCP(cpOut); okChildInt("StartupInfoA", "cb", startup.cb); okChildString("StartupInfoA", "lpDesktop", startup.lpDesktop); okChildString("StartupInfoA", "lpTitle", startup.lpTitle); okChildInt("StartupInfoA", "dwX", startup.dwX); okChildInt("StartupInfoA", "dwY", startup.dwY); okChildInt("StartupInfoA", "dwXSize", startup.dwXSize); okChildInt("StartupInfoA", "dwYSize", startup.dwYSize); okChildInt("StartupInfoA", "dwXCountChars", startup.dwXCountChars); okChildInt("StartupInfoA", "dwYCountChars", startup.dwYCountChars); okChildInt("StartupInfoA", "dwFillAttribute", startup.dwFillAttribute); okChildInt("StartupInfoA", "dwFlags", startup.dwFlags); okChildInt("StartupInfoA", "wShowWindow", startup.wShowWindow); /* check child correctly inherited the console */ okChildInt("StartupInfoA", "hStdInput", (DWORD)startup.hStdInput); okChildInt("StartupInfoA", "hStdOutput", (DWORD)startup.hStdOutput); okChildInt("StartupInfoA", "hStdError", (DWORD)startup.hStdError); okChildInt("Console", "SizeX", sbi.dwSize.X); okChildInt("Console", "SizeY", sbi.dwSize.Y); okChildInt("Console", "CursorX", sbi.dwCursorPosition.X); okChildInt("Console", "CursorY", sbi.dwCursorPosition.Y); okChildInt("Console", "Attributes", sbi.wAttributes); okChildInt("Console", "winLeft", sbi.srWindow.Left); okChildInt("Console", "winTop", sbi.srWindow.Top); okChildInt("Console", "winRight", sbi.srWindow.Right); okChildInt("Console", "winBottom", sbi.srWindow.Bottom); okChildInt("Console", "maxWinWidth", sbi.dwMaximumWindowSize.X); okChildInt("Console", "maxWinHeight", sbi.dwMaximumWindowSize.Y); okChildInt("Console", "InputCP", cpIn); okChildInt("Console", "OutputCP", cpOut); okChildInt("Console", "InputMode", modeIn); okChildInt("Console", "OutputMode", modeOut); todo_wine ok(cpInC == 1252, "Wrong console CP (expected 1252 got %ld/%ld)", cpInC, cpIn); todo_wine ok(cpOutC == 1252, "Wrong console-SB CP (expected 1252 got %ld/%ld)", cpOutC, cpOut); ok(modeInC == (modeIn ^ 1), "Wrong console mode"); ok(modeOutC == (modeOut ^ 1), "Wrong console-SB mode"); ok(sbiC.dwCursorPosition.X == (sbi.dwCursorPosition.X ^ 1), "Wrong cursor position"); ok(sbiC.dwCursorPosition.Y == (sbi.dwCursorPosition.Y ^ 1), "Wrong cursor position"); release_memory(); assert(DeleteFileA(resfile) != 0); ok(CreatePipe(&hParentIn, &hChildOut, NULL, 0), "Creating parent-input pipe"); ok(DuplicateHandle(GetCurrentProcess(), hChildOut, GetCurrentProcess(), &hChildOutInh, 0, TRUE, DUPLICATE_SAME_ACCESS), "Duplicating as inheritable child-output pipe"); CloseHandle(hChildOut); ok(CreatePipe(&hChildIn, &hParentOut, NULL, 0), "Creating parent-output pipe"); ok(DuplicateHandle(GetCurrentProcess(), hChildIn, GetCurrentProcess(), &hChildInInh, 0, TRUE, DUPLICATE_SAME_ACCESS), "Duplicating as inheritable child-input pipe"); CloseHandle(hChildIn); memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); startup.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES; startup.wShowWindow = SW_SHOWNORMAL; startup.hStdInput = hChildInInh; startup.hStdOutput = hChildOutInh; startup.hStdError = hChildOutInh; get_file_name(resfile); sprintf(buffer, "%s tests/process.c %s stdhandle", selfname, resfile); ok(CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &startup, &info), "CreateProcess"); ok(CloseHandle(hChildInInh), "Closing handle"); ok(CloseHandle(hChildOutInh), "Closing handle"); msg_len = strlen(msg) + 1; ok(WriteFile(hParentOut, msg, msg_len, &w, NULL), "Writting to child"); ok(w == msg_len, "Should have written %u bytes, actually wrote %lu", msg_len, w); memset(buffer, 0, sizeof(buffer)); ok(ReadFile(hParentIn, buffer, sizeof(buffer), &w, NULL), "Reading from child"); ok(strcmp(buffer, msg) == 0, "Should have received '%s'", msg); /* wait for child to terminate */ ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination"); /* child process has changed result file, so let profile functions know about it */ WritePrivateProfileStringA(NULL, NULL, NULL, resfile); okChildString("StdHandle", "msg", msg); release_memory(); assert(DeleteFileA(resfile) != 0);}static void test_ExitCode(void){ char buffer[MAX_PATH]; PROCESS_INFORMATION info; STARTUPINFOA startup; DWORD code; /* let's start simplistic */ memset(&startup, 0, sizeof(startup)); startup.cb = sizeof(startup); startup.dwFlags = STARTF_USESHOWWINDOW; startup.wShowWindow = SW_SHOWNORMAL; get_file_name(resfile); sprintf(buffer, "%s tests/process.c %s exit_code", selfname, resfile); ok(CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info), "CreateProcess"); /* wait for child to terminate */ ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0, "Child process termination"); /* child process has changed result file, so let profile functions know about it */ WritePrivateProfileStringA(NULL, NULL, NULL, resfile); ok(GetExitCodeProcess(info.hProcess, &code), "Getting exit code"); okChildInt("ExitCode", "value", code); release_memory(); assert(DeleteFileA(resfile) != 0);}START_TEST(process){ int b = init(); ok(b, "Basic init of CreateProcess test"); if (!b) return; if (myARGC >= 3) { doChild(myARGV[2], (myARGC == 3) ? NULL : myARGV[3]); return; } test_Startup(); test_CommandLine(); test_Directory(); test_Environment(); test_SuspendFlag(); test_DebuggingFlag(); test_Console(); test_ExitCode(); /* things that can be tested: * lookup: check the way program to be executed is searched * handles: check the handle inheritance stuff (+sec options) * console: check if console creation parameters work */}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?