[PATCH] explorer.c: Test for explorer.exe (try 3)

Carlos Vega García carlosvegagc at gmail.com
Sat Mar 24 00:15:52 CDT 2018


Signed-off-by: Carlos Vega García <carlosvegagc at gmail.com>

Makefile.in: Makefile for explorer.exe tests (try 3)

Signed-off-by: Carlos Vega García <carlosvegagc at gmail.com>

Makefile.in: Makefile for explorer.exe tests (try 3)

Signed-off-by: Carlos Vega García <carlosvegagc at gmail.com>
---
 programs/explorer/tests/Makefile.in |   6 ++
 programs/explorer/tests/explorer.c  | 180 ++++++++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+)
 create mode 100755 programs/explorer/tests/Makefile.in
 create mode 100644 programs/explorer/tests/explorer.c

diff --git a/programs/explorer/tests/Makefile.in b/programs/explorer/tests/Makefile.in
new file mode 100755
index 0000000..041549a
--- /dev/null
+++ b/programs/explorer/tests/Makefile.in
@@ -0,0 +1,6 @@
+TESTDLL   = explorer.exe
+IMPORTS   = shell32 ole32 oleaut32 user32 gdi32 advapi32 shlwapi
+
+C_SRCS = \
+	explorer.c 
+
diff --git a/programs/explorer/tests/explorer.c b/programs/explorer/tests/explorer.c
new file mode 100644
index 0000000..d195486
--- /dev/null
+++ b/programs/explorer/tests/explorer.c
@@ -0,0 +1,180 @@
+/*
+ * 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 < 10; 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.
+*I test two window name because in some Windows versions when I open the explorer it creates
+*the window with another header.
+*/
+BOOL explorer_available(void)
+{
+    STARTUPINFOA si;
+    PROCESS_INFORMATION pi;
+    BOOL is_window_created;
+
+    char cmd[] = {'e', 'x', 'p', 'l', 'o', 'r', 'e', 'r', ' ', 'C',
+                  ':', 92,  'w', 'i', 'n', 'd', 'o', 'w', 's', 0};
+    char window_name[] = {'w', 'i', 'n', 'd', 'o', 'w', 's', 0};
+    char window_name_alternative[] = {'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*/
+
+    memset(&si, 0, sizeof(si));
+    si.cb = sizeof(si);
+    CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
+
+    is_window_created = check_window_exists(window_name);
+
+    /*Checks if the window has been created*/
+    if (is_window_created)
+    {
+        return TRUE;
+    }
+
+    /*If the first window has not been detected it checks with the alterntive name*/
+    if (!is_window_created)
+    {
+	if(check_window_exists(window_name_alternative)){
+            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");
+    }
+}
-- 
2.7.4




More information about the wine-devel mailing list