[APPHELP][APPHELP_APITEST] Add some apphelp GUID helper functions + tests to be used...
authorMark Jansen <mark.jansen@reactos.org>
Sun, 1 May 2016 21:43:30 +0000 (21:43 +0000)
committerMark Jansen <mark.jansen@reactos.org>
Sun, 1 May 2016 21:43:30 +0000 (21:43 +0000)
- SdbGetStandardDatabaseGUID
- SdbGUIDFromString
- SdbGUIDToString
- SdbIsNullGUID

svn path=/trunk/; revision=71230

reactos/dll/appcompat/apphelp/apphelp.h
reactos/dll/appcompat/apphelp/apphelp.spec
reactos/dll/appcompat/apphelp/sdbapi.c
rostests/apitests/apphelp/apphelp.c

index a0eda94..f9f2500 100644 (file)
@@ -32,6 +32,11 @@ typedef UINT64 QWORD;
 #define TAGREF_NULL (0)
 #define TAGREF_ROOT (0)
 
+#define HID_DATABASE_TYPE_MASK 0xF00F0000
+#define SDB_DATABASE_MAIN_MSI 0x80020000
+#define SDB_DATABASE_MAIN_SHIM 0x80030000
+#define SDB_DATABASE_MAIN_DRIVERS 0x80040000
+
 typedef struct tagATTRINFO {
   TAG   type;
   DWORD flags;
index 5323c9b..fe00e30 100644 (file)
 @ stdcall SdbGetPermLayerKeys(wstr wstr ptr long)
 @ stub SdbGetShowDebugInfoOption
 @ stub SdbGetShowDebugInfoOptionValue
-@ stub SdbGetStandardDatabaseGUID
+@ stdcall SdbGetStandardDatabaseGUID(long ptr)
 @ stub SdbGetStringTagPtr
 @ stub SdbGetTagDataSize
 @ stub SdbGetTagFromTagID
 @ stub SdbGrabMatchingInfo
 @ stub SdbGrabMatchingInfoEx
-@ stub SdbGUIDFromString
-@ stub SdbGUIDToString
+@ stdcall SdbGUIDFromString(wstr ptr)
+@ stdcall SdbGUIDToString(ptr wstr long)
 @ stub SdbInitDatabase
 @ stub SdbInitDatabaseEx
-@ stub SdbIsNullGUID
+@ stdcall SdbIsNullGUID(ptr)
 @ stub SdbIsStandardDatabase
 @ stub SdbIsTagrefFromLocalDB
 @ stub SdbIsTagrefFromMainDB
index fc6f2e3..17224e2 100644 (file)
 #include "wine/unicode.h"
 
 
+static const GUID GUID_DATABASE_MSI = {0xd8ff6d16,0x6a3a,0x468a, {0x8b,0x44,0x01,0x71,0x4d,0xdc,0x49,0xea}};
+static const GUID GUID_DATABASE_SHIM = {0x11111111,0x1111,0x1111, {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}};
+static const GUID GUID_DATABASE_DRIVERS = {0xf9ab2228,0x3312,0x4a73, {0xb6,0xf9,0x93,0x6d,0x70,0xe1,0x12,0xef}};
+
 static HANDLE SdbpHeap(void);
 
 #if SDBAPI_DEBUG_ALLOC
@@ -286,6 +290,88 @@ void WINAPI SdbpCloseMemMappedFile(PMEMMAPPED mapping)
     RtlZeroMemory(mapping, sizeof(*mapping));
 }
 
