void UpdaterTest::testSendingUpdateMessageToBumpTop() { // start up an instance of bumptop STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); #ifdef DEBUG path bumptopDirPath = current_path().branch_path() / path("Source/Debug", native); #else path bumptopDirPath = current_path().branch_path() / path("Source/Release", native); #endif path bumptopPath = bumptopDirPath / path("BumpTop.exe"); // Start the child process. if( !CreateProcess( NULL, // No module name (use command line) (LPSTR) bumptopPath.native_file_string().c_str(), // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block (LPSTR) bumptopDirPath.native_directory_string().c_str(), // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Pointer to PROCESS_INFORMATION structure ) { ostringstream error_message; error_message << "CreateProcess failed (" << GetLastError() << ")\n"; CPPUNIT_ASSERT_MESSAGE(error_message.str(), false); } Sleep(500); // Search for BumpTop window bool foundBumptopWindow = false; HWND bumptopHwnd = 0; for (int i = 0; i < 50; i++) { CWindowIterator cwi(1000); for (HWND hwnd = cwi.First(); hwnd; hwnd=cwi.Next()) { if ((GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE)) { DWORD pidwin; GetWindowThreadProcessId(hwnd, &pidwin); TCHAR classnameBuffer[MAX_PATH+1]; GetClassName(hwnd, classnameBuffer, MAX_PATH); TCHAR titleBuffer[MAX_PATH+1]; GetWindowText(hwnd, titleBuffer, MAX_PATH); if (pidwin==pi.dwProcessId && string(classnameBuffer) == string("BumpTop") && string(titleBuffer) == string("BumpTop")) { foundBumptopWindow = true; bumptopHwnd = hwnd; break; } } } if (foundBumptopWindow) break; Sleep(100); // give the window a little time to start } CPPUNIT_ASSERT_MESSAGE("Testing if we found the BumpTop window", foundBumptopWindow); Sleep(500); vector<string> versionStrings; versionStrings.push_back("800"); MockUpdateServer *mus = new MockUpdateServer(versionStrings); Updater *u = new Updater(mus, 99, ".", 0, 0, bumptopHwnd); int updateDownloadedMessageResponse = u->sendUpdateDownloadedMessageToBumpTop(true); SendMessageTimeout(bumptopHwnd, WM_CLOSE, 0, 0, SMTO_NORMAL, 1000, NULL); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); CPPUNIT_ASSERT_EQUAL(3, updateDownloadedMessageResponse); }