2 * Copyright 2001-2005 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 #include "XMLObjectBaseTestCase.h"
\r
20 #include <xercesc/util/XMLUniDefs.hpp>
\r
22 const XMLCh SimpleXMLObject::NAMESPACE[] = {
\r
23 chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,
\r
24 chLatin_w, chLatin_w, chLatin_w, chPeriod,
\r
25 chLatin_e, chLatin_x, chLatin_a, chLatin_m, chLatin_p, chLatin_l, chLatin_e, chPeriod,
\r
26 chLatin_o, chLatin_r, chLatin_g, chForwardSlash,
\r
27 chLatin_t, chLatin_e, chLatin_s, chLatin_t,
\r
28 chLatin_O, chLatin_b, chLatin_j, chLatin_e, chLatin_c, chLatin_t, chLatin_s, chNull
\r
31 const XMLCh SimpleXMLObject::NAMESPACE_PREFIX[] = {
\r
32 chLatin_t, chLatin_e, chLatin_s, chLatin_t, chNull
\r
35 const XMLCh SimpleXMLObject::LOCAL_NAME[] = {
\r
36 chLatin_S, chLatin_i, chLatin_m, chLatin_p, chLatin_l, chLatin_e,
\r
37 chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull
\r
40 const XMLCh SimpleXMLObject::DERIVED_NAME[] = {
\r
41 chLatin_D, chLatin_e, chLatin_r, chLatin_i, chLatin_v, chLatin_e, chLatin_d,
\r
42 chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull
\r
45 const XMLCh SimpleXMLObject::TYPE_NAME[] = {
\r
46 chLatin_S, chLatin_i, chLatin_m, chLatin_p, chLatin_l, chLatin_e,
\r
47 chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t,
\r
48 chLatin_T, chLatin_y, chLatin_p, chLatin_e, chNull
\r
51 const XMLCh SimpleXMLObject::ID_ATTRIB_NAME[] = {
\r
52 chLatin_I, chLatin_d, chNull
\r
55 class UnmarshallingTest : public CxxTest::TestSuite {
\r
59 UnmarshallingTest() : m_qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME,SimpleXMLObject::NAMESPACE_PREFIX),
\r
60 m_qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME,SimpleXMLObject::NAMESPACE_PREFIX) {}
\r
63 XMLObjectBuilder::registerBuilder(m_qname, new SimpleXMLObjectBuilder());
\r
64 XMLObjectBuilder::registerBuilder(m_qtype, new SimpleXMLObjectBuilder());
\r
68 XMLObjectBuilder::deregisterBuilder(m_qname);
\r
69 XMLObjectBuilder::deregisterBuilder(m_qtype);
\r
72 void testUnmarshallingWithAttributes() {
\r
73 TS_TRACE("testUnmarshallingWithAttributes");
\r
75 string path=data_path + "SimpleXMLObjectWithAttribute.xml";
\r
76 ifstream fs(path.c_str());
\r
77 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
78 TS_ASSERT(doc!=NULL);
\r
80 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
83 auto_ptr<SimpleXMLObject> sxObject(
\r
84 dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))
\r
86 TS_ASSERT(sxObject.get()!=NULL);
\r
88 auto_ptr_XMLCh expected("Firefly");
\r
89 TSM_ASSERT_SAME_DATA("ID was not expected value", expected.get(), sxObject->getId(), XMLString::stringLen(expected.get()));
\r
92 void testUnmarshallingWithElementContent() {
\r
93 TS_TRACE("testUnmarshallingWithElementContent");
\r
95 string path=data_path + "SimpleXMLObjectWithContent.xml";
\r
96 ifstream fs(path.c_str());
\r
97 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
98 TS_ASSERT(doc!=NULL);
\r
100 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
101 TS_ASSERT(b!=NULL);
\r
103 auto_ptr<SimpleXMLObject> sxObject(
\r
104 dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))
\r
106 TS_ASSERT(sxObject.get()!=NULL);
\r
108 auto_ptr_XMLCh expected("Sample Content");
\r
109 TSM_ASSERT_SAME_DATA("Element content was not expected value", expected.get(), sxObject->getValue(), XMLString::stringLen(expected.get()));
\r
112 void testUnmarshallingWithChildElements() {
\r
113 TS_TRACE("testUnmarshallingWithChildElements");
\r
115 string path=data_path + "SimpleXMLObjectWithChildren.xml";
\r
116 ifstream fs(path.c_str());
\r
117 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
118 TS_ASSERT(doc!=NULL);
\r
120 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
121 TS_ASSERT(b!=NULL);
\r
123 auto_ptr<SimpleXMLObject> sxObject(
\r
124 dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))
\r
126 TS_ASSERT(sxObject.get()!=NULL);
\r
128 VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects();
\r
129 TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, kids.size());
\r
130 TSM_ASSERT_EQUALS("Child's schema type was not expected value", m_qtype, *(kids.back()->getSchemaType()));
\r
133 void testUnmarshallingWithClone() {
\r
134 TS_TRACE("testUnmarshallingWithClone");
\r
136 string path=data_path + "SimpleXMLObjectWithChildren.xml";
\r
137 ifstream fs(path.c_str());
\r
138 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
139 TS_ASSERT(doc!=NULL);
\r
141 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
142 TS_ASSERT(b!=NULL);
\r
144 auto_ptr<SimpleXMLObject> sxObject(
\r
145 dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))
\r
147 TS_ASSERT(sxObject.get()!=NULL);
\r
149 sxObject->releaseThisAndChildrenDOM();
\r
150 auto_ptr<SimpleXMLObject> clonedObject(sxObject->clone());
\r
152 VectorOf(SimpleXMLObject) kids=clonedObject->getSimpleXMLObjects();
\r
153 TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, kids.size());
\r
154 TSM_ASSERT_EQUALS("Child's schema type was not expected value", m_qtype, *(kids.back()->getSchemaType()));
\r
157 void testUnmarshallingWithUnknownChild() {
\r
158 TS_TRACE("testUnmarshallingWithUnknownChild");
\r
160 string path=data_path + "SimpleXMLObjectWithUnknownChild.xml";
\r
161 ifstream fs(path.c_str());
\r
162 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
163 TS_ASSERT(doc!=NULL);
\r
165 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
166 TS_ASSERT(b!=NULL);
\r
168 TS_ASSERT_THROWS(b->buildFromDocument(doc),UnmarshallingException);
\r