Detlef Riekenberg : kernel32/tests: Add tests for GetProductInfo.

Alexandre Julliard julliard at winehq.org
Thu May 31 13:30:41 CDT 2012


Module: wine
Branch: master
Commit: 64fbf5cac2d1c09e7c4dd25f42c74350f324ab19
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=64fbf5cac2d1c09e7c4dd25f42c74350f324ab19

Author: Detlef Riekenberg <wine.dev at web.de>
Date:   Wed May 30 18:40:34 2012 +0200

kernel32/tests: Add tests for GetProductInfo.

---

 dlls/kernel32/tests/version.c |  100 ++++++++++++++++++++++++++++++++++++++---
 1 files changed, 94 insertions(+), 6 deletions(-)

diff --git a/dlls/kernel32/tests/version.c b/dlls/kernel32/tests/version.c
index 9f9b72e..bb71cf8 100644
--- a/dlls/kernel32/tests/version.c
+++ b/dlls/kernel32/tests/version.c
@@ -18,31 +18,118 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+/* Needed for PRODUCT_* defines and GetProductInfo() */
+#define _WIN32_WINNT 0x0600
+
 #include <assert.h>
 
 #include "wine/test.h"
 #include "winbase.h"
 
+static BOOL (WINAPI * pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, DWORD *);
 static BOOL (WINAPI * pVerifyVersionInfoA)(LPOSVERSIONINFOEXA, DWORD, DWORDLONG);
 static ULONGLONG (WINAPI * pVerSetConditionMask)(ULONGLONG, DWORD, BYTE);
 
 #define KERNEL32_GET_PROC(func)                                     \
-    p##func = (void *)GetProcAddress(hKernel32, #func);             \
-    if(!p##func) trace("GetProcAddress(hKernel32, '%s') failed\n", #func);
+    p##func = (void *)GetProcAddress(hKernel32, #func);
 
 static void init_function_pointers(void)
 {
     HMODULE hKernel32;
 
-    pVerifyVersionInfoA = NULL;
-    pVerSetConditionMask = NULL;
-
     hKernel32 = GetModuleHandleA("kernel32.dll");
-    assert(hKernel32);
+
+    KERNEL32_GET_PROC(GetProductInfo);
     KERNEL32_GET_PROC(VerifyVersionInfoA);
     KERNEL32_GET_PROC(VerSetConditionMask);
 }
 
+#define PRODUCT2NAME(x) case x:\
+                        return #x;
+
+static const char * product_to_name(DWORD product)
+{
+    switch (product)
+    {
+        PRODUCT2NAME(PRODUCT_PROFESSIONAL)
+        PRODUCT2NAME(PRODUCT_STANDARD_SERVER)
+        PRODUCT2NAME(PRODUCT_BUSINESS)
+        PRODUCT2NAME(PRODUCT_ULTIMATE)
+        PRODUCT2NAME(PRODUCT_ULTIMATE_N)
+        PRODUCT2NAME(PRODUCT_HOME_PREMIUM)
+    }
+    return "";
+}
+#undef PRODUCT2NAME
+
+static void test_GetProductInfo(void)
+{
+    OSVERSIONINFOEXA os;
+    DWORD product;
+    DWORD res;
+    DWORD table[] = {9,8,7,6,
+                     7,0,0,0,
+                     6,2,0,0,
+                     6,1,2,0,
+                     6,1,1,0,
+                     6,1,0,2,
+                     6,1,0,0,
+                     6,0,3,0,
+                     6,0,2,0,
+                     6,0,1,5,
+                     6,0,1,0,
+                     6,0,0,0,
+                     5,3,0,0,
+                     5,2,0,0,
+                     5,1,0,0,
+                     5,0,0,0,
+                     0};
+
+    DWORD *entry = table;
+
+    if (!pGetProductInfo)
+    {
+        /* Not present before Vista */
+        win_skip("GetProductInfo() not available\n");
+        return;
+    }
+
+    memset(&os, 0, sizeof(OSVERSIONINFOEXA));
+    os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
+    res = GetVersionExA((OSVERSIONINFOA *)&os);
+    ok(res, "got %d (expected TRUE)\n", res);
+
+    trace("%s %u.%u (SP: %u.%u)\n", os.wProductType == VER_NT_WORKSTATION ? "Workstation" : "Server",
+        os.dwMajorVersion, os.dwMinorVersion, os.wServicePackMajor, os.wServicePackMinor);
+
+    while (*entry)
+    {
+        /* SetLastError() / GetLastError(): value is untouched */
+        product = 0xdeadbeef;
+        SetLastError(0xdeadbeef);
+        res = pGetProductInfo(entry[0], entry[1], entry[2], entry[3], &product);
+        trace("%d.%d / %d.%d: got %d and 0x%x %s\n",
+            entry[0], entry[1], entry[2], entry[3], res, product, product_to_name(product));
+
+        if (entry[0] >= 6)
+            ok(res && (product > PRODUCT_UNDEFINED) && (product <= PRODUCT_EMBEDDED) && (GetLastError() == 0xdeadbeef),
+               "got %d and 0x%x with 0x%x (expected TRUE and a valid PRODUCT_* value  with LastError untouched)\n",
+               res, product, GetLastError());
+        else
+            ok(!res && !product && (GetLastError() == 0xdeadbeef),
+               "got %d and 0x%x with 0x%x (expected FALSE and PRODUCT_UNDEFINED with LastError untouched)\n",
+               res, product, GetLastError());
+
+        entry+= 4;
+    }
+
+    /* NULL pointer is not a problem */
+    SetLastError(0xdeadbeef);
+    res = pGetProductInfo(6, 1, 0, 0, NULL);
+    ok( (!res) && (GetLastError() == 0xdeadbeef),
+        "got %d with 0x%x (expected FALSE with LastError untouched\n", res, GetLastError());
+}
+
 static void test_GetVersionEx(void)
 {
     OSVERSIONINFOA infoA;
@@ -292,6 +379,7 @@ START_TEST(version)
 {
     init_function_pointers();
 
+    test_GetProductInfo();
     test_GetVersionEx();
     test_VerifyVersionInfo();
 }




More information about the wine-cvs mailing list