+/**
+ * Parses a string to retrieve a GUID.
+ *
+ * @param [in]  GuidString  The string to parse.
+ * @param [out] Guid        The resulting GUID.
+ *
+ * @return  TRUE if it succeeds, FALSE if it fails.
+ */
+BOOL WINAPI SdbGUIDFromString(PCWSTR GuidString, GUID *Guid)
+{
+    UNICODE_STRING GuidString_u;
+    RtlInitUnicodeString(&GuidString_u, GuidString);
+    return NT_SUCCESS(RtlGUIDFromString(&GuidString_u, Guid));
+}
+
+/**
+ * Converts a GUID to a string.
+ *
+ * @param [in]  Guid        The GUID to convert.
+ * @param [out] GuidString  The resulting string representation of Guid.
+ * @param [in]  Length      The length of GuidString.
+ *
+ * @return  TRUE if it succeeds, FALSE if it fails.
+ */
+BOOL WINAPI SdbGUIDToString(CONST GUID *Guid, PWSTR GuidString, SIZE_T Length)
+{
+    UNICODE_STRING GuidString_u;
+    if(NT_SUCCESS(RtlStringFromGUID(Guid, &GuidString_u)))
+    {
+        HRESULT hr = StringCchCopyNW(GuidString, Length, GuidString_u.Buffer, GuidString_u.Length / 2);
+        RtlFreeUnicodeString(&GuidString_u);
+        return SUCCEEDED(hr);
+    }
+    return FALSE;
+}
+
+/**
+ * Checks if the specified GUID is a NULL GUID
+ *
+ * @param [in]  Guid    The GUID to check.
+ *
+ * @return  TRUE if it is a NULL GUID.
+ */
+BOOL WINAPI SdbIsNullGUID(CONST GUID *Guid)
+{
+    static GUID NullGuid = { 0 };
+    return !Guid || IsEqualGUID(&NullGuid, Guid);
+}
+
+/**
+ * Get the GUID from one of the standard databases.
+ *
+ * @param [in]  Flags   The ID to retrieve the guid from. (See SDB_DATABASE_MAIN_[xxx])
+ * @param [out] Guid    The resulting GUID.
+ *
+ * @return  TRUE if a known database ID.
+ */
+BOOL WINAPI SdbGetStandardDatabaseGUID(DWORD Flags, GUID* Guid)
+{
+    const GUID* copy_from = NULL;
+    switch(Flags & HID_DATABASE_TYPE_MASK)
+    {
+    case SDB_DATABASE_MAIN_MSI:
+        copy_from = &GUID_DATABASE_MSI;
+        break;
+    case SDB_DATABASE_MAIN_SHIM:
+        copy_from = &GUID_DATABASE_SHIM;
+        break;
+    case SDB_DATABASE_MAIN_DRIVERS:
+        copy_from = &GUID_DATABASE_DRIVERS;
+        break;
+    default:
+        SHIM_ERR("Cannot obtain database guid for databases other than main\n");
+        return FALSE;
+    }
+    if(Guid)
+    {
+        memcpy(Guid, copy_from, sizeof(GUID));
+    }
+    return TRUE;
+}
+
 /**
  * Converts specified tag into a string.
  *
index f065ba8..0718f37 100644 (file)
@@ -32,6 +32,7 @@
 
 #include <winerror.h>
 #include <stdio.h>
+#include <initguid.h>
 
 #include "wine/test.h"
 
@@ -119,9 +120,21 @@ typedef struct tagATTRINFO {
 
 static HMODULE hdll;
 static LPCWSTR (WINAPI *pSdbTagToString)(TAG);
+static BOOL (WINAPI *pSdbGUIDToString)(CONST GUID *, PCWSTR, SIZE_T);
+static BOOL (WINAPI *pSdbIsNullGUID)(CONST GUID *);
+static BOOL (WINAPI *pSdbGetStandardDatabaseGUID)(DWORD, GUID*);
 static BOOL (WINAPI *pSdbGetFileAttributes)(LPCWSTR, PATTRINFO *, LPDWORD);
 static BOOL (WINAPI *pSdbFreeFileAttributes)(PATTRINFO);
 
+/* 'Known' database guids */
+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_UserAssist, 0xdd313e04, 0xfeff, 0x11d1, 0x8e, 0xcd, 0x00, 0x00, 0xf8, 0x7a, 0x47, 0x0c);
+
 static void test_SdbTagToString(void)
 {
     static const TAG invalid_values[] = {
@@ -425,6 +438,32 @@ static void test_SdbTagToStringAllTags(void)
     }
 }
 
+static void test_GuidFunctions(void)
+{
+    GUID guid;
+    ok(pSdbIsNullGUID(&GUID_NULL), "expected GUID_NULL to be recognized as NULL GUID\n");
+    ok(pSdbIsNullGUID(NULL), "expected NULL to be recognized as NULL GUID\n");
+    ok(pSdbIsNullGUID(&test_UserAssist) == 0, "expected a set GUID not to be recognized as NULL GUID\n");
+
+    memset(&guid, 0, sizeof(guid));
+    ok(pSdbGetStandardDatabaseGUID(0, &guid) == 0,"Expected SdbGetStandardDatabaseGUID to fail\n");
+    ok(IsEqualGUID(&GUID_NULL, &guid), "Expected guid not to be changed\n");
+
+    ok(pSdbGetStandardDatabaseGUID(0x80020000, NULL),"Expected SdbGetStandardDatabaseGUID to succeed\n");
+
+    memset(&guid, 0, sizeof(guid));
+    ok(pSdbGetStandardDatabaseGUID(0x80020000, &guid),"Expected SdbGetStandardDatabaseGUID to succeed\n");
+    ok(IsEqualGUID(&GUID_DATABASE_MSI, &guid), "Expected guid to equal GUID_DATABASE_MSI, was: %s\n", wine_dbgstr_guid(&guid));
+
+    memset(&guid, 0, sizeof(guid));
+    ok(pSdbGetStandardDatabaseGUID(0x80030000, &guid),"Expected SdbGetStandardDatabaseGUID to succeed\n");
+    ok(IsEqualGUID(&GUID_DATABASE_SHIM, &guid), "Expected guid to equal GUID_DATABASE_SHIM, was: %s\n", wine_dbgstr_guid(&guid));
+
+    memset(&guid, 0, sizeof(guid));
+    ok(pSdbGetStandardDatabaseGUID(0x80040000, &guid),"Expected SdbGetStandardDatabaseGUID to succeed\n");
+    ok(IsEqualGUID(&GUID_DATABASE_DRIVERS, &guid), "Expected guid to equal GUID_DATABASE_DRIVERS, was: %s\n", wine_dbgstr_guid(&guid));
+}
+
 static void expect_tag_skip_imp(PATTRINFO pattr, DWORD num)
 {
     PATTRINFO p = &pattr[num];
@@ -820,9 +859,13 @@ START_TEST(apphelp)
     //SetEnvironmentVariable("DEBUGCHANNEL", "+apphelp");
     hdll = LoadLibraryA("apphelp.dll");
     pSdbTagToString = (void *) GetProcAddress(hdll, "SdbTagToString");
+    pSdbGUIDToString = (void *) GetProcAddress(hdll, "SdbGUIDToString");
+    pSdbIsNullGUID = (void *) GetProcAddress(hdll, "SdbIsNullGUID");
+    pSdbGetStandardDatabaseGUID = (void *) GetProcAddress(hdll, "SdbGetStandardDatabaseGUID");
     pSdbGetFileAttributes = (void *) GetProcAddress(hdll, "SdbGetFileAttributes");
     pSdbFreeFileAttributes = (void *) GetProcAddress(hdll, "SdbFreeFileAttributes");
 
+    test_GuidFunctions();
     test_ApplicationAttributes();
     test_SdbTagToString();
 #ifdef __REACTOS__