-- v2: msmxl4/tests: Add tests for get_xml. msxml4/tests: Use wide string literals.
From: Daniel Lehman dlehman25@gmail.com
--- dlls/msxml4/tests/domdoc.c | 93 ++++++++++++++------------------------ 1 file changed, 33 insertions(+), 60 deletions(-)
diff --git a/dlls/msxml4/tests/domdoc.c b/dlls/msxml4/tests/domdoc.c index 39fe8c5a995..7b09cada130 100644 --- a/dlls/msxml4/tests/domdoc.c +++ b/dlls/msxml4/tests/domdoc.c @@ -36,76 +36,50 @@
#include "wine/test.h"
-static BSTR alloced_bstrs[256]; -static int alloced_bstrs_count; - -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; -} - -static BSTR _bstr_(const char *str) -{ - assert(alloced_bstrs_count < ARRAY_SIZE(alloced_bstrs)); - alloced_bstrs[alloced_bstrs_count] = alloc_str_from_narrow(str); - return alloced_bstrs[alloced_bstrs_count++]; -} - -static void free_bstrs(void) -{ - int i; - for (i = 0; i < alloced_bstrs_count; i++) - SysFreeString(alloced_bstrs[i]); - alloced_bstrs_count = 0; -} - /* see dlls/msxml[36]/tests/domdoc.c */ static void test_namespaces_as_attributes(void) { struct test { - const char *xml; + const wchar_t *xml; int explen; - const char *names[3]; - const char *prefixes[3]; - const char *basenames[3]; - const char *uris[3]; - const char *texts[3]; + const wchar_t *names[3]; + const wchar_t *prefixes[3]; + const wchar_t *basenames[3]; + const wchar_t *uris[3]; + const wchar_t *texts[3]; }; static const struct test tests[] = { { - "<a ns:b="b attr" d="d attr" xmlns:ns="nshref" />", 3, - { "ns:b", "d", "xmlns:ns" }, /* nodeName */ - { "ns", NULL, "xmlns" }, /* prefix */ - { "b", "d", "ns" }, /* baseName */ - { "nshref", NULL, "" }, /* namespaceURI */ - { "b attr", "d attr", "nshref" }, /* text */ + L"<a ns:b="b attr" d="d attr" xmlns:ns="nshref" />", 3, + { L"ns:b", L"d", L"xmlns:ns" }, /* nodeName */ + { L"ns", NULL, L"xmlns" }, /* prefix */ + { L"b", L"d", L"ns" }, /* baseName */ + { L"nshref", NULL, L"" }, /* namespaceURI */ + { L"b attr", L"d attr", L"nshref" }, /* text */ }, /* property only */ { - "<a d="d attr" />", 1, - { "d" }, /* nodeName */ - { NULL }, /* prefix */ - { "d" }, /* baseName */ - { NULL }, /* namespaceURI */ - { "d attr" }, /* text */ + L"<a d="d attr" />", 1, + { L"d" }, /* nodeName */ + { NULL }, /* prefix */ + { L"d" }, /* baseName */ + { NULL }, /* namespaceURI */ + { L"d attr" }, /* text */ }, /* namespace only */ { - "<a xmlns:ns="nshref" />", 1, - { "xmlns:ns" }, /* nodeName */ - { "xmlns" }, /* prefix */ - { "ns" }, /* baseName */ - { "" }, /* namespaceURI */ - { "nshref" }, /* text */ + L"<a xmlns:ns="nshref" />", 1, + { L"xmlns:ns" }, /* nodeName */ + { L"xmlns" }, /* prefix */ + { L"ns" }, /* baseName */ + { L"" }, /* namespaceURI */ + { L"nshref" }, /* text */ }, /* no properties or namespaces */ { - "<a />", 0, + L"<a />", 0, },
{ NULL } @@ -125,11 +99,11 @@ static void test_namespaces_as_attributes(void) hr = CoCreateInstance(&CLSID_DOMDocument40, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (void **)&doc); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
- hr = IXMLDOMDocument2_loadXML(doc, _bstr_(test->xml), &b); + hr = IXMLDOMDocument2_loadXML(doc, (BSTR)test->xml, &b); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
node = NULL; - hr = IXMLDOMDocument2_selectSingleNode(doc, _bstr_("a"), &node); + hr = IXMLDOMDocument2_selectSingleNode(doc, (BSTR)L"a", &node); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr);
hr = IXMLDOMNode_get_attributes(node, &map); @@ -154,7 +128,7 @@ static void test_namespaces_as_attributes(void) str = NULL; hr = IXMLDOMNode_get_nodeName(item, &str); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); - ok(!lstrcmpW(str, _bstr_(test->names[i])), "got %s\n", wine_dbgstr_w(str)); + ok(!lstrcmpW(str, test->names[i]), "got %s\n", wine_dbgstr_w(str)); SysFreeString(str);
str = NULL; @@ -162,7 +136,7 @@ static void test_namespaces_as_attributes(void) if (test->prefixes[i]) { ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); - ok(!lstrcmpW(str, _bstr_(test->prefixes[i])), "got %s\n", wine_dbgstr_w(str)); + ok(!lstrcmpW(str, test->prefixes[i]), "got %s\n", wine_dbgstr_w(str)); SysFreeString(str); } else @@ -171,7 +145,7 @@ static void test_namespaces_as_attributes(void) str = NULL; hr = IXMLDOMNode_get_baseName(item, &str); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); - ok(!lstrcmpW(str, _bstr_(test->basenames[i])), "got %s\n", wine_dbgstr_w(str)); + ok(!lstrcmpW(str, test->basenames[i]), "got %s\n", wine_dbgstr_w(str)); SysFreeString(str);
str = NULL; @@ -179,10 +153,10 @@ static void test_namespaces_as_attributes(void) if (test->uris[i]) { ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); - if (test->prefixes[i] && !strcmp(test->prefixes[i], "xmlns")) + if (test->prefixes[i] && !lstrcmpW(test->prefixes[i], L"xmlns")) ok(!lstrcmpW(str, L""), "got %s\n", wine_dbgstr_w(str)); else - ok(!lstrcmpW(str, _bstr_(test->uris[i])), "got %s\n", wine_dbgstr_w(str)); + ok(!lstrcmpW(str, test->uris[i]), "got %s\n", wine_dbgstr_w(str)); SysFreeString(str); } else @@ -191,7 +165,7 @@ static void test_namespaces_as_attributes(void) str = NULL; hr = IXMLDOMNode_get_text(item, &str); ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); - ok(!lstrcmpW(str, _bstr_(test->texts[i])), "got %s\n", wine_dbgstr_w(str)); + ok(!lstrcmpW(str, test->texts[i]), "got %s\n", wine_dbgstr_w(str)); SysFreeString(str);
IXMLDOMNode_Release(item); @@ -203,7 +177,6 @@ static void test_namespaces_as_attributes(void)
test++; } - free_bstrs(); }
START_TEST(domdoc)
From: Daniel Lehman dlehman25@gmail.com
--- dlls/msxml4/tests/domdoc.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/dlls/msxml4/tests/domdoc.c b/dlls/msxml4/tests/domdoc.c index 7b09cada130..bc1c25245cc 100644 --- a/dlls/msxml4/tests/domdoc.c +++ b/dlls/msxml4/tests/domdoc.c @@ -48,6 +48,7 @@ static void test_namespaces_as_attributes(void) const wchar_t *basenames[3]; const wchar_t *uris[3]; const wchar_t *texts[3]; + const wchar_t *xmls[3]; }; static const struct test tests[] = { @@ -58,6 +59,7 @@ static void test_namespaces_as_attributes(void) { L"b", L"d", L"ns" }, /* baseName */ { L"nshref", NULL, L"" }, /* namespaceURI */ { L"b attr", L"d attr", L"nshref" }, /* text */ + { L"ns:b="b attr"", L"d="d attr"", L"xmlns:ns="nshref"" }, /* xml */ }, /* property only */ { @@ -67,6 +69,7 @@ static void test_namespaces_as_attributes(void) { L"d" }, /* baseName */ { NULL }, /* namespaceURI */ { L"d attr" }, /* text */ + { L"d="d attr"" }, /* xml */ }, /* namespace only */ { @@ -76,6 +79,7 @@ static void test_namespaces_as_attributes(void) { L"ns" }, /* baseName */ { L"" }, /* namespaceURI */ { L"nshref" }, /* text */ + { L"xmlns:ns="nshref"" }, /* xml */ }, /* no properties or namespaces */ { @@ -168,6 +172,12 @@ static void test_namespaces_as_attributes(void) ok(!lstrcmpW(str, test->texts[i]), "got %s\n", wine_dbgstr_w(str)); SysFreeString(str);
+ str = NULL; + hr = IXMLDOMNode_get_xml(item, &str); + ok(SUCCEEDED(hr), "Failed to get node xml, hr %#lx.\n", hr); + ok(!lstrcmpW(str, test->xmls[i]), "got %s\n", wine_dbgstr_w(str)); + SysFreeString(str); + IXMLDOMNode_Release(item); }
this ok for msxml4? will do the rest like this if so
We still needs to pass BSTRs, but without conversion in alloc_str_from_narrow(). And it's better to use WCHAR for test strings.