| OLD | NEW |
| (Empty) |
| 1 // Copyright 2008-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include "omaha/tools/goopdump/process_commandline.h" | |
| 17 | |
| 18 #include "omaha/common/scoped_any.h" | |
| 19 #include "omaha/common/system.h" | |
| 20 #include "omaha/testing/unit_test.h" | |
| 21 | |
| 22 namespace omaha { | |
| 23 | |
| 24 TEST(GoopdumpProcessCommandLineTest, TestRunNotepad) { | |
| 25 // TODO(omaha): Can we use Process::GetCommandLine() instead of | |
| 26 // GetProcessCommandLine? Should be safer than injecting a thread and can | |
| 27 // be used in coverage builds. | |
| 28 #ifdef COVERAGE_ENABLED | |
| 29 std::wcout << _T("\tTest does not run in coverage builds because the ") | |
| 30 << _T("instrumentation of InjectFunction results in references ") | |
| 31 << _T("to invalid memory locations in Notepad.exe.") | |
| 32 << std::endl; | |
| 33 #else | |
| 34 TCHAR notepad_path[MAX_PATH] = {0}; | |
| 35 TCHAR system_directory[MAX_PATH] = {0}; | |
| 36 ::GetSystemDirectory(system_directory, arraysize(system_directory)); | |
| 37 _stprintf_s(notepad_path, | |
| 38 arraysize(notepad_path), | |
| 39 _T("%s\\notepad.exe %s\\loadfix.com"), | |
| 40 system_directory, system_directory); | |
| 41 | |
| 42 PROCESS_INFORMATION pi = {0}; | |
| 43 EXPECT_SUCCEEDED(System::StartProcess(NULL, notepad_path, &pi)); | |
| 44 ::CloseHandle(pi.hThread); | |
| 45 scoped_process process_handle(pi.hProcess); | |
| 46 | |
| 47 CString command_line; | |
| 48 EXPECT_SUCCEEDED(GetProcessCommandLine(pi.dwProcessId, &command_line)); | |
| 49 | |
| 50 ::TerminateProcess(get(process_handle), 0); | |
| 51 | |
| 52 EXPECT_STREQ(notepad_path, command_line); | |
| 53 #endif | |
| 54 } | |
| 55 | |
| 56 } // namespace omaha | |
| 57 | |
| OLD | NEW |