msxml3: Implement IXMLDOMDocument2::setProperty("SelectionLanguage", ...).

This commit is contained in:
Mikołaj Zalewski 2007-05-09 20:09:11 +02:00 committed by Alexandre Julliard
parent 918ee77d1c
commit bf3849ad6f
2 changed files with 145 additions and 4 deletions

View File

@ -43,6 +43,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(msxml);
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
static const WCHAR SZ_PROPERTY_SELECTION_LANGUAGE[] = {'S','e','l','e','c','t','i','o','n','L','a','n','g','u','a','g','e',0};
static const WCHAR SZ_VALUE_XPATH[] = {'X','P','a','t','h',0};
static const WCHAR SZ_VALUE_XSLPATTERN[] = {'X','S','L','P','a','t','t','e','r','n',0};
typedef struct { typedef struct {
const struct IBindStatusCallbackVtbl *lpVtbl; const struct IBindStatusCallbackVtbl *lpVtbl;
} bsc; } bsc;
@ -169,6 +173,7 @@ typedef struct _domdoc
VARIANT_BOOL validating; VARIANT_BOOL validating;
VARIANT_BOOL resolving; VARIANT_BOOL resolving;
VARIANT_BOOL preserving; VARIANT_BOOL preserving;
BOOL bUseXPath;
IUnknown *node_unk; IUnknown *node_unk;
IXMLDOMNode *node; IXMLDOMNode *node;
IXMLDOMSchemaCollection *schema; IXMLDOMSchemaCollection *schema;
@ -1374,8 +1379,38 @@ static HRESULT WINAPI domdoc_setProperty(
BSTR p, BSTR p,
VARIANT var) VARIANT var)
{ {
FIXME("\n"); domdoc *This = impl_from_IXMLDOMDocument2( iface );
return E_NOTIMPL;
if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
{
VARIANT varStr;
HRESULT hr;
BSTR bstr;
V_VT(&varStr) = VT_EMPTY;
if (V_VT(&var) != VT_BSTR)
{
if (FAILED(hr = VariantChangeType(&varStr, &var, 0, VT_BSTR)))
return hr;
bstr = V_BSTR(&varStr);
}
else
bstr = V_BSTR(&var);
hr = S_OK;
if (lstrcmpiW(bstr, SZ_VALUE_XPATH) == 0)
This->bUseXPath = TRUE;
else if (lstrcmpiW(bstr, SZ_VALUE_XSLPATTERN) == 0)
This->bUseXPath = FALSE;
else
hr = E_FAIL;
VariantClear(&varStr);
return hr;
}
FIXME("Unknown property %s\n", wine_dbgstr_w(p));
return E_FAIL;
} }
static HRESULT WINAPI domdoc_getProperty( static HRESULT WINAPI domdoc_getProperty(
@ -1383,8 +1418,22 @@ static HRESULT WINAPI domdoc_getProperty(
BSTR p, BSTR p,
VARIANT* var) VARIANT* var)
{ {
FIXME("\n"); domdoc *This = impl_from_IXMLDOMDocument2( iface );
return E_NOTIMPL;
if (var == NULL)
return E_INVALIDARG;
if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
{
V_VT(var) = VT_BSTR;
if (This->bUseXPath)
V_BSTR(var) = SysAllocString(SZ_VALUE_XPATH);
else
V_BSTR(var) = SysAllocString(SZ_VALUE_XSLPATTERN);
return S_OK;
}
FIXME("Unknown property %s\n", wine_dbgstr_w(p));
return E_FAIL;
} }
static const struct IXMLDOMDocument2Vtbl domdoc_vtbl = static const struct IXMLDOMDocument2Vtbl domdoc_vtbl =
@ -1491,6 +1540,7 @@ HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
doc->validating = 0; doc->validating = 0;
doc->resolving = 0; doc->resolving = 0;
doc->preserving = 0; doc->preserving = 0;
doc->bUseXPath = FALSE;
doc->error = S_OK; doc->error = S_OK;
doc->schema = NULL; doc->schema = NULL;

View File

@ -26,6 +26,7 @@
#include "xmldom.h" #include "xmldom.h"
#include "msxml2.h" #include "msxml2.h"
#include <stdio.h> #include <stdio.h>
#include <assert.h>
#include "wine/test.h" #include "wine/test.h"
@ -101,6 +102,59 @@ static const WCHAR szstr2[] = { 's','t','r','2',0 };
static const WCHAR szstar[] = { '*',0 }; static const WCHAR szstar[] = { '*',0 };
static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0}; static const WCHAR szfn1_txt[] = {'f','n','1','.','t','x','t',0};
#define expect_bstr_eq_and_free(bstr, expect) { \
BSTR bstrExp = alloc_str_from_narrow(expect); \
ok(lstrcmpW(bstr, bstrExp) == 0, "String differs\n"); \
SysFreeString(bstr); \
SysFreeString(bstrExp); \
}
#define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
#define ole_check(expr) { \
HRESULT r = expr; \
ok(r == S_OK, #expr " returned %x\n", r); \
}
#define ole_expect(expr, expect) { \
HRESULT r = expr; \
ok(r == (expect), #expr " returned %x, expected %x\n", r, expect); \
}
static BSTR alloc_str_from_narrow(const char *str)
{
int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
BSTR ret = SysAllocStringLen(NULL, len - 1); /* NUL character added automatically */
MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
return ret;
}
BSTR alloced_bstrs[256];
int alloced_bstrs_count = 0;
static BSTR _bstr_(const char *str)
{
assert(alloced_bstrs_count < sizeof(alloced_bstrs)/sizeof(alloced_bstrs[0]));
alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str);
return alloced_bstrs[alloced_bstrs_count++];
}
static void free_bstrs()
{
int i;
for (i = 0; i < alloced_bstrs_count; i++)
SysFreeString(alloced_bstrs[i]);
alloced_bstrs_count = 0;
}
static VARIANT _variantbstr_(const char *str)
{
VARIANT v;
V_VT(&v) = VT_BSTR;
V_BSTR(&v) = _bstr_(str);
return v;
}
static void test_domdoc( void ) static void test_domdoc( void )
{ {
HRESULT r; HRESULT r;
@ -1162,6 +1216,8 @@ static void test_IXMLDOMDocument2(void)
BSTR str; BSTR str;
IXMLDOMDocument *doc; IXMLDOMDocument *doc;
IXMLDOMDocument2 *doc2; IXMLDOMDocument2 *doc2;
VARIANT var;
int ref;
r = CoCreateInstance( &CLSID_DOMDocument, NULL, r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc ); CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
@ -1177,8 +1233,43 @@ static void test_IXMLDOMDocument2(void)
r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 ); r = IXMLDOMDocument_QueryInterface( doc, &IID_IXMLDOMDocument2, (void**)&doc2 );
ok( r == S_OK, "ret %08x\n", r ); ok( r == S_OK, "ret %08x\n", r );
ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n"); ok( doc == (IXMLDOMDocument*)doc2, "interfaces differ\n");
/* we will check if the variant got cleared */
ref = IXMLDOMDocument2_AddRef(doc2);
expect_eq(ref, 3, int, "%d"); /* doc, doc2, AddRef*/
V_VT(&var) = VT_UNKNOWN;
V_UNKNOWN(&var) = (IUnknown *)doc2;
/* invalid calls */
ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("askldhfaklsdf"), &var), E_FAIL);
expect_eq(V_VT(&var), VT_UNKNOWN, int, "%x");
ole_expect(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), NULL), E_INVALIDARG);
/* valid call */
ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
expect_eq(V_VT(&var), VT_BSTR, int, "%x");
expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
V_VT(&var) = VT_R4;
/* the variant didn't get cleared*/
expect_eq(IXMLDOMDocument2_Release(doc2), 2, int, "%d");
/* setProperty tests */
ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("askldhfaklsdf"), var), E_FAIL);
ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), var), E_FAIL);
ole_expect(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("alskjdh faklsjd hfk")), E_FAIL);
ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XPath")));
ole_check(IXMLDOMDocument2_setProperty(doc2, _bstr_("SelectionLanguage"), _variantbstr_("XSLPattern")));
/* contrary to what MSDN calims you can switch back from XPath to XSLPattern */
ole_check(IXMLDOMDocument2_getProperty(doc2, _bstr_("SelectionLanguage"), &var));
expect_eq(V_VT(&var), VT_BSTR, int, "%x");
expect_bstr_eq_and_free(V_BSTR(&var), "XSLPattern");
IXMLDOMDocument2_Release( doc2 ); IXMLDOMDocument2_Release( doc2 );
IXMLDOMDocument_Release( doc ); IXMLDOMDocument_Release( doc );
free_bstrs();
} }
START_TEST(domdoc) START_TEST(domdoc)