Module: wine Branch: refs/heads/master Commit: 8ec390676890a64e4c32a060a3340fed7350d5eb URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=8ec390676890a64e4c32a060...
Author: Michael Stefaniuc mstefani@redhat.de Date: Mon Dec 5 12:00:24 2005 +0100
Fix VarBstrCmp for NULL input BSTRs (MSDN is wrong).
---
dlls/oleaut32/tests/vartype.c | 32 ++++++++++++++++++++++++++++++++ dlls/oleaut32/vartype.c | 18 ++++++++---------- 2 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/dlls/oleaut32/tests/vartype.c b/dlls/oleaut32/tests/vartype.c index 9beaa35..d77655c 100644 --- a/dlls/oleaut32/tests/vartype.c +++ b/dlls/oleaut32/tests/vartype.c @@ -516,6 +516,7 @@ static HRESULT (WINAPI *pVarBoolFromUI8) static HRESULT (WINAPI *pVarBstrFromR4)(FLOAT,LCID,ULONG,BSTR*); static HRESULT (WINAPI *pVarBstrFromDate)(DATE,LCID,ULONG,BSTR*); static HRESULT (WINAPI *pVarBstrFromDec)(DECIMAL*,LCID,ULONG,BSTR*); +static HRESULT (WINAPI *pVarBstrCmp)(BSTR,BSTR,LCID,ULONG);
static HRESULT (WINAPI *pVarCmp)(LPVARIANT,LPVARIANT,LCID,ULONG);
@@ -4960,6 +4961,36 @@ static void test_VarBstrFromDec(void) #undef BSTR_DEC #undef BSTR_DEC64
+#define _VARBSTRCMP(left,right,lcid,flags,result) \ + hres = pVarBstrCmp(left,right,lcid,flags); \ + ok(hres == result, "VarBstrCmp: expected " #result ", got hres=0x%lx\n", hres) +#define VARBSTRCMP(left,right,result) \ + _VARBSTRCMP(left,right,lcid,0,result) + +static void test_VarBstrCmp(void) +{ + LCID lcid; + HRESULT hres; + static const WCHAR sz[] = {'W','u','r','s','c','h','t','\0'}; + static const WCHAR szempty[] = {'\0'}; + BSTR bstr, bstrempty; + + CHECKPTR(VarBstrCmp); + + lcid = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT); + bstr = SysAllocString(sz); + bstrempty = SysAllocString(szempty); + + /* NULL handling. Yepp, MSDN is totaly wrong here */ + VARBSTRCMP(NULL,NULL,VARCMP_EQ); + VARBSTRCMP(bstr,NULL,VARCMP_GT); + VARBSTRCMP(NULL,bstr,VARCMP_LT); + + /* NULL and empty string comparisions */ + VARBSTRCMP(bstrempty,NULL,VARCMP_EQ); + VARBSTRCMP(NULL,bstrempty,VARCMP_EQ); +} + /* Get the internal representation of a BSTR */ static inline LPINTERNAL_BSTR Get(const BSTR lpszString) { @@ -5968,6 +5999,7 @@ START_TEST(vartype) test_VarBstrFromR4(); test_VarBstrFromDate(); test_VarBstrFromDec(); + test_VarBstrCmp(); test_SysStringLen(); test_SysStringByteLen(); test_SysAllocString(); diff --git a/dlls/oleaut32/vartype.c b/dlls/oleaut32/vartype.c index 2075827..1214752 100644 --- a/dlls/oleaut32/vartype.c +++ b/dlls/oleaut32/vartype.c @@ -6599,23 +6599,21 @@ HRESULT WINAPI VarBstrCat(BSTR pbstrLeft * RETURNS * VARCMP_LT, VARCMP_EQ or VARCMP_GT indicating that pbstrLeft is less * than, equal to or greater than pbstrRight respectively. - * VARCMP_NULL is returned if either string is NULL, unless both are NULL - * in which case VARCMP_EQ is returned. + * + * NOTES + * VARCMP_NULL is NOT returned if either string is NULL unlike MSDN + * states. A NULL BSTR pointer is equivalent to an empty string. */ HRESULT WINAPI VarBstrCmp(BSTR pbstrLeft, BSTR pbstrRight, LCID lcid, DWORD dwFlags) { - if (!pbstrLeft) + if (!pbstrLeft || !*pbstrLeft) { if (!pbstrRight || !*pbstrRight) return VARCMP_EQ; - return VARCMP_NULL; - } - else if (!pbstrRight) - { - if (!*pbstrLeft) - return VARCMP_EQ; - return VARCMP_NULL; + return VARCMP_LT; } + else if (!pbstrRight || !*pbstrRight) + return VARCMP_GT;
return CompareStringW(lcid, dwFlags, pbstrLeft, -1, pbstrRight, -1) - 1; }