[SHELL32_APITEST] -Add some tests for SHParseDisplayName for CORE-12882.
[reactos.git] / rostests / apitests / apphelp / apphelp.c
index d498d29..6bfd978 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2012 Detlef Riekenberg
  * Copyright 2013 Mislav Blažević
- * Copyright 2016 Mark Jansen
+ * Copyright 2015,2016 Mark Jansen
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 #include <winerror.h>
 #include <stdio.h>
 #include <initguid.h>
+#include <shlguid.h>
+#include <shobjidl.h>
 
 #include "wine/test.h"
 
-/* data.c */
-void test_create_exe_imp(const char* name, int skip_rsrc_exports);
-void test_create_file_imp(const char* name, const char* contents, size_t len);
-void test_create_ne_imp(const char* name, int skip_names);
-DWORD get_host_winver();
-
-#define test_create_exe     (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : test_create_exe_imp
-#define test_create_file    (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : test_create_file_imp
-#define test_create_ne      (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : test_create_ne_imp
-
-
-static DWORD g_WinVersion;
-
-#define WINVER_ANY     0
-#define WINVER_WINXP   0x0501
-#define WINVER_2003    0x0502
-#define WINVER_VISTA   0x0600
-#define WINVER_WIN7    0x0601
-#define WINVER_WIN8    0x0602
-#define WINVER_WIN10   0x1000
+#include "apphelp_apitest.h"
 
 
 typedef WORD TAG;
@@ -120,6 +103,7 @@ typedef struct tagATTRINFO {
 } ATTRINFO, *PATTRINFO;
 
 static HMODULE hdll;
+static BOOL (WINAPI *pApphelpCheckShellObject)(REFCLSID, BOOL, ULONGLONG *);
 static LPCWSTR (WINAPI *pSdbTagToString)(TAG);
 static BOOL (WINAPI *pSdbGUIDToString)(CONST GUID *, PCWSTR, SIZE_T);
 static BOOL (WINAPI *pSdbIsNullGUID)(CONST GUID *);
@@ -131,10 +115,67 @@ static BOOL (WINAPI *pSdbFreeFileAttributes)(PATTRINFO);
 DEFINE_GUID(GUID_DATABASE_MSI,0xd8ff6d16,0x6a3a,0x468a,0x8b,0x44,0x01,0x71,0x4d,0xdc,0x49,0xea);
 DEFINE_GUID(GUID_DATABASE_SHIM,0x11111111,0x1111,0x1111,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11);
 DEFINE_GUID(GUID_DATABASE_DRIVERS,0xf9ab2228,0x3312,0x4a73,0xb6,0xf9,0x93,0x6d,0x70,0xe1,0x12,0xef);
-DEFINE_GUID(GUID_DATABASE_TEST,0x6E989AB7,0x864D,0x4575,0x87,0x34,0x90,0x36,0x4A,0xC6,0x4F,0xBD);
 
 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
+
+DEFINE_GUID(test_Microsoft_Browser_Architecture, 0xa5e46e3a, 0x8849, 0x11d1, 0x9d, 0x8c, 0x00, 0xc0, 0x4f, 0xc9, 0x9d, 0x61);
 DEFINE_GUID(test_UserAssist, 0xdd313e04, 0xfeff, 0x11d1, 0x8e, 0xcd, 0x00, 0x00, 0xf8, 0x7a, 0x47, 0x0c);
+DEFINE_GUID(CLSID_InternetSecurityManager, 0x7b8a2d94, 0x0ac9, 0x11d1, 0x89, 0x6c, 0x00, 0xc0, 0x4f, 0xB6, 0xbf, 0xc4);
+
+static const CLSID * objects[] = {
+    &GUID_NULL,
+    /* used by IE */
+    &test_Microsoft_Browser_Architecture,
+    &CLSID_MenuBand,
+    &CLSID_ShellLink,
+    &CLSID_ShellWindows,
+    &CLSID_InternetSecurityManager,
+    &test_UserAssist,
+    (const CLSID *)NULL
+};
+
+static void test_ApphelpCheckShellObject(void)
+{
+    ULONGLONG flags;
+    BOOL res;
+    int i;
+
+    if (!pApphelpCheckShellObject)
+    {
+        win_skip("ApphelpCheckShellObject not available\n");
+        return;
+    }
+
+    for (i = 0; objects[i]; i++)
+    {
+        flags = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = pApphelpCheckShellObject(objects[i], FALSE, &flags);
+        ok(res && (flags == 0), "%s 0: got %d and 0x%x%08x with 0x%x (expected TRUE and 0)\n",
+            wine_dbgstr_guid(objects[i]), res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError());
+
+        flags = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = pApphelpCheckShellObject(objects[i], TRUE, &flags);
+        ok(res && (flags == 0), "%s 1: got %d and 0x%x%08x with 0x%x (expected TRUE and 0)\n",
+            wine_dbgstr_guid(objects[i]), res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError());
+
+    }
+
+    /* NULL as pointer to flags is checked */
+    SetLastError(0xdeadbeef);
+    res = pApphelpCheckShellObject(&GUID_NULL, FALSE, NULL);
+    ok(res, "%s 0: got %d with 0x%x (expected != FALSE)\n", wine_dbgstr_guid(&GUID_NULL), res, GetLastError());
+
+    /* NULL as CLSID* crash on Windows */
+    if (0)
+    {
+        flags = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = pApphelpCheckShellObject(NULL, FALSE, &flags);
+        trace("NULL as CLSID*: got %d and 0x%x%08x with 0x%x\n", res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError());
+    }
+}
 
 static void test_SdbTagToString(void)
 {
@@ -849,9 +890,13 @@ START_TEST(apphelp)
 {
     g_WinVersion = get_host_winver();
     trace("Detected version: 0x%x\n", g_WinVersion);
+    silence_debug_output();
+
     //SetEnvironmentVariable("SHIM_DEBUG_LEVEL", "4");
     //SetEnvironmentVariable("DEBUGCHANNEL", "+apphelp");
     hdll = LoadLibraryA("apphelp.dll");
+
+    pApphelpCheckShellObject = (void *) GetProcAddress(hdll, "ApphelpCheckShellObject");
     pSdbTagToString = (void *) GetProcAddress(hdll, "SdbTagToString");
     pSdbGUIDToString = (void *) GetProcAddress(hdll, "SdbGUIDToString");
     pSdbIsNullGUID = (void *) GetProcAddress(hdll, "SdbIsNullGUID");
@@ -859,6 +904,7 @@ START_TEST(apphelp)
     pSdbGetFileAttributes = (void *) GetProcAddress(hdll, "SdbGetFileAttributes");
     pSdbFreeFileAttributes = (void *) GetProcAddress(hdll, "SdbFreeFileAttributes");
 
+    test_ApphelpCheckShellObject();
     test_GuidFunctions();
     test_ApplicationAttributes();
     test_SdbTagToString();