Changes: Now everything follows code rules. The test runs on every windows version. Is prepared for continue making more tests in it.
Signed-off-by: Carlos Vega García carlosvegagc@gmail.com --- programs/explorer/tests/explorer.c | 166 +++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 programs/explorer/tests/explorer.c
diff --git a/programs/explorer/tests/explorer.c b/programs/explorer/tests/explorer.c new file mode 100644 index 0000000..857589d --- /dev/null +++ b/programs/explorer/tests/explorer.c @@ -0,0 +1,166 @@ +/* + * Unit tests for explorer.exe + * + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "dde.h" +#include "ddeml.h" +#include "shlobj.h" +#include "wine/test.h" +#include "winuser.h" +#include <stdio.h> +#include <winbase.h> + +/* We test the explorer.exe. This will be the base for start making other tests + * for future + * funtionalities for the explorer (drag&drop). + * + * Tests already implemented: + * - BOOL explorer_available() + */ + +static BOOL use_common(void) +{ + HMODULE hmod; + static BOOL(WINAPI * pIsNTAdmin)(DWORD, LPDWORD); + + /* IsNTAdmin() is available on all platforms. */ + hmod = LoadLibraryA("advpack.dll"); + pIsNTAdmin = (void *)GetProcAddress(hmod, "IsNTAdmin"); + + if (!pIsNTAdmin(0, NULL)) + { + /* We are definitely not an administrator */ + FreeLibrary(hmod); + return FALSE; + } + FreeLibrary(hmod); + + return TRUE; +} + +static BOOL full_title(void) +{ + CABINETSTATE cs; + + memset(&cs, 0, sizeof(cs)); + ReadCabinetState(&cs, sizeof(cs)); + + return (cs.fFullPathTitle == -1); +} + +static char ProgramsDir[MAX_PATH]; +static void init_strings(void) +{ + char commonprograms[MAX_PATH]; + char programs[MAX_PATH]; + + SHGetSpecialFolderPathA(NULL, programs, CSIDL_PROGRAMS, FALSE); + SHGetSpecialFolderPathA(NULL, commonprograms, CSIDL_COMMON_PROGRAMS, FALSE); + + /* ProgramsDir on Vista+ is always the users one (CSIDL_PROGRAMS). Before + * Vista + * it depends on whether the user is an administrator (CSIDL_COMMON_PROGRAMS) + * or + * not (CSIDL_PROGRAMS). + */ + + if (use_common()) + lstrcpyA(ProgramsDir, commonprograms); + else + lstrcpyA(ProgramsDir, programs); +} + +static BOOL check_window_exists(const char *name) +{ + char title[MAX_PATH]; + HWND window = NULL; + int i; + + if (full_title()) + { + strcpy(title, ProgramsDir); + strcat(title, "\"); + strcat(title, name); + } + else + + strcpy(title, name); + trace("\n \n Window name: %s \n \n", name); + + /* In the next lines we want to ceck if te specified windows has created. We + * don't know exactly how long it will + * take to open the window so we use a loop and sleep function to wait until + * the window opens. + */ + for (i = 0; i < 20; i++) + { + Sleep(20 + 20 * i); + if ((window = FindWindowA("ExplorerWClass", title)) + || (window = FindWindowA("CabinetWClass", title))) + { + SendMessageA(window, WM_SYSCOMMAND, SC_CLOSE, 0); + break; + } + } + + return (window != NULL); +} + +/* +*We make a call to open a new explorer window and we test if it finally opens. +*/ +BOOL explorer_available(void) +{ + STARTUPINFOA si; + PROCESS_INFORMATION pi; + + char cmd[] = {'e', 'x', 'p', 'l', 'o', 'r', 'e', 'r', ' ', 'C', + ':', 92, 'w', 'i', 'n', 'd', 'o', 'w', 's', 0}; + /*I use the character 92 = '' because if you write the character the gcc + * compiler misunderstand it*/ + char windowName[] = {'w', 'i', 'n', 'd', 'o', 'w', 's', 0}; + + memset(&si, 0, sizeof(si)); + si.cb = sizeof(si); + CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); + + /*Checks if the window has been created*/ + if (check_window_exists(windowName)) + { + return TRUE; + } + return FALSE; +} + +START_TEST(explorer) +{ + BOOL is_explorer_available; + + /*First we initialize and get th Programs Directoy*/ + init_strings(); + + /*We get if the explorer is avaible and correctcly opens, the we save it into a varible*/ + is_explorer_available = explorer_available(); + + ok(is_explorer_available == TRUE, "No explorer window has opened \n"); + if (!is_explorer_available) + { + win_skip("Explorer.exe is not available \n"); + } +}
Hi,
While running your changed tests on Windows, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? Full results can be found at https://testbot.winehq.org/JobDetails.pl?Key=37104
Your paranoid android.
=== build (build) === Recreation of tests/Makefile failed