oleaut32 2/2: [RESEND 2] Conformance test for varformat:VarWeekdayName

Benjamin Arai me at benjaminarai.com
Wed Sep 27 19:09:39 CDT 2006


Hi,

---
 dlls/oleaut32/tests/varformat.c |  130 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 130 insertions(+), 0 deletions(-)

Copyright: Google
License: LGPL

-- 
Benjamin Arai
http://www.benjaminarai.com
-------------- next part --------------

diff --git a/dlls/oleaut32/tests/varformat.c b/dlls/oleaut32/tests/varformat.c
index 9df22e0..5f1cd20 100644
--- a/dlls/oleaut32/tests/varformat.c
+++ b/dlls/oleaut32/tests/varformat.c
@@ -392,10 +392,140 @@ static void test_VarFormat(void)
   VARFMT(VT_BOOL,V_BOOL,VARIANT_TRUE,"",E_INVALIDARG,"");
 }
 
+void test_VarWeekdayName(void)
+{
+    WCHAR day_LongFormat[][10] =
+    {
+        {'S','u','n','d','a','y',0},
+        {'M','o','n','d','a','y',0},
+        {'T','u','e','s','d','a','y',0},
+        {'W','e','d','n','e','s','d','a','y',0},
+        {'T','h','u','r','s','d','a','y',0},
+        {'F','r','i','d','a','y',0},
+        {'S','a','t','u','r','d','a','y',0}
+    };
+
+    WCHAR day_ShortFormat[][4] =
+    {
+        {'S','u','n',0},
+        {'M','o','n',0},
+        {'T','u','e',0},
+        {'W','e','d',0},
+        {'T','h','u',0},
+        {'F','r','i',0},
+        {'S','a','t',0}
+    };
+
+    HRESULT hres,expectedhres;
+    BSTR pbstrOut = NULL;
+    BSTR day = NULL;
+    int iFirstDay,iWeekday,expectedDay;
+    static char expectedBuff[10];
+    static char resultBuff[10];
+
+    /* test bad value for weekday */
+    hres = VarWeekdayName(-1, 0, 1, 0, &pbstrOut);
+    ok (hres == E_INVALIDARG,
+        "VarWeekdayName: Weekday=-1,Abbrev=0,FirstDay=1, expected 0x%08lx, got 0x%08lx\n",
+        E_INVALIDARG,hres);
+
+    SysFreeString(pbstrOut);
+    pbstrOut = NULL;
+
+    /* test bad value for first day */
+    hres = VarWeekdayName(1, 0, -1, 0, &pbstrOut);
+    ok (hres == E_INVALIDARG,
+        "VarWeekdayName: Weekday=1,Abbrev=0,FirstDay=-1, expected 0x%08lx, got 0x%08lx\n",
+        E_INVALIDARG,hres);
+
+    SysFreeString(pbstrOut);
+    pbstrOut = NULL;
+
+    /* test bad bstr */
+    hres = VarWeekdayName(1, 0, 1, 0, NULL);
+    ok (hres == E_INVALIDARG,
+        "VarWeekdayName: pbstrOut=NULL, expected 0x%08lx, got 0x%08lx\n",
+        E_INVALIDARG,hres);
+
+    /* if the language is not English skip the remaining tests */
+    if (PRIMARYLANGID(LANGIDFROMLCID(GetUserDefaultLCID())) != LANG_ENGLISH)
+    {
+        trace("Skipping VarWeekdayName tests for non english language\n");
+        return;
+    }
+
+    /* check all possible start days */
+    for (iFirstDay = 0; iFirstDay < 9; iFirstDay++)
+    {
+        /* Check all possible days */
+        for (iWeekday = 0; iWeekday < 9; iWeekday++)
+        {
+            expectedDay = (iFirstDay + iWeekday - 2) % 7;
+            if (iFirstDay == 0)
+                expectedDay += 1;
+
+            if ((iWeekday < 1) || (iWeekday > 7) ||
+                (iFirstDay < 0) || (iFirstDay > 7))
+                expectedhres = E_INVALIDARG;
+            else
+                expectedhres = S_OK;
+
+            /* Test long format day */
+            hres = VarWeekdayName(iWeekday, 0, iFirstDay, 0, &pbstrOut);
+
+            ok (hres == expectedhres,
+                "VarWeekdayName: Weekday=%d,Abbrev=0,FirstDay=%d, expected 0x%08lx, got 0x%08lx\n",
+                iWeekday,iFirstDay,expectedhres,hres);
+
+            /* if the hres is not S_OK then we don't care about the result */
+            if (hres == S_OK && expectedhres == S_OK)
+            {
+                day = SysAllocStringLen(day_LongFormat[expectedDay],
+                    lstrlenW(day_LongFormat[expectedDay]));
+                WideCharToMultiByte(CP_ACP, 0, (WCHAR *)day,
+                    -1,expectedBuff, sizeof(expectedBuff), NULL, NULL);
+                WideCharToMultiByte(CP_ACP,0,(WCHAR *)pbstrOut,-1,resultBuff,
+                    sizeof(resultBuff), NULL, NULL);
+                ok(VarBstrCmp(pbstrOut,day,0,0) == VARCMP_EQ,
+                    "VarWeekdayName: Weekday=%d,Abbrev=0,FirstDay=%d, expected \"%s\" got \"%s\"\n",
+                    iWeekday,iFirstDay,expectedBuff,resultBuff);
+                SysFreeString(day);
+            }
+            SysFreeString(pbstrOut);
+            pbstrOut = NULL;
+
+            /* Test short format day */
+            hres = VarWeekdayName(iWeekday, 1, iFirstDay,0, &pbstrOut);
+
+            ok (hres == expectedhres,
+                "VarWeekdayName: Weekday=%d,Abbrev=1,FirstDay=%d expected 0x%08lx, got 0x%08lx\n",
+                iWeekday,iFirstDay,expectedhres,hres);
+
+            /* if the hres is not S_OK then we don't care about the result */
+            if (hres == S_OK && expectedhres == S_OK)
+            {
+                day = SysAllocStringLen(day_ShortFormat[expectedDay],
+                    lstrlenW(day_ShortFormat[expectedDay]));
+                WideCharToMultiByte(CP_ACP, 0, (WCHAR *)day,
+                    -1,expectedBuff, sizeof(expectedBuff), NULL, NULL);
+                WideCharToMultiByte(CP_ACP,0,(WCHAR *)pbstrOut,-1,resultBuff,
+                     sizeof(resultBuff), NULL, NULL);
+                ok(VarBstrCmp(pbstrOut,day,0,0) == VARCMP_EQ,
+                    "VarWeekdayName: Weekday=%d,Abbrev=1,FirstDay=%d, expected \"%s\" got \"%s\"\n",
+                    iWeekday,iFirstDay,expectedBuff,resultBuff);
+                SysFreeString(day);
+            }
+            SysFreeString(pbstrOut);
+            pbstrOut = NULL;
+        }
+    }
+}
+
 START_TEST(varformat)
 {
   hOleaut32 = LoadLibraryA("oleaut32.dll");
 
   test_VarFormatNumber();
   test_VarFormat();
+  test_VarWeekdayName();
 }
-- 
1.4.0


More information about the wine-patches mailing list