[PATCH v3 2/2] propsys/tests: Add VariantToStringWithDefault tests.

Mohamad Al-Jaf mohamadaljaf at gmail.com
Mon Mar 28 14:31:00 CDT 2022


Signed-off-by: Mohamad Al-Jaf <mohamadaljaf at gmail.com>
---
v2: - Add some more tests to see what variants are supported.
    - Test for BYREF.
    - Test nested BSTR and BYREF.

v3: - Add test for NULL default_value (Thanks Nikolay).
    - Test returned pointer value with BSTR.

I tested the other unsupported variants listed here for
NULL default_value and they all return NULL. It seems
unnecessary to add it to every variant type.

--

I added a nested nested VARIANT test and it showed that Windows
returns the default value. However, it causes propsys to crash
in 64-bit tests, namely propsys_test64.exe.

How do I compile 64-bit tests like propsys_test64.exe? It's
different from propsys_test.exe in the 64-build of Wine.
---
 dlls/propsys/tests/propsys.c | 183 +++++++++++++++++++++++++++++++++++
 1 file changed, 183 insertions(+)

diff --git a/dlls/propsys/tests/propsys.c b/dlls/propsys/tests/propsys.c
index 124b3405bcb..bb1788bd897 100644
--- a/dlls/propsys/tests/propsys.c
+++ b/dlls/propsys/tests/propsys.c
@@ -2064,6 +2064,188 @@ static void test_InitVariantFromFileTime(void)
     ok(V_DATE(&var) == d, "got wrong value: %f, expected %f\n", V_DATE(&var), d);
 }
 
+static void test_VariantToStringWithDefault(void)
+{
+    static WCHAR default_value[] = {'t', 'e', 's', 't', '\0'};
+    static WCHAR wstr_test[] =  {'t', 'e', 's', 't', '1', '\0'};
+    static WCHAR wstr_empty[] = {'\0'};
+    static WCHAR wstr_space[] = {' ', '\0'};
+    PCWSTR result;
+    VARIANT var, nes;
+    BSTR b;
+
+    V_VT(&var) = VT_EMPTY;
+    result = VariantToStringWithDefault(&var, NULL);
+    ok(result == NULL, "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_EMPTY;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_NULL;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_BOOL;
+    V_BOOL(&var) = VARIANT_TRUE;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_CY;
+    V_CY(&var).int64 = 100000;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_DATE;
+    V_DATE(&var) = 42.0;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_BYREF;
+    V_BYREF(&var) = &wstr_test;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_ERROR;
+    V_ERROR(&var) = DISP_E_PARAMNOTFOUND;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_I4;
+    V_I4(&var) = 15;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_I1;
+    V_I1(&var) = 't';
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == default_value, "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    /* V_BSTR */
+
+    V_VT(&var) = VT_BSTR;
+    V_BSTR(&var) = NULL;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_BSTR;
+    V_BSTR(&var) = SysAllocString(wstr_empty);
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == V_BSTR(&var), "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(V_BSTR(&var));
+
+    V_VT(&var) = VT_BSTR;
+    V_BSTR(&var) = SysAllocString(wstr_space);
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == V_BSTR(&var), "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(V_BSTR(&var));
+
+    V_VT(&var) = VT_BSTR;
+    V_BSTR(&var) = SysAllocString(wstr_test);
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == V_BSTR(&var), "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(V_BSTR(&var));
+
+    /* V_BSTRREF */
+
+    V_VT(&var) = VT_BYREF | VT_BSTR;
+    b = NULL;
+    V_BSTRREF(&var) = &b;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_BYREF | VT_BSTR;
+    b = SysAllocString(wstr_empty);
+    V_BSTRREF(&var) = &b;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(b);
+
+    V_VT(&var) = VT_BYREF | VT_BSTR;
+    b = SysAllocString(wstr_space);
+    V_BSTRREF(&var) = &b;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(b);
+
+    V_VT(&var) = VT_BYREF | VT_BSTR;
+    b = SysAllocString(wstr_test);
+    V_BSTRREF(&var) = &b;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(b);
+
+    /* Nested V_BSTR */
+
+    V_VT(&var) = VT_BYREF | VT_VARIANT;
+    V_VT(&nes) = VT_BSTR;
+    V_BSTR(&nes) = NULL;
+    V_VARIANTREF(&var) = &nes;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_BYREF | VT_VARIANT;
+    V_VT(&nes) = VT_BSTR;
+    V_BSTR(&nes) = SysAllocString(wstr_empty);
+    V_VARIANTREF(&var) = &nes;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == V_BSTR(&nes), "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(V_BSTR(&nes));
+
+    V_VT(&var) = VT_BYREF | VT_VARIANT;
+    V_VT(&nes) = VT_BSTR;
+    V_BSTR(&nes) = SysAllocString(wstr_space);
+    V_VARIANTREF(&var) = &nes;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == V_BSTR(&nes), "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(V_BSTR(&nes));
+
+    V_VT(&var) = VT_BYREF | VT_VARIANT;
+    V_VT(&nes) = VT_BSTR;
+    V_BSTR(&nes) = SysAllocString(wstr_test);
+    V_VARIANTREF(&var) = &nes;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == V_BSTR(&nes), "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(V_BSTR(&nes));
+
+    /* Nested V_BSTRREF */
+
+    V_VT(&var) = VT_BYREF | VT_VARIANT;
+    V_VT(&nes) = VT_BYREF | VT_BSTR;
+    b = NULL;
+    V_BSTRREF(&nes) = &b;
+    V_VARIANTREF(&var) = &nes;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result[0] == '\0', "Unexpected value %s\n", wine_dbgstr_w(result));
+
+    V_VT(&var) = VT_BYREF | VT_VARIANT;
+    V_VT(&nes) = VT_BYREF | VT_BSTR;
+    b = SysAllocString(wstr_empty);
+    V_BSTRREF(&nes) = &b;
+    V_VARIANTREF(&var) = &nes;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(b);
+
+    V_VT(&var) = VT_BYREF | VT_VARIANT;
+    V_VT(&nes) = VT_BYREF | VT_BSTR;
+    b = SysAllocString(wstr_space);
+    V_BSTRREF(&nes) = &b;
+    V_VARIANTREF(&var) = &nes;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(b);
+
+    V_VT(&var) = VT_BYREF | VT_VARIANT;
+    V_VT(&nes) = VT_BYREF | VT_BSTR;
+    b = SysAllocString(wstr_test);
+    V_BSTRREF(&nes) = &b;
+    V_VARIANTREF(&var) = &nes;
+    result = VariantToStringWithDefault(&var, default_value);
+    ok(result == b, "Unexpected value %s\n", wine_dbgstr_w(result));
+    SysFreeString(b);
+}
+
 START_TEST(propsys)
 {
     test_PSStringFromPropertyKey();
@@ -2088,4 +2270,5 @@ START_TEST(propsys)
     test_propertystore();
     test_PSCreatePropertyStoreFromObject();
     test_InitVariantFromFileTime();
+    test_VariantToStringWithDefault();
 }
-- 
2.35.1




More information about the wine-devel mailing list