msxml3: Allow IXMLDOMDocument to save as another IXMLDOMDocument.
authorAlistair Leslie-Hughes <leslie_alistair@hotmail.com>
Wed, 12 Mar 2008 10:47:17 +0000 (21:47 +1100)
committerAlexandre Julliard <julliard@winehq.org>
Wed, 12 Mar 2008 11:25:19 +0000 (12:25 +0100)
dlls/msxml3/domdoc.c
dlls/msxml3/tests/domdoc.c

index fed1b8b6149b9a63b2efd06bca48ef866c7061e0..a05247ab977bd0b32efda3008c291b26369cf81e 100644 (file)
@@ -1559,12 +1559,37 @@ static HRESULT WINAPI domdoc_save(
     TRACE("(%p)->(var(vt %x, %s))\n", This, V_VT(&destination),
           V_VT(&destination) == VT_BSTR ? debugstr_w(V_BSTR(&destination)) : NULL);
 
-    if(V_VT(&destination) != VT_BSTR)
+    if(V_VT(&destination) != VT_BSTR && V_VT(&destination) != VT_UNKNOWN)
     {
-        FIXME("Unhandled vt %x\n", V_VT(&destination));
+        FIXME("Unhandled vt %d\n", V_VT(&destination));
         return S_FALSE;
     }
 
+    if(V_VT(&destination) == VT_UNKNOWN)
+    {
+        IUnknown *pUnk = V_UNKNOWN(&destination);
+        IXMLDOMDocument *pDocument;
+
+        ret = IXMLDOMDocument_QueryInterface(pUnk, &IID_IXMLDOMDocument2, (void**)&pDocument);
+        if(ret == S_OK)
+        {
+            BSTR bXML;
+            VARIANT_BOOL bSuccessful;
+
+            ret = IXMLDOMDocument_get_xml(iface, &bXML);
+            if(ret == S_OK)
+            {
+                ret = IXMLDOMDocument_loadXML(pDocument, bXML, &bSuccessful);
+
+                SysFreeString(bXML);
+            }
+
+            IXMLDOMDocument_Release(pDocument);
+        }
+
+        return ret;
+    }
+
     handle = CreateFileW( V_BSTR(&destination), GENERIC_WRITE, 0,
                           NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
     if( handle == INVALID_HANDLE_VALUE )
index c4c5b9cb04bf2c8c80d309cf41b43c3d9e1fa2e0..b59767082d0e2ade7c9219102da2ffbe02ed194b 100644 (file)
@@ -3013,6 +3013,60 @@ static void test_nodeTypeTests( void )
     free_bstrs();
 }
 
+static void test_DocumentSaveToDocument(void)
+{
+    IXMLDOMDocument *doc = NULL;
+    IXMLDOMDocument *doc2 = NULL;
+    IXMLDOMElement *pRoot;
+
+    HRESULT hr;
+
+    hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc );
+    if( hr != S_OK )
+        return;
+
+    hr = CoCreateInstance( &CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument2, (LPVOID*)&doc2 );
+    if( hr != S_OK )
+    {
+        IXMLDOMDocument_Release(doc);
+        return;
+    }
+
+    hr = IXMLDOMDocument_createElement(doc, _bstr_("Testing"), &pRoot);
+    ok(hr == S_OK, "ret %08x\n", hr );
+    if(hr == S_OK)
+    {
+        hr = IXMLDOMDocument_appendChild(doc, (IXMLDOMNode*)pRoot, NULL);
+        ok(hr == S_OK, "ret %08x\n", hr );
+        if(hr == S_OK)
+        {
+            VARIANT vDoc;
+            BSTR sOrig;
+            BSTR sNew;
+
+            V_VT(&vDoc) = VT_UNKNOWN;
+            V_UNKNOWN(&vDoc) = (IUnknown*)doc2;
+
+            hr = IXMLDOMDocument_save(doc, vDoc);
+            ok(hr == S_OK, "ret %08x\n", hr );
+
+            hr = IXMLDOMDocument_get_xml(doc, &sOrig);
+            ok(hr == S_OK, "ret %08x\n", hr );
+
+            hr = IXMLDOMDocument_get_xml(doc2, &sNew);
+            ok(hr == S_OK, "ret %08x\n", hr );
+
+            ok( !lstrcmpW( sOrig, sNew ), "New document is not the same as origial\n");
+
+            SysFreeString(sOrig);
+            SysFreeString(sNew);
+        }
+    }
+
+    IXMLDOMDocument_Release(doc2);
+    IXMLDOMDocument_Release(doc);
+}
+
 START_TEST(domdoc)
 {
     HRESULT r;
@@ -3034,6 +3088,7 @@ START_TEST(domdoc)
     test_cloneNode();
     test_xmlTypes();
     test_nodeTypeTests();
+    test_DocumentSaveToDocument();
 
     CoUninitialize();
 }