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::ID_ATTRIB_NAME[] = {
\r
41 chLatin_I, chLatin_d, chNull
\r
44 class UnmarshallingTest : public CxxTest::TestSuite {
\r
47 UnmarshallingTest() : m_qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME) {}
\r
50 XMLObjectBuilder::registerBuilder(m_qname, new SimpleXMLObjectBuilder());
\r
54 XMLObjectBuilder::deregisterBuilder(m_qname);
\r
57 void testUnmarshallingWithAttributes() {
\r
58 TS_TRACE("testUnmarshallingWithAttributes");
\r
60 string path=data_path + "SimpleXMLObjectWithAttribute.xml";
\r
61 ifstream fs(path.c_str());
\r
62 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
63 TS_ASSERT(doc!=NULL);
\r
65 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
68 auto_ptr<SimpleXMLObject> sxObject(
\r
69 dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))
\r
71 TS_ASSERT(sxObject.get()!=NULL);
\r
73 auto_ptr_XMLCh expected("Firefly");
\r
74 TSM_ASSERT_SAME_DATA("ID was not expected value", expected.get(), sxObject->getId(), XMLString::stringLen(expected.get()));
\r
77 void testUnmarshallingWithElementContent() {
\r
78 TS_TRACE("testUnmarshallingWithElementContent");
\r
80 string path=data_path + "SimpleXMLObjectWithContent.xml";
\r
81 ifstream fs(path.c_str());
\r
82 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
83 TS_ASSERT(doc!=NULL);
\r
85 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
88 auto_ptr<SimpleXMLObject> sxObject(
\r
89 dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))
\r
91 TS_ASSERT(sxObject.get()!=NULL);
\r
93 auto_ptr_XMLCh expected("Sample Content");
\r
94 TSM_ASSERT_SAME_DATA("Element content was not expected value", expected.get(), sxObject->getValue(), XMLString::stringLen(expected.get()));
\r
97 void testUnmarshallingWithChildElements() {
\r
98 TS_TRACE("testUnmarshallingWithChildElements");
\r
100 string path=data_path + "SimpleXMLObjectWithChildren.xml";
\r
101 ifstream fs(path.c_str());
\r
102 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
103 TS_ASSERT(doc!=NULL);
\r
105 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
106 TS_ASSERT(b!=NULL);
\r
108 auto_ptr<SimpleXMLObject> sxObject(
\r
109 dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))
\r
111 TS_ASSERT(sxObject.get()!=NULL);
\r
113 VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects();
\r
114 TSM_ASSERT_EQUALS("Number of child elements was not expected value", 2, kids.size());
\r
117 void testUnmarshallingWithUnknownChild() {
\r
118 TS_TRACE("testUnmarshallingWithUnknownChild");
\r
120 string path=data_path + "SimpleXMLObjectWithUnknownChild.xml";
\r
121 ifstream fs(path.c_str());
\r
122 DOMDocument* doc=nonvalidatingPool->parse(fs);
\r
123 TS_ASSERT(doc!=NULL);
\r
125 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
\r
126 TS_ASSERT(b!=NULL);
\r
128 TS_ASSERT_THROWS(b->buildFromDocument(doc),UnmarshallingException);
\r