Commit 8ec39067 authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

Fix VarBstrCmp for NULL input BSTRs (MSDN is wrong).

parent 58e156b5
...@@ -516,6 +516,7 @@ static HRESULT (WINAPI *pVarBoolFromUI8)(ULONG64,VARIANT_BOOL*); ...@@ -516,6 +516,7 @@ static HRESULT (WINAPI *pVarBoolFromUI8)(ULONG64,VARIANT_BOOL*);
static HRESULT (WINAPI *pVarBstrFromR4)(FLOAT,LCID,ULONG,BSTR*); static HRESULT (WINAPI *pVarBstrFromR4)(FLOAT,LCID,ULONG,BSTR*);
static HRESULT (WINAPI *pVarBstrFromDate)(DATE,LCID,ULONG,BSTR*); static HRESULT (WINAPI *pVarBstrFromDate)(DATE,LCID,ULONG,BSTR*);
static HRESULT (WINAPI *pVarBstrFromDec)(DECIMAL*,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); static HRESULT (WINAPI *pVarCmp)(LPVARIANT,LPVARIANT,LCID,ULONG);
...@@ -4960,6 +4961,36 @@ static void test_VarBstrFromDec(void) ...@@ -4960,6 +4961,36 @@ static void test_VarBstrFromDec(void)
#undef BSTR_DEC #undef BSTR_DEC
#undef BSTR_DEC64 #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 */ /* Get the internal representation of a BSTR */
static inline LPINTERNAL_BSTR Get(const BSTR lpszString) static inline LPINTERNAL_BSTR Get(const BSTR lpszString)
{ {
...@@ -5968,6 +5999,7 @@ START_TEST(vartype) ...@@ -5968,6 +5999,7 @@ START_TEST(vartype)
test_VarBstrFromR4(); test_VarBstrFromR4();
test_VarBstrFromDate(); test_VarBstrFromDate();
test_VarBstrFromDec(); test_VarBstrFromDec();
test_VarBstrCmp();
test_SysStringLen(); test_SysStringLen();
test_SysStringByteLen(); test_SysStringByteLen();
test_SysAllocString(); test_SysAllocString();
......
...@@ -6599,23 +6599,21 @@ HRESULT WINAPI VarBstrCat(BSTR pbstrLeft, BSTR pbstrRight, BSTR *pbstrOut) ...@@ -6599,23 +6599,21 @@ HRESULT WINAPI VarBstrCat(BSTR pbstrLeft, BSTR pbstrRight, BSTR *pbstrOut)
* RETURNS * RETURNS
* VARCMP_LT, VARCMP_EQ or VARCMP_GT indicating that pbstrLeft is less * VARCMP_LT, VARCMP_EQ or VARCMP_GT indicating that pbstrLeft is less
* than, equal to or greater than pbstrRight respectively. * 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) HRESULT WINAPI VarBstrCmp(BSTR pbstrLeft, BSTR pbstrRight, LCID lcid, DWORD dwFlags)
{ {
if (!pbstrLeft) if (!pbstrLeft || !*pbstrLeft)
{ {
if (!pbstrRight || !*pbstrRight) if (!pbstrRight || !*pbstrRight)
return VARCMP_EQ; return VARCMP_EQ;
return VARCMP_NULL; return VARCMP_LT;
}
else if (!pbstrRight)
{
if (!*pbstrLeft)
return VARCMP_EQ;
return VARCMP_NULL;
} }
else if (!pbstrRight || !*pbstrRight)
return VARCMP_GT;
return CompareStringW(lcid, dwFlags, pbstrLeft, -1, pbstrRight, -1) - 1; return CompareStringW(lcid, dwFlags, pbstrLeft, -1, pbstrRight, -1) - 1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment