>From 68d95689210c4fc6f8d428514395d3f89fe2329c Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <nsivov@codeweavers.com>
Date: Mon, 23 Jan 2012 07:23:47 +0300
Subject: [PATCH 1/4] Make remove() method a stub in version 6, more collection tests

---
 dlls/msxml3/schema.c       |    2 +
 dlls/msxml3/tests/domdoc.c |  180 +++++++++++++++++++++++++++++++++++++++++++-
 dlls/msxml3/tests/schema.c |  104 +++++++++++++++++++++++--
 3 files changed, 275 insertions(+), 11 deletions(-)

diff --git a/dlls/msxml3/schema.c b/dlls/msxml3/schema.c
index 2c97639..a147105 100644
--- a/dlls/msxml3/schema.c
+++ b/dlls/msxml3/schema.c
@@ -1167,6 +1167,8 @@ static HRESULT WINAPI schema_cache_remove(IXMLDOMSchemaCollection2* iface, BSTR
     xmlChar* name = uri ? xmlchar_from_wchar(uri) : xmlchar_from_wchar(emptyW);
     TRACE("(%p)->(%s)\n", This, debugstr_w(uri));
 
+    if (This->version == MSXML6) return E_NOTIMPL;
+
     xmlHashRemoveEntry(This->cache, name, cache_free);
     heap_free(name);
     return S_OK;
diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c
index cc01a25..7c8bd9c 100644
--- a/dlls/msxml3/tests/domdoc.c
+++ b/dlls/msxml3/tests/domdoc.c
@@ -11140,24 +11140,41 @@ static void test_nodeValue(void)
     IXMLDOMDocument_Release(doc);
 }
 
-static char namespacesA[] =
+static const char namespacesA[] =
 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
 "   <ns1:elem1 xmlns:ns1=\"http://blah.org\">"
-"     <ns1:elem2/>"
+"     <ns2:elem2 xmlns:ns2=\"http://blah.org\"/>"
 "     <ns1:elem3/>"
 "     <ns1:elem4/>"
 "     <elem5 xmlns=\"http://blahblah.org\"/>"
 "     <ns1:elem6>true</ns1:elem6>"
 "   </ns1:elem1>";
 
+static const char xsd_schema1_uri[] = "x-schema:test1.xsd";
+static const char xsd_schema1_xml[] =
+"<?xml version='1.0'?>"
+"<schema xmlns='http://www.w3.org/2001/XMLSchema'"
+"            targetNamespace='x-schema:test1.xsd'>"
+"   <element name='root'>"
+"       <complexType>"
+"           <sequence maxOccurs='unbounded'>"
+"               <any/>"
+"           </sequence>"
+"       </complexType>"
+"   </element>"
+"</schema>";
+
 static void test_get_namespaces(void)
 {
     IXMLDOMSchemaCollection *collection, *collection2;
-    IXMLDOMDocument2 *doc;
+    IXMLDOMDocument2 *doc, *doc2;
+    IEnumVARIANT *enumv;
     IXMLDOMNode *node;
     VARIANT_BOOL b;
     HRESULT hr;
+    VARIANT v;
     LONG len;
+    BSTR s;
 
     doc = create_document(&IID_IXMLDOMDocument2);
     if (!doc) return;
@@ -11214,9 +11231,166 @@ todo_wine
     EXPECT_HR(hr, S_OK);
     ok(node == NULL, "got %p\n", node);
 
+    /* load schema and try to add it */
+    doc2 = create_document(&IID_IXMLDOMDocument2);
+    hr = IXMLDOMDocument2_loadXML(doc2, _bstr_(xsd_schema1_xml), &b);
+    EXPECT_HR(hr, S_OK);
+
+    V_VT(&v) = VT_DISPATCH;
+    V_DISPATCH(&v) = (IDispatch*)doc2;
+    hr = IXMLDOMSchemaCollection_add(collection, _bstr_(xsd_schema1_uri), v);
+    EXPECT_HR(hr, E_FAIL);
+
+    hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 0, &s);
+    EXPECT_HR(hr, S_OK);
+    ok(!lstrcmpW(s, _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(s));
+    SysFreeString(s);
+
+    hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 1, &s);
+    EXPECT_HR(hr, S_OK);
+    ok(!lstrcmpW(s, _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(s));
+    SysFreeString(s);
+
+    s = (void*)0xdeadbeef;
+    hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 2, &s);
+    EXPECT_HR(hr, E_FAIL);
+    ok(s == (void*)0xdeadbeef, "got %p\n", s);
+
+    /* enumerate */
+    enumv = (void*)0xdeadbeef;
+    hr = IXMLDOMSchemaCollection_get__newEnum(collection, (IUnknown**)&enumv);
+    EXPECT_HR(hr, S_OK);
+    ok(enumv != NULL, "got %p\n", enumv);
+
+    V_VT(&v) = VT_EMPTY;
+    hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
+    EXPECT_HR(hr, S_OK);
+    ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
+    ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
+    VariantClear(&v);
+
+    V_VT(&v) = VT_EMPTY;
+    hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
+    EXPECT_HR(hr, S_OK);
+    ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
+    ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
+    VariantClear(&v);
+
+    V_VT(&v) = VT_NULL;
+    hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
+    EXPECT_HR(hr, S_FALSE);
+    ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
+
+    IEnumVARIANT_Release(enumv);
     IXMLDOMSchemaCollection_Release(collection);
 
     IXMLDOMDocument2_Release(doc);
+
+    /* now with CLSID_DOMDocument60 */
+    doc = create_document_version(60, &IID_IXMLDOMDocument2);
+    if (!doc) return;
+
+    /* null pointer */
+    hr = IXMLDOMDocument2_get_namespaces(doc, NULL);
+    EXPECT_HR(hr, E_POINTER);
+
+    /* no document loaded */
+    collection = (void*)0xdeadbeef;
+    hr = IXMLDOMDocument2_get_namespaces(doc, &collection);
+todo_wine
+    EXPECT_HR(hr, S_OK);
+    if (hr != S_OK)
+    {
+        IXMLDOMDocument_Release(doc);
+        return;
+    }
+    EXPECT_REF(collection, 2);
+
+    collection2 = (void*)0xdeadbeef;
+    hr = IXMLDOMDocument2_get_namespaces(doc, &collection2);
+    EXPECT_HR(hr, S_OK);
+    ok(collection == collection2, "got %p\n", collection2);
+    EXPECT_REF(collection, 3);
+    IXMLDOMSchemaCollection_Release(collection);
+
+    len = -1;
+    hr = IXMLDOMSchemaCollection_get_length(collection, &len);
+    EXPECT_HR(hr, S_OK);
+    ok(len == 0, "got %d\n", len);
+    IXMLDOMSchemaCollection_Release(collection);
+
+    /* now with document */
+    hr = IXMLDOMDocument2_loadXML(doc, _bstr_(namespacesA), &b);
+    EXPECT_HR(hr, S_OK);
+
+    hr = IXMLDOMDocument2_get_namespaces(doc, &collection);
+    EXPECT_HR(hr, S_OK);
+
+    len = -1;
+    hr = IXMLDOMSchemaCollection_get_length(collection, &len);
+    EXPECT_HR(hr, S_OK);
+    ok(len == 2, "got %d\n", len);
+
+    /* try to lookup some uris */
+    node = (void*)0xdeadbeef;
+    hr = IXMLDOMSchemaCollection_get(collection, _bstr_("http://blah.org"), &node);
+    EXPECT_HR(hr, E_NOTIMPL);
+    ok(node == (void*)0xdeadbeef, "got %p\n", node);
+
+    /* load schema and try to add it */
+    doc2 = create_document(&IID_IXMLDOMDocument2);
+    hr = IXMLDOMDocument2_loadXML(doc2, _bstr_(xsd_schema1_xml), &b);
+    EXPECT_HR(hr, S_OK);
+
+    V_VT(&v) = VT_DISPATCH;
+    V_DISPATCH(&v) = (IDispatch*)doc2;
+    hr = IXMLDOMSchemaCollection_add(collection, _bstr_(xsd_schema1_uri), v);
+    EXPECT_HR(hr, E_FAIL);
+    IXMLDOMSchemaCollection_Release(doc2);
+
+    hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 0, &s);
+    EXPECT_HR(hr, S_OK);
+    ok(!lstrcmpW(s, _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(s));
+    SysFreeString(s);
+
+    hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 1, &s);
+    EXPECT_HR(hr, S_OK);
+    ok(!lstrcmpW(s, _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(s));
+    SysFreeString(s);
+
+    s = (void*)0xdeadbeef;
+    hr = IXMLDOMSchemaCollection_get_namespaceURI(collection, 2, &s);
+    EXPECT_HR(hr, E_FAIL);
+    ok(s == (void*)0xdeadbeef, "got %p\n", s);
+
+    /* enumerate */
+    enumv = (void*)0xdeadbeef;
+    hr = IXMLDOMSchemaCollection_get__newEnum(collection, (IUnknown**)&enumv);
+    EXPECT_HR(hr, S_OK);
+    ok(enumv != NULL, "got %p\n", enumv);
+
+    V_VT(&v) = VT_EMPTY;
+    hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
+    EXPECT_HR(hr, S_OK);
+    ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
+    ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
+    VariantClear(&v);
+
+    V_VT(&v) = VT_EMPTY;
+    hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
+    EXPECT_HR(hr, S_OK);
+    ok(V_VT(&v) == VT_BSTR, "got %d\n", V_VT(&v));
+    ok(!lstrcmpW(V_BSTR(&v), _bstr_("http://blahblah.org")), "got %s\n", wine_dbgstr_w(V_BSTR(&v)));
+    VariantClear(&v);
+
+    V_VT(&v) = VT_NULL;
+    hr = IEnumVARIANT_Next(enumv, 1, &v, NULL);
+    EXPECT_HR(hr, S_FALSE);
+    ok(V_VT(&v) == VT_EMPTY, "got %d\n", V_VT(&v));
+
+    IEnumVARIANT_Release(enumv);
+    IXMLDOMSchemaCollection_Release(collection);
+    IXMLDOMDocument2_Release(doc);
     free_bstrs();
 }
 
diff --git a/dlls/msxml3/tests/schema.c b/dlls/msxml3/tests/schema.c
index b394186..48e9d4d 100644
--- a/dlls/msxml3/tests/schema.c
+++ b/dlls/msxml3/tests/schema.c
@@ -1477,11 +1477,9 @@ static void test_dispex(void)
 
 static void test_get(void)
 {
-    static const WCHAR uriW[] = {'u','r','i',0};
     IXMLDOMSchemaCollection2 *cache;
     IXMLDOMNode *node;
     HRESULT hr;
-    BSTR s;
 
     cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection2);
     if (!cache) return;
@@ -1489,10 +1487,8 @@ static void test_get(void)
     hr = IXMLDOMSchemaCollection2_get(cache, NULL, NULL);
     EXPECT_HR(hr, E_NOTIMPL);
 
-    s = SysAllocString(uriW);
-    hr = IXMLDOMSchemaCollection2_get(cache, s, &node);
+    hr = IXMLDOMSchemaCollection2_get(cache, _bstr_("uri"), &node);
     EXPECT_HR(hr, E_NOTIMPL);
-    SysFreeString(s);
 
     IXMLDOMSchemaCollection2_Release(cache);
 
@@ -1502,12 +1498,103 @@ static void test_get(void)
     hr = IXMLDOMSchemaCollection2_get(cache, NULL, NULL);
     EXPECT_HR(hr, E_POINTER);
 
-    s = SysAllocString(uriW);
-    hr = IXMLDOMSchemaCollection2_get(cache, s, &node);
+    hr = IXMLDOMSchemaCollection2_get(cache, _bstr_("uri"), &node);
     EXPECT_HR(hr, S_OK);
-    SysFreeString(s);
 
     IXMLDOMSchemaCollection2_Release(cache);
+    free_bstrs();
+}
+
+static void test_remove(void)
+{
+    IXMLDOMSchemaCollection2 *cache;
+    IXMLDOMDocument *doc;
+    VARIANT_BOOL b;
+    HRESULT hr;
+    VARIANT v;
+    LONG len;
+
+    cache = create_cache_version(60, &IID_IXMLDOMSchemaCollection2);
+    if (!cache) return;
+
+    doc = create_document_version(60, &IID_IXMLDOMDocument);
+    ok(doc != NULL, "got %p\n", doc);
+
+    hr = IXMLDOMDocument_loadXML(doc, _bstr_(xsd_schema1_xml), &b);
+    EXPECT_HR(hr, S_OK);
+
+    V_VT(&v) = VT_DISPATCH;
+    V_DISPATCH(&v) = (IDispatch*)doc;
+    hr = IXMLDOMSchemaCollection2_add(cache, _bstr_(xsd_schema1_uri), v);
+    EXPECT_HR(hr, S_OK);
+
+    len = -1;
+    hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
+    EXPECT_HR(hr, S_OK);
+    ok(len == 1, "got %d\n", len);
+
+    /* ::remove() is a stub for version 6 */
+    hr = IXMLDOMSchemaCollection2_remove(cache, NULL);
+    EXPECT_HR(hr, E_NOTIMPL);
+
+    hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_("invaliduri"));
+    EXPECT_HR(hr, E_NOTIMPL);
+
+    hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_(xsd_schema1_uri));
+    EXPECT_HR(hr, E_NOTIMPL);
+
+    len = -1;
+    hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
+    EXPECT_HR(hr, S_OK);
+    ok(len == 1, "got %d\n", len);
+
+    IXMLDOMDocument_Release(doc);
+    IXMLDOMSchemaCollection2_Release(cache);
+    free_bstrs();
+
+    /* ::remove() works for version 4 */
+    cache = create_cache_version(40, &IID_IXMLDOMSchemaCollection2);
+    if (!cache) return;
+
+    doc = create_document_version(40, &IID_IXMLDOMDocument);
+    ok(doc != NULL, "got %p\n", doc);
+
+    hr = IXMLDOMDocument_loadXML(doc, _bstr_(xsd_schema1_xml), &b);
+    EXPECT_HR(hr, S_OK);
+
+    V_VT(&v) = VT_DISPATCH;
+    V_DISPATCH(&v) = (IDispatch*)doc;
+    hr = IXMLDOMSchemaCollection2_add(cache, _bstr_(xsd_schema1_uri), v);
+    EXPECT_HR(hr, S_OK);
+
+    len = -1;
+    hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
+    EXPECT_HR(hr, S_OK);
+    ok(len == 1, "got %d\n", len);
+
+    hr = IXMLDOMSchemaCollection2_remove(cache, NULL);
+    EXPECT_HR(hr, S_OK);
+
+    hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_("invaliduri"));
+    EXPECT_HR(hr, S_OK);
+
+    len = -1;
+    hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
+    EXPECT_HR(hr, S_OK);
+    ok(len == 1, "got %d\n", len);
+
+    hr = IXMLDOMSchemaCollection2_remove(cache, _bstr_(xsd_schema1_uri));
+    EXPECT_HR(hr, S_OK);
+
+    len = -1;
+    hr = IXMLDOMSchemaCollection2_get_length(cache, &len);
+    EXPECT_HR(hr, S_OK);
+    ok(len == 0, "got %d\n", len);
+
+    IXMLDOMDocument_Release(doc);
+    IXMLDOMSchemaCollection2_Release(cache);
+
+    free_bstrs();
 }
 
 START_TEST(schema)
@@ -1526,6 +1613,7 @@ START_TEST(schema)
     test_validate_on_load();
     test_dispex();
     test_get();
+    test_remove();
 
     CoUninitialize();
 }
-- 
1.5.6.5


