Index: rostests/apitests/shell32/CDesktopBrowser.cpp =================================================================== --- rostests/apitests/shell32/CDesktopBrowser.cpp (nonexistent) +++ rostests/apitests/shell32/CDesktopBrowser.cpp (working copy) @@ -0,0 +1,234 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory + * PURPOSE: Tests for CDesktopBrowser + * PROGRAMMER: Mark Jansen + */ + +#include "shelltest.h" +#include +#include +#include +#include +#include + +#define NDEBUG +#include +#include + +#define ok_hr(status, expected) ok_hex(status, expected) + +static HWND g_Window; + + +#define ok_notfound(name) \ + do { \ + dwRet = GetEnvironmentVariableA(name, buf, _countof(buf)); \ + dwErr = GetLastError(); \ + ok_hex(dwRet, 0); \ + ok_hex(dwErr, ERROR_ENVVAR_NOT_FOUND); \ + } while (0) + +#define ok_envval(name, expected) \ + do { \ + dwRet = GetEnvironmentVariableA(name, buf, _countof(buf)); \ + ok_hex(dwRet, strlen(expected)); \ + ok_str(buf, expected); \ + } while (0) + +struct CheckVar +{ + CheckVar(const char* name_, bool copy_from_old_env = false) + :name(name_), copy_old(copy_from_old_env) + { + exists = value.GetEnvironmentVariable(name); + CStringA tmp = "New value:"; + tmp += name; + SetEnvironmentVariableA(name, tmp); + } + + void check() + { + CStringA current; + BOOL hasCur = current.GetEnvironmentVariable(name); + ok(hasCur == exists, "Expected hasCur(%i) to equals exists(%i) for %s\n", hasCur, exists, (const char*)name); + if (copy_old) + { + CStringA tmp = "New value:"; + tmp += name; + ok(current == tmp, "Expected current(%s) to equal tmp(%s) for %s\n", (const char*)current, (const char*)tmp, (const char*)name); + } + else + { + ok(current == value, "Expected current(%s) to equal value(%s) for %s\n", (const char*)current, (const char*)value, (const char*)name); + } + } + + CStringA name; + CStringA value; + BOOL exists; + bool copy_old; +}; + + +static void run_tests() +{ + char buf[100]; + DWORD dwRet, dwErr; + + ok_notfound("apitest_var"); + + // Set the variable in the env. + SetEnvironmentVariableA("apitest_var", "some randome value"); + ok_envval("apitest_var", "some randome value"); + + CheckVar all[] = { + CheckVar("ALLUSERSPROFILE", true), + CheckVar("APPDATA"), + CheckVar("COMPUTERNAME"), + CheckVar("HOMEDRIVE"), + CheckVar("HOMEPATH"), + CheckVar("LOCALAPPDATA"), + CheckVar("LOGONSERVER"), + CheckVar("NUMBER_OF_PROCESSORS"), + CheckVar("OS"), + //CheckVar("PATH"), // TODO: expands various paths from SystemRoot + CheckVar("PATHEXT"), + //CheckVar("PROCESSOR_ARCHITECTURE"), bug in WoW64 on windows :) + CheckVar("ProgramData", true), + CheckVar("ProgramFiles"), + CheckVar("SystemDrive", true), + CheckVar("SystemRoot", true), + //CheckVar("TEMP"), // TODO: expands from %USERPROFILE%\AppData\Local\Temp + //CheckVar("TMP"), // TODO: expands from %USERPROFILE%\AppData\Local\Temp + CheckVar("USERDOMAIN"), + CheckVar("USERNAME"), + CheckVar("USERPROFILE"), + //CheckVar("windir"), // TODO: expands from %SystemRoot% + CheckVar("something_else_completely"), + }; + + // Ask CDesktopBrowser to reload the environment + SendMessageW(g_Window, WM_SETTINGCHANGE, NULL, (LPARAM)L"Environment"); + + ok_notfound("apitest_var"); + + for (size_t n = 0; n < _countof(all); ++n) + all[n].check(); +} + +const GUID IID_IShellDesktopTray = { 0x213e2df9, 0x9a14, 0x4328, { 0x99, 0xb1, 0x69, 0x61, 0xf9, 0x14, 0x3c, 0xe9 } }; + +class IShellDesktopTray +{ + /*** IUnknown methods ***/ + STDMETHOD_(HRESULT, QueryInterface) (THIS_ REFIID riid, void** ppvObject) + { + if (riid == IID_IUnknown || riid == IID_IShellDesktopTray) + { + *ppvObject = this; + return S_OK; + } + return E_NOINTERFACE; + } + STDMETHOD_(ULONG, AddRef) (THIS) { return 2; } + STDMETHOD_(ULONG, Release) (THIS) { return 1; } + + /*** IShellDesktopTray ***/ + STDMETHOD_(ULONG,GetState)(THIS) { return 0; } + STDMETHOD(GetTrayWindow)(THIS_ HWND*) { return E_FAIL; } + STDMETHOD(RegisterDesktopWindow)(THIS_ HWND) { return E_FAIL; } + STDMETHOD(Unknown)(THIS_ DWORD,DWORD) { return E_FAIL; } +}; + +static UINT g_TestMessage; + +LRESULT CALLBACK test_SubClassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +{ + if (uMsg == WM_NCDESTROY) + { + RemoveWindowSubclass(hWnd, test_SubClassProc, uIdSubclass); + } + else if (uMsg == g_TestMessage) + { + run_tests(); + PostQuitMessage(0); + } + else if (uMsg == WM_TIMER) + { + if (wParam == 0x1337) + { + ok(0, "Test timed out\n"); + PostQuitMessage(0); + } + } + + return DefSubclassProc(hWnd, uMsg, wParam, lParam); +} + +typedef HANDLE(WINAPI * PSHCREATEDESKTOP)(IShellDesktopTray *ShellDesk); + +struct CCoInit +{ + CCoInit() { hres = CoInitialize(NULL); } + ~CCoInit() { if (SUCCEEDED(hres)) { CoUninitialize(); } } + HRESULT hres; +}; + +START_TEST(CDesktopBrowser) +{ + CCoInit init; + + PSHCREATEDESKTOP SHCreateDesktop = (PSHCREATEDESKTOP) GetProcAddress(LoadLibraryA("shell32.dll"), MAKEINTRESOURCEA(200)); + + IShellDesktopTray tray; + CComPtr browser; + browser.Attach(static_cast(SHCreateDesktop(&tray))); + ok(browser.p != NULL, "Expected an IShellBrowser\n"); + if (!browser.p) + return; + + CComPtr shellView; + HRESULT hr = browser->QueryActiveShellView(&shellView); + ok_hr(hr, S_OK); + if (!SUCCEEDED(hr)) + return; + + hr = browser->GetWindow(&g_Window); + ok_hr(hr, S_OK); + if (!SUCCEEDED(hr)) + return; + + char buf[100]; + GetWindowTextA(g_Window, buf, 100); + ok_str(buf, "Program Manager"); + + RealGetWindowClassA(g_Window, buf, 100); + ok_str(buf, "Progman"); + + DWORD pid; + GetWindowThreadProcessId(g_Window, &pid); + ok(pid == GetCurrentProcessId(), "Expected pid to be 0x%lx, was 0x%lx\n", GetCurrentProcessId(), pid); + + g_TestMessage = RegisterWindowMessageW(L"apitest_cb_msg"); + SetWindowSubclass(g_Window, test_SubClassProc, 1, 0); + + // kick off the test loop + PostMessage(g_Window, g_TestMessage, 0, 0); + // watchdog + SetTimer(g_Window, 0x1337, 20 * 1000, NULL); + + MSG Msg; + BOOL bRet; + while ((bRet = GetMessageW(&Msg, NULL, 0, 0)) != 0) + { + if (bRet != -1) + { + if (shellView->TranslateAccelerator(&Msg) != S_OK) + { + TranslateMessage(&Msg); + DispatchMessage(&Msg); + } + } + } +} Index: rostests/apitests/shell32/CMakeLists.txt =================================================================== --- rostests/apitests/shell32/CMakeLists.txt (revision 73453) +++ rostests/apitests/shell32/CMakeLists.txt (working copy) @@ -1,9 +1,10 @@ -set_cpp(WITH_RUNTIME) +set_cpp(WITH_RUNTIME WITH_EXCEPTIONS) include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/atl) add_executable(shell32_apitest + CDesktopBrowser.cpp CFSFolder.cpp CMyComputer.cpp CShellDesktop.cpp @@ -15,5 +16,5 @@ testlist.c) target_link_libraries(shell32_apitest wine uuid ${PSEH_LIB}) set_module_type(shell32_apitest win32cui) -add_importlibs(shell32_apitest user32 gdi32 shell32 ole32 oleaut32 advapi32 shlwapi msvcrt kernel32 ntdll) +add_importlibs(shell32_apitest user32 gdi32 shell32 ole32 oleaut32 comctl32 advapi32 shlwapi msvcrt kernel32 ntdll) add_cd_file(TARGET shell32_apitest DESTINATION reactos/bin FOR all) Index: rostests/apitests/shell32/testlist.c =================================================================== --- rostests/apitests/shell32/testlist.c (revision 73453) +++ rostests/apitests/shell32/testlist.c (working copy) @@ -1,8 +1,10 @@ #define __ROS_LONG64__ #define STANDALONE +#include #include +extern void func_CDesktopBrowser(void); extern void func_CFSFolder(void); extern void func_CMyComputer(void); extern void func_CShellDesktop(void); @@ -13,6 +15,7 @@ const struct test winetest_testlist[] = { + { "CDesktopBrowser", func_CDesktopBrowser }, { "CFSFolder", func_CFSFolder }, { "CMyComputer", func_CMyComputer }, { "CShellDesktop", func_CShellDesktop },