Bug fixes and API changes from second unit test.
[shibboleth/cpp-xmltooling.git] / xmltoolingtest / UnmarshallingTest.h
1 /*\r
2  *  Copyright 2001-2005 Internet2\r
3  * \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
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 #include "XMLObjectBaseTestCase.h"\r
18 \r
19 #include <fstream>\r
20 #include <xercesc/util/XMLUniDefs.hpp>\r
21 \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
29 };\r
30 \r
31 const XMLCh SimpleXMLObject::NAMESPACE_PREFIX[] = {\r
32     chLatin_t, chLatin_e, chLatin_s, chLatin_t, chNull\r
33 };\r
34 \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
38 };\r
39 \r
40 const XMLCh SimpleXMLObject::ID_ATTRIB_NAME[] = {\r
41     chLatin_I, chLatin_d, chNull\r
42 };\r
43 \r
44 class UnmarshallingTest : public CxxTest::TestSuite {\r
45     QName m_qname;\r
46 public:\r
47     UnmarshallingTest() : m_qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME) {}\r
48 \r
49     void setUp() {
50         XMLObjectBuilder::registerBuilder(m_qname, new SimpleXMLObjectBuilder());
51         Marshaller::registerMarshaller(m_qname, new SimpleXMLObjectMarshaller());
52         Unmarshaller::registerUnmarshaller(m_qname, new SimpleXMLObjectUnmarshaller());
53     }
54
55     void tearDown() {
56         XMLObjectBuilder::deregisterBuilder(m_qname);
57         Marshaller::deregisterMarshaller(m_qname);
58         Unmarshaller::deregisterUnmarshaller(m_qname);
59     }
60 \r
61     void testUnmarshallingWithAttributes() {\r
62         ifstream fs("../xmltoolingtest/data/SimpleXMLObjectWithAttribute.xml");\r
63         DOMDocument* doc=nonvalidatingPool->parse(fs);\r
64         TS_ASSERT(doc!=NULL);\r
65 \r
66         const Unmarshaller* u = Unmarshaller::getUnmarshaller(doc->getDocumentElement());\r
67         TS_ASSERT(u!=NULL);\r
68 \r
69         auto_ptr<SimpleXMLObject> sxObject(dynamic_cast<SimpleXMLObject*>(u->unmarshall(doc->getDocumentElement(),true)));\r
70         TS_ASSERT(sxObject.get()!=NULL);\r
71 \r
72         auto_ptr_XMLCh expectedId("Firefly");\r
73         TSM_ASSERT_SAME_DATA("ID was not expected value", expectedId.get(), sxObject->getId(), XMLString::stringLen(expectedId.get()));\r
74     }\r
75 };\r