2010-10-20 17:12:46 +02:00
|
|
|
// Copyright (c) 2010 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2011-12-23 18:36:30 +01:00
|
|
|
#include "include/cef_stream.h"
|
|
|
|
#include "include/cef_xml_reader.h"
|
|
|
|
#include "include/wrapper/cef_xml_object.h"
|
2010-10-20 17:12:46 +02:00
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
char g_test_xml[] =
|
|
|
|
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
|
|
|
|
"<?my_instruction my_value?>\n"
|
|
|
|
"<!DOCTYPE my_document SYSTEM \"example.dtd\" [\n"
|
|
|
|
" <!ENTITY EA \"EA Value\">\n"
|
|
|
|
" <!ENTITY EB \"EB Value\">\n"
|
|
|
|
"]>\n"
|
|
|
|
"<ns:obj xmlns:ns=\"http://www.example.org/ns\">\n"
|
|
|
|
" <ns:objA>value A</ns:objA>\n"
|
|
|
|
" <!-- my comment -->\n"
|
|
|
|
" <ns:objB>\n"
|
|
|
|
" <ns:objB_1>value B1</ns:objB_1>\n"
|
|
|
|
" <ns:objB_2><![CDATA[some <br/> data]]></ns:objB_2>\n"
|
|
|
|
" <ns:objB_3>&EB;</ns:objB_3>\n"
|
|
|
|
" <ns:objB_4><b>this is</b> mixed content &EA;</ns:objB_4>\n"
|
|
|
|
" </ns:objB>\n"
|
|
|
|
" <ns:objC ns:attr1=\"value C1\" ns:attr2=\"value C2\"/><ns:objD></ns:objD>\n"
|
|
|
|
"</ns:obj>\n";
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Test XML reading
|
|
|
|
TEST(XmlReaderTest, Read)
|
|
|
|
{
|
|
|
|
// Create the stream reader.
|
|
|
|
CefRefPtr<CefStreamReader> stream(
|
|
|
|
CefStreamReader::CreateForData(g_test_xml, sizeof(g_test_xml) - 1));
|
|
|
|
ASSERT_TRUE(stream.get() != NULL);
|
|
|
|
|
|
|
|
// Create the XML reader.
|
|
|
|
CefRefPtr<CefXmlReader> reader(
|
|
|
|
CefXmlReader::Create(stream, XML_ENCODING_NONE,
|
2010-11-22 18:49:46 +01:00
|
|
|
"http://www.example.org/example.xml"));
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader.get() != NULL);
|
|
|
|
|
|
|
|
// Move to the processing instruction node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 0);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_PROCESSING_INSTRUCTION);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "my_instruction");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "my_instruction");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "my_value");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the DOCTYPE node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 0);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_DOCUMENT_TYPE);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "my_document");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "my_document");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to ns:obj element start node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 0);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "obj");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:obj");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasAttributes());
|
2010-11-15 16:39:56 +01:00
|
|
|
ASSERT_EQ(reader->GetAttributeCount(), (size_t)1);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetAttribute(0), "http://www.example.org/ns");
|
|
|
|
ASSERT_EQ(reader->GetAttribute("xmlns:ns"), "http://www.example.org/ns");
|
|
|
|
ASSERT_EQ(reader->GetAttribute("ns", "http://www.w3.org/2000/xmlns/"),
|
|
|
|
"http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the whitespace node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
|
|
|
|
|
|
|
|
// Move to the ns:objA element start node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 1);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objA");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objA");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the ns:objA value node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_TEXT);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "#text");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "#text");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "value A");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the ns:objA element ending node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 1);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objA");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objA");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the whitespace node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 1);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
|
|
|
|
|
|
|
|
// Move to the comment node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 1);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_COMMENT);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "#comment");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "#comment");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), " my comment ");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the whitespace node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
|
|
|
|
|
|
|
|
// Move to the ns:objB element start node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 1);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objB");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the whitespace node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
|
|
|
|
|
|
|
|
// Move to the ns:objB_1 element start node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objB_1");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_1");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the ns:objB_1 value node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 3);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_TEXT);
|
|
|
|
ASSERT_TRUE(reader->HasValue());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "value B1");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the ns:objB_1 element ending node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objB_1");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_1");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the whitespace node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
|
|
|
|
|
|
|
|
// Move to the ns:objB_2 element start node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objB_2");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_2");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the ns:objB_2 value node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 3);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_CDATA);
|
|
|
|
ASSERT_TRUE(reader->HasValue());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "some <br/> data");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the ns:objB_2 element ending node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objB_2");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_2");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the whitespace node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
|
|
|
|
|
|
|
|
// Move to the ns:objB_3 element start node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objB_3");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_3");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the EB entity reference node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 3);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ENTITY_REFERENCE);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "EB");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "EB");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "EB Value");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the ns:objB_3 element ending node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objB_3");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_3");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the whitespace node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
|
|
|
|
|
|
|
|
// Move to the ns:objB_4 element start node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objB_4");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_4");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetInnerXml(), "<b>this is</b> mixed content &EA;");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetOuterXml(),
|
2010-11-22 18:49:46 +01:00
|
|
|
"<ns:objB_4 xmlns:ns=\"http://www.example.org/ns\">"
|
|
|
|
"<b>this is</b> mixed content &EA;</ns:objB_4>");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the <b> element node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 3);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "b");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "b");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the text node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 4);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_TEXT);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "#text");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "#text");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "this is");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the </b> element node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 3);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "b");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "b");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the text node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 3);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_TEXT);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "#text");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "#text");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), " mixed content ");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the EA entity reference node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 3);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ENTITY_REFERENCE);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "EA");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "EA");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "EA Value");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the ns:objB_4 element ending node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objB_4");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB_4");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the whitespace node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
|
|
|
|
|
|
|
|
// Move to the ns:objB element ending node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 1);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objB");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objB");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the whitespace node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
|
|
|
|
|
|
|
|
// Move to the ns:objC element start node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 1);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objC");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objC");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->IsEmptyElement());
|
|
|
|
ASSERT_TRUE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
2010-11-15 16:39:56 +01:00
|
|
|
ASSERT_EQ(reader->GetAttributeCount(), (size_t)2);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetAttribute(0), "value C1");
|
|
|
|
ASSERT_EQ(reader->GetAttribute("ns:attr1"), "value C1");
|
|
|
|
ASSERT_EQ(reader->GetAttribute("attr1", "http://www.example.org/ns"),
|
|
|
|
"value C1");
|
|
|
|
ASSERT_EQ(reader->GetAttribute(1), "value C2");
|
|
|
|
ASSERT_EQ(reader->GetAttribute("ns:attr2"), "value C2");
|
|
|
|
ASSERT_EQ(reader->GetAttribute("attr2", "http://www.example.org/ns"),
|
|
|
|
"value C2");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the ns:attr1 attribute.
|
|
|
|
ASSERT_TRUE(reader->MoveToFirstAttribute());
|
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ATTRIBUTE);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "attr1");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:attr1");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "value C1");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the ns:attr2 attribute.
|
|
|
|
ASSERT_TRUE(reader->MoveToNextAttribute());
|
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ATTRIBUTE);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "attr2");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:attr2");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "value C2");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// No more attributes.
|
|
|
|
ASSERT_FALSE(reader->MoveToNextAttribute());
|
|
|
|
|
|
|
|
// Return to the ns:objC element start node.
|
|
|
|
ASSERT_TRUE(reader->MoveToCarryingElement());
|
|
|
|
ASSERT_EQ(reader->GetDepth(), 1);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objC");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the ns:attr1 attribute.
|
|
|
|
ASSERT_TRUE(reader->MoveToAttribute(0));
|
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ATTRIBUTE);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "attr1");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:attr1");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "value C1");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Return to the ns:objC element start node.
|
|
|
|
ASSERT_TRUE(reader->MoveToCarryingElement());
|
|
|
|
ASSERT_EQ(reader->GetDepth(), 1);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objC");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the ns:attr2 attribute.
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_TRUE(reader->MoveToAttribute("ns:attr2"));
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ATTRIBUTE);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "attr2");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:attr2");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "value C2");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the ns:attr1 attribute without returning to the ns:objC element.
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_TRUE(reader->MoveToAttribute("attr1", "http://www.example.org/ns"));
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 2);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ATTRIBUTE);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "attr1");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:attr1");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasValue());
|
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetValue(), "value C1");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Move to the ns:objD element start node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 1);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_START);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objD");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objD");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the ns:objD element end node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 1);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "objD");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:objD");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_FALSE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
|
|
|
|
// Move to the whitespace node without returning to the ns:objC element.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_WHITESPACE);
|
|
|
|
|
|
|
|
// Move to ns:obj element ending node.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_TRUE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(reader->GetDepth(), 0);
|
|
|
|
ASSERT_EQ(reader->GetType(), XML_NODE_ELEMENT_END);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(reader->GetLocalName(), "obj");
|
|
|
|
ASSERT_EQ(reader->GetPrefix(), "ns");
|
|
|
|
ASSERT_EQ(reader->GetQualifiedName(), "ns:obj");
|
|
|
|
ASSERT_EQ(reader->GetNamespaceURI(), "http://www.example.org/ns");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(reader->IsEmptyElement());
|
|
|
|
ASSERT_TRUE(reader->HasAttributes());
|
|
|
|
ASSERT_FALSE(reader->HasValue());
|
|
|
|
// Strangely, the end node will report if the starting node has attributes
|
|
|
|
// but will not provide access to them.
|
|
|
|
ASSERT_TRUE(reader->HasAttributes());
|
2010-11-15 16:39:56 +01:00
|
|
|
ASSERT_EQ(reader->GetAttributeCount(), (size_t)0);
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// And we're done.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_FALSE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
ASSERT_TRUE(reader->Close());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test XML read error handling.
|
|
|
|
TEST(XmlReaderTest, ReadError)
|
|
|
|
{
|
|
|
|
char test_str[] =
|
|
|
|
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
|
|
|
|
"<!ATTRIBUTE foo bar>\n";
|
|
|
|
|
|
|
|
// Create the stream reader.
|
|
|
|
CefRefPtr<CefStreamReader> stream(
|
|
|
|
CefStreamReader::CreateForData(test_str, sizeof(test_str) - 1));
|
|
|
|
ASSERT_TRUE(stream.get() != NULL);
|
|
|
|
|
|
|
|
// Create the XML reader.
|
|
|
|
CefRefPtr<CefXmlReader> reader(
|
|
|
|
CefXmlReader::Create(stream, XML_ENCODING_NONE,
|
2010-11-22 18:49:46 +01:00
|
|
|
"http://www.example.org/example.xml"));
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader.get() != NULL);
|
|
|
|
|
|
|
|
// Move to the processing instruction node and generate parser error.
|
2010-10-21 17:19:43 +02:00
|
|
|
ASSERT_FALSE(reader->MoveToNextNode());
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(reader->HasError());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test XmlObject load behavior.
|
|
|
|
TEST(XmlReaderTest, ObjectLoad)
|
|
|
|
{
|
|
|
|
// Create the stream reader.
|
|
|
|
CefRefPtr<CefStreamReader> stream(
|
|
|
|
CefStreamReader::CreateForData(g_test_xml, sizeof(g_test_xml) - 1));
|
|
|
|
ASSERT_TRUE(stream.get() != NULL);
|
|
|
|
|
|
|
|
// Create the XML reader.
|
2010-11-22 18:49:46 +01:00
|
|
|
CefRefPtr<CefXmlObject> object(new CefXmlObject("object"));
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(object->Load(stream, XML_ENCODING_NONE,
|
2010-11-22 18:49:46 +01:00
|
|
|
"http://www.example.org/example.xml", NULL));
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
ASSERT_FALSE(object->HasAttributes());
|
|
|
|
ASSERT_TRUE(object->HasChildren());
|
2010-11-15 16:39:56 +01:00
|
|
|
ASSERT_EQ(object->GetChildCount(), (size_t)1);
|
2010-10-20 17:12:46 +02:00
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CefRefPtr<CefXmlObject> obj(object->FindChild("ns:obj"));
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(obj.get());
|
|
|
|
ASSERT_TRUE(obj->HasChildren());
|
2010-11-15 16:39:56 +01:00
|
|
|
ASSERT_EQ(obj->GetChildCount(), (size_t)4);
|
2010-10-20 17:12:46 +02:00
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CefRefPtr<CefXmlObject> obj_child(obj->FindChild("ns:objC"));
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(obj_child.get());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(obj_child->GetName(), "ns:objC");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(obj_child->HasChildren());
|
|
|
|
ASSERT_FALSE(obj_child->HasValue());
|
|
|
|
ASSERT_TRUE(obj_child->HasAttributes());
|
|
|
|
|
|
|
|
CefXmlObject::ObjectVector obj_children;
|
2010-11-15 16:39:56 +01:00
|
|
|
ASSERT_EQ(obj->GetChildren(obj_children), (size_t)4);
|
|
|
|
ASSERT_EQ(obj_children.size(), (size_t)4);
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
CefXmlObject::ObjectVector::const_iterator it = obj_children.begin();
|
|
|
|
for (int ct = 0; it != obj_children.end(); ++it, ++ct) {
|
|
|
|
obj_child = *it;
|
|
|
|
ASSERT_TRUE(obj_child.get());
|
|
|
|
if (ct == 0) {
|
|
|
|
// ns:objA
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(obj_child->GetName(), "ns:objA");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(obj_child->HasChildren());
|
|
|
|
ASSERT_TRUE(obj_child->HasValue());
|
|
|
|
ASSERT_FALSE(obj_child->HasAttributes());
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(obj_child->GetValue(), "value A");
|
2010-10-20 17:12:46 +02:00
|
|
|
} else if (ct == 1) {
|
|
|
|
// ns:objB
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(obj_child->GetName(), "ns:objB");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(obj_child->HasChildren());
|
|
|
|
ASSERT_FALSE(obj_child->HasValue());
|
|
|
|
ASSERT_FALSE(obj_child->HasAttributes());
|
2010-11-15 16:39:56 +01:00
|
|
|
ASSERT_EQ(obj_child->GetChildCount(), (size_t)4);
|
2010-11-22 18:49:46 +01:00
|
|
|
obj_child = obj_child->FindChild("ns:objB_4");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_TRUE(obj_child.get());
|
|
|
|
ASSERT_TRUE(obj_child->HasValue());
|
|
|
|
ASSERT_EQ(obj_child->GetValue(),
|
2010-11-22 18:49:46 +01:00
|
|
|
"<b>this is</b> mixed content EA Value");
|
2010-10-20 17:12:46 +02:00
|
|
|
} else if (ct == 2) {
|
|
|
|
// ns:objC
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(obj_child->GetName(), "ns:objC");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(obj_child->HasChildren());
|
|
|
|
ASSERT_FALSE(obj_child->HasValue());
|
|
|
|
ASSERT_TRUE(obj_child->HasAttributes());
|
|
|
|
|
|
|
|
CefXmlObject::AttributeMap attribs;
|
2010-11-15 16:39:56 +01:00
|
|
|
ASSERT_EQ(obj_child->GetAttributes(attribs), (size_t)2);
|
|
|
|
ASSERT_EQ(attribs.size(), (size_t)2);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(attribs["ns:attr1"], "value C1");
|
|
|
|
ASSERT_EQ(attribs["ns:attr2"], "value C2");
|
2010-10-20 17:12:46 +02:00
|
|
|
|
2010-11-15 16:39:56 +01:00
|
|
|
ASSERT_EQ(obj_child->GetAttributeCount(), (size_t)2);
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_TRUE(obj_child->HasAttribute("ns:attr1"));
|
|
|
|
ASSERT_EQ(obj_child->GetAttributeValue("ns:attr1"), "value C1");
|
|
|
|
ASSERT_TRUE(obj_child->HasAttribute("ns:attr2"));
|
|
|
|
ASSERT_EQ(obj_child->GetAttributeValue("ns:attr2"), "value C2");
|
2010-10-20 17:12:46 +02:00
|
|
|
} else if (ct == 3) {
|
|
|
|
// ns:objD
|
2010-11-22 18:49:46 +01:00
|
|
|
ASSERT_EQ(obj_child->GetName(), "ns:objD");
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(obj_child->HasChildren());
|
|
|
|
ASSERT_FALSE(obj_child->HasValue());
|
|
|
|
ASSERT_FALSE(obj_child->HasAttributes());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test XmlObject load error handling behavior.
|
|
|
|
TEST(XmlReaderTest, ObjectLoadError)
|
|
|
|
{
|
|
|
|
// Test start/end tag mismatch error.
|
|
|
|
{
|
|
|
|
char error_xml[] = "<obj>\n<foo>\n</obj>\n</foo>";
|
|
|
|
|
|
|
|
// Create the stream reader.
|
|
|
|
CefRefPtr<CefStreamReader> stream(
|
|
|
|
CefStreamReader::CreateForData(error_xml, sizeof(error_xml) - 1));
|
|
|
|
ASSERT_TRUE(stream.get() != NULL);
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CefString error_str;
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Create the XML reader.
|
2010-11-22 18:49:46 +01:00
|
|
|
CefRefPtr<CefXmlObject> object(new CefXmlObject("object"));
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(object->Load(stream, XML_ENCODING_NONE,
|
2010-11-22 18:49:46 +01:00
|
|
|
"http://www.example.org/example.xml", &error_str));
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(error_str,
|
2010-11-22 18:49:46 +01:00
|
|
|
"Opening and ending tag mismatch: foo line 2 and obj, line 3");
|
2010-10-20 17:12:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test value following child error.
|
|
|
|
{
|
|
|
|
char error_xml[] = "<obj>\n<foo>\n</foo>disallowed value\n</obj>";
|
|
|
|
|
|
|
|
// Create the stream reader.
|
|
|
|
CefRefPtr<CefStreamReader> stream(
|
|
|
|
CefStreamReader::CreateForData(error_xml, sizeof(error_xml) - 1));
|
|
|
|
ASSERT_TRUE(stream.get() != NULL);
|
|
|
|
|
2010-11-22 18:49:46 +01:00
|
|
|
CefString error_str;
|
2010-10-20 17:12:46 +02:00
|
|
|
|
|
|
|
// Create the XML reader.
|
2010-11-22 18:49:46 +01:00
|
|
|
CefRefPtr<CefXmlObject> object(new CefXmlObject("object"));
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_FALSE(object->Load(stream, XML_ENCODING_NONE,
|
2010-11-22 18:49:46 +01:00
|
|
|
"http://www.example.org/example.xml", &error_str));
|
2010-10-20 17:12:46 +02:00
|
|
|
ASSERT_EQ(error_str,
|
2010-11-22 18:49:46 +01:00
|
|
|
"Value following child element, line 4");
|
2010-10-20 17:12:46 +02:00
|
|
|
}
|
|
|
|
}
|