Piotr Caban : msxml3/tests: Added element attributes tests when SAXXMLReader is used.

Alexandre Julliard julliard at winehq.org
Wed Oct 26 12:35:47 CDT 2011


Module: wine
Branch: master
Commit: df5d3e348a8036f3f8b536c9ccf4fb4ca964fb39
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=df5d3e348a8036f3f8b536c9ccf4fb4ca964fb39

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Wed Oct 26 13:25:52 2011 +0200

msxml3/tests: Added element attributes tests when SAXXMLReader is used.

---

 dlls/msxml3/tests/saxreader.c |  130 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 129 insertions(+), 1 deletions(-)

diff --git a/dlls/msxml3/tests/saxreader.c b/dlls/msxml3/tests/saxreader.c
index ca9c4aa..973381b 100644
--- a/dlls/msxml3/tests/saxreader.c
+++ b/dlls/msxml3/tests/saxreader.c
@@ -121,6 +121,11 @@ static const CHAR szTestXML[] =
 "   <Name>Captain Ahab</Name>\n"
 "</BankAccount>\n";
 
+static const CHAR szTestAttributes[] =
+"<?xml version=\"1.0\" ?>\n"
+"<document xmlns:test=\"prefix_test\" xmlns=\"prefix\" test:arg1=\"arg1\" arg2=\"arg2\">\n"
+"</document>\n";
+
 typedef struct _contenthandlercheck {
     CH id;
     int line;
@@ -202,6 +207,34 @@ static content_handler_test contentHandlerTestCallbackResult6[] = {
     { CH_ENDTEST }
 };
 
+static content_handler_test contentHandlerTestAttributes[] = {
+    { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0 },
+    { CH_STARTDOCUMENT, 0, 0, 1, 22 },
+    { CH_STARTPREFIXMAPPING, 2, 80, 2, 79, "test", "prefix_test" },
+    { CH_STARTPREFIXMAPPING, 2, 80, 2, 79, "", "prefix" },
+    { CH_STARTELEMENT, 2, 80, 2, 79, "prefix", "document", "document" },
+    { CH_CHARACTERS, 2, 80, 3, 1, "\n" },
+    { CH_ENDELEMENT, 3, 3, 3, 11, "prefix", "document", "document" },
+    { CH_ENDPREFIXMAPPING, 3, 3, 3, 11, "" },
+    { CH_ENDPREFIXMAPPING, 3, 3, 3, 11, "test" },
+    { CH_ENDDOCUMENT, 0, 0, 4, 0 },
+    { CH_ENDTEST }
+};
+
+static content_handler_test contentHandlerTestAttributes6[] = {
+    { CH_PUTDOCUMENTLOCATOR, 0, 0, 1, 0 },
+    { CH_STARTDOCUMENT, 0, 0, 1, 22 },
+    { CH_STARTPREFIXMAPPING, 2, 80, 2, 79, "test", "prefix_test" },
+    { CH_STARTPREFIXMAPPING, 2, 80, 2, 79, "", "prefix" },
+    { CH_STARTELEMENT, 2, 80, 2, 79, "prefix", "document", "document" },
+    { CH_CHARACTERS, 2, 80, 3, 1, "\n" },
+    { CH_ENDELEMENT, 3, 3, 3, 11, "prefix", "document", "document" },
+    { CH_ENDPREFIXMAPPING, 3, 3, 3, 11, "test" },
+    { CH_ENDPREFIXMAPPING, 3, 3, 3, 11, "" },
+    { CH_ENDDOCUMENT, 0, 0, 4, 0 },
+    { CH_ENDTEST }
+};
+
 static content_handler_test *expectCall;
 static ISAXLocator *locator;
 int msxml_version;
@@ -321,7 +354,7 @@ static HRESULT WINAPI contentHandler_startPrefixMapping(
         const WCHAR *pUri,
         int nUri)
 {
-    if(!test_expect_call(CH_ENDDOCUMENT))
+    if(!test_expect_call(CH_STARTPREFIXMAPPING))
         return E_FAIL;
 
     test_saxstr(__LINE__, pPrefix, nPrefix, expectCall->arg1);
@@ -357,6 +390,9 @@ static HRESULT WINAPI contentHandler_startElement(
         int nQName,
         ISAXAttributes *pAttr)
 {
+    int len;
+    HRESULT hres;
+
     if(!test_expect_call(CH_STARTELEMENT))
         return E_FAIL;
 
@@ -366,6 +402,79 @@ static HRESULT WINAPI contentHandler_startElement(
     test_locator(__LINE__, msxml_version>=6 ? expectCall->line_v6 : expectCall->line,
             msxml_version>=6 ? expectCall->column_v6 : expectCall->column);
 
+    if(expectCall == contentHandlerTestAttributes+4) {
+        int i;
+        /* msxml3 returns attributes and namespaces in the input order */
+        hres = ISAXAttributes_getLength(pAttr, &len);
+        ok(hres == S_OK, "getLength returned %x\n", hres);
+        ok(len == 4, "Incorrect number of attributes: %d\n", len);
+        ok(msxml_version < 6, "wrong msxml_version: %d\n", msxml_version);
+
+        for(i=0; i<len; i++) {
+            hres = ISAXAttributes_getName(pAttr, i, &pNamespaceUri, &nNamespaceUri,
+                    &pLocalName, &nLocalName, &pQName, &nQName);
+            ok(hres == S_OK, "getName returned %x\n", hres);
+
+            if(nQName == 4) {
+                todo_wine ok(i==3, "Incorrect attributes order\n");
+                test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
+                test_saxstr(__LINE__, pLocalName, nLocalName, "arg2");
+                test_saxstr(__LINE__, pQName, nQName, "arg2");
+            } else if(nQName == 5) {
+                todo_wine ok(i==1, "Incorrect attributes order\n");
+                test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
+                test_saxstr(__LINE__, pLocalName, nLocalName, "");
+                test_saxstr(__LINE__, pQName, nQName, "xmlns");
+            } else if(nQName == 9) {
+                todo_wine ok(i==2, "Incorrect attributes order\n");
+                test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
+                test_saxstr(__LINE__, pLocalName, nLocalName, "arg1");
+                test_saxstr(__LINE__, pQName, nQName, "test:arg1");
+            } else if(nQName == 10) {
+                todo_wine ok(i==0, "Incorrect attributes order\n");
+                test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
+                test_saxstr(__LINE__, pLocalName, nLocalName, "");
+                test_saxstr(__LINE__, pQName, nQName, "xmlns:test");
+            } else {
+                ok(0, "Unexpected attribute\n");
+            }
+        }
+    } else if(expectCall == contentHandlerTestAttributes6+4) {
+        /* msxml6 returns attributes first and then namespaces */
+        hres = ISAXAttributes_getLength(pAttr, &len);
+        ok(hres == S_OK, "getLength returned %x\n", hres);
+        ok(len == 4, "Incorrect number of attributes: %d\n", len);
+        ok(msxml_version >= 6, "wrong msxml_version: %d\n", msxml_version);
+
+        hres = ISAXAttributes_getName(pAttr, 0, &pNamespaceUri, &nNamespaceUri,
+                &pLocalName, &nLocalName, &pQName, &nQName);
+        ok(hres == S_OK, "getName returned %x\n", hres);
+        test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "prefix_test");
+        test_saxstr(__LINE__, pLocalName, nLocalName, "arg1");
+        test_saxstr(__LINE__, pQName, nQName, "test:arg1");
+
+        hres = ISAXAttributes_getName(pAttr, 1, &pNamespaceUri, &nNamespaceUri,
+                &pLocalName, &nLocalName, &pQName, &nQName);
+        ok(hres == S_OK, "getName returned %x\n", hres);
+        test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "");
+        test_saxstr(__LINE__, pLocalName, nLocalName, "arg2");
+        test_saxstr(__LINE__, pQName, nQName, "arg2");
+
+        hres = ISAXAttributes_getName(pAttr, 2, &pNamespaceUri, &nNamespaceUri,
+                &pLocalName, &nLocalName, &pQName, &nQName);
+        ok(hres == S_OK, "getName returned %x\n", hres);
+        test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "http://www.w3.org/2000/xmlns/");
+        test_saxstr(__LINE__, pLocalName, nLocalName, "");
+        test_saxstr(__LINE__, pQName, nQName, "xmlns:test");
+
+        hres = ISAXAttributes_getName(pAttr, 3, &pNamespaceUri, &nNamespaceUri,
+                &pLocalName, &nLocalName, &pQName, &nQName);
+        ok(hres == S_OK, "getName returned %x\n", hres);
+        test_saxstr(__LINE__, pNamespaceUri, nNamespaceUri, "http://www.w3.org/2000/xmlns/");
+        test_saxstr(__LINE__, pLocalName, nLocalName, "");
+        test_saxstr(__LINE__, pQName, nQName, "xmlns");
+    }
+
     return (expectCall++)->ret;
 }
 
@@ -1182,6 +1291,25 @@ static void test_saxreader(int version)
 
     IStream_Release(iStream);
 
+    CreateStreamOnHGlobal(NULL, TRUE, &iStream);
+    liSize.QuadPart = strlen(szTestAttributes);
+    IStream_SetSize(iStream, liSize);
+    IStream_Write(iStream, szTestAttributes, strlen(szTestAttributes), &bytesWritten);
+    liPos.QuadPart = 0;
+    IStream_Seek(iStream, liPos, STREAM_SEEK_SET, NULL);
+    V_VT(&var) = VT_UNKNOWN|VT_DISPATCH;
+    V_UNKNOWN(&var) = (IUnknown*)iStream;
+
+    if(version >= 6)
+        expectCall = contentHandlerTestAttributes6;
+    else
+        expectCall = contentHandlerTestAttributes;
+    hr = ISAXXMLReader_parse(reader, var);
+    ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
+    test_expect_call(CH_ENDTEST);
+
+    IStream_Release(iStream);
+
     V_VT(&var) = VT_BSTR;
     V_BSTR(&var) = SysAllocString(szCarriageRetTest);
 




More information about the wine-cvs mailing list