-/*\r
- * Copyright 2001-2005 Internet2\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-#include "XMLObjectBaseTestCase.h"\r
-\r
-#include <fstream>\r
-#include <xercesc/util/XMLUniDefs.hpp>\r
-\r
-const XMLCh SimpleXMLObject::NAMESPACE[] = {\r
- chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,\r
- chLatin_w, chLatin_w, chLatin_w, chPeriod,\r
- chLatin_e, chLatin_x, chLatin_a, chLatin_m, chLatin_p, chLatin_l, chLatin_e, chPeriod,\r
- chLatin_o, chLatin_r, chLatin_g, chForwardSlash,\r
- chLatin_t, chLatin_e, chLatin_s, chLatin_t,\r
- chLatin_O, chLatin_b, chLatin_j, chLatin_e, chLatin_c, chLatin_t, chLatin_s, chNull\r
-};\r
-\r
-const XMLCh SimpleXMLObject::NAMESPACE_PREFIX[] = {\r
- chLatin_t, chLatin_e, chLatin_s, chLatin_t, chNull\r
-};\r
-\r
-const XMLCh SimpleXMLObject::LOCAL_NAME[] = {\r
- chLatin_S, chLatin_i, chLatin_m, chLatin_p, chLatin_l, chLatin_e,\r
- chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull\r
-};\r
-\r
-const XMLCh SimpleXMLObject::DERIVED_NAME[] = {\r
- chLatin_D, chLatin_e, chLatin_r, chLatin_i, chLatin_v, chLatin_e, chLatin_d,\r
- chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull\r
-};\r
-\r
-const XMLCh SimpleXMLObject::TYPE_NAME[] = {\r
- chLatin_S, chLatin_i, chLatin_m, chLatin_p, chLatin_l, chLatin_e,\r
- chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, \r
- chLatin_T, chLatin_y, chLatin_p, chLatin_e, chNull\r
-};\r
-\r
-const XMLCh SimpleXMLObject::ID_ATTRIB_NAME[] = {\r
- chLatin_I, chLatin_d, chNull\r
-};\r
-\r
-class UnmarshallingTest : public CxxTest::TestSuite {\r
- QName m_qname;\r
- QName m_qtype;\r
-public:\r
- UnmarshallingTest() : m_qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME,SimpleXMLObject::NAMESPACE_PREFIX),\r
- m_qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME,SimpleXMLObject::NAMESPACE_PREFIX) {}\r
-\r
- void setUp() {\r
- XMLObjectBuilder::registerBuilder(m_qname, new SimpleXMLObjectBuilder());\r
- XMLObjectBuilder::registerBuilder(m_qtype, new SimpleXMLObjectBuilder());\r
- }\r
-\r
- void tearDown() {\r
- XMLObjectBuilder::deregisterBuilder(m_qname);\r
- XMLObjectBuilder::deregisterBuilder(m_qtype);\r
- }\r
-\r
- void testUnmarshallingWithAttributes() {\r
- TS_TRACE("testUnmarshallingWithAttributes");\r
-\r
- string path=data_path + "SimpleXMLObjectWithAttribute.xml";\r
- ifstream fs(path.c_str());\r
- DOMDocument* doc=nonvalidatingPool->parse(fs);\r
- TS_ASSERT(doc!=NULL);\r
-\r
- const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
- TS_ASSERT(b!=NULL);\r
-\r
- auto_ptr<SimpleXMLObject> sxObject(\r
- dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))\r
- );\r
- TS_ASSERT(sxObject.get()!=NULL);\r
-\r
- auto_ptr_XMLCh expected("Firefly");\r
- TSM_ASSERT_SAME_DATA("ID was not expected value", expected.get(), sxObject->getId(), XMLString::stringLen(expected.get()));\r
- }\r
-\r
- void testUnmarshallingWithElementContent() {\r
- TS_TRACE("testUnmarshallingWithElementContent");\r
-\r
- string path=data_path + "SimpleXMLObjectWithContent.xml";\r
- ifstream fs(path.c_str());\r
- DOMDocument* doc=nonvalidatingPool->parse(fs);\r
- TS_ASSERT(doc!=NULL);\r
-\r
- const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
- TS_ASSERT(b!=NULL);\r
-\r
- auto_ptr<SimpleXMLObject> sxObject(\r
- dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))\r
- );\r
- TS_ASSERT(sxObject.get()!=NULL);\r
-\r
- auto_ptr_XMLCh expected("Sample Content");\r
- TSM_ASSERT_SAME_DATA("Element content was not expected value", expected.get(), sxObject->getValue(), XMLString::stringLen(expected.get()));\r
- }\r
-\r
- void testUnmarshallingWithChildElements() {\r
- TS_TRACE("testUnmarshallingWithChildElements");\r
-\r
- string path=data_path + "SimpleXMLObjectWithChildren.xml";\r
- ifstream fs(path.c_str());\r
- DOMDocument* doc=nonvalidatingPool->parse(fs);\r
- TS_ASSERT(doc!=NULL);\r
-\r
- const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
- TS_ASSERT(b!=NULL);\r
-\r
- auto_ptr<SimpleXMLObject> sxObject(\r
- dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))\r
- );\r
- TS_ASSERT(sxObject.get()!=NULL);\r
-\r
- VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects();\r
- TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, kids.size());\r
- TSM_ASSERT_EQUALS("Child's schema type was not expected value", m_qtype, *(kids.back()->getSchemaType()));\r
- }\r
-\r
- void testUnmarshallingWithClone() {\r
- TS_TRACE("testUnmarshallingWithClone");\r
-\r
- string path=data_path + "SimpleXMLObjectWithChildren.xml";\r
- ifstream fs(path.c_str());\r
- DOMDocument* doc=nonvalidatingPool->parse(fs);\r
- TS_ASSERT(doc!=NULL);\r
-\r
- const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
- TS_ASSERT(b!=NULL);\r
-\r
- auto_ptr<SimpleXMLObject> sxObject(\r
- dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))\r
- );\r
- TS_ASSERT(sxObject.get()!=NULL);\r
-\r
- sxObject->releaseThisAndChildrenDOM();\r
- auto_ptr<SimpleXMLObject> clonedObject(sxObject->clone());\r
-\r
- VectorOf(SimpleXMLObject) kids=clonedObject->getSimpleXMLObjects();\r
- TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, kids.size());\r
- TSM_ASSERT_EQUALS("Child's schema type was not expected value", m_qtype, *(kids.back()->getSchemaType()));\r
- }\r
-\r
- void testUnmarshallingWithUnknownChild() {\r
- TS_TRACE("testUnmarshallingWithUnknownChild");\r
-\r
- string path=data_path + "SimpleXMLObjectWithUnknownChild.xml";\r
- ifstream fs(path.c_str());\r
- DOMDocument* doc=nonvalidatingPool->parse(fs);\r
- TS_ASSERT(doc!=NULL);\r
-\r
- const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());\r
- TS_ASSERT(b!=NULL);\r
-\r
- TS_ASSERT_THROWS(b->buildFromDocument(doc),UnmarshallingException);\r
- doc->release();\r
- }\r
-};\r
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
+ *
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ */
+
+#include "XMLObjectBaseTestCase.h"
+
+#include <fstream>
+#include <xercesc/util/XMLUniDefs.hpp>
+
+const XMLCh SimpleXMLObject::NAMESPACE[] = {
+ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash,
+ chLatin_w, chLatin_w, chLatin_w, chPeriod,
+ chLatin_e, chLatin_x, chLatin_a, chLatin_m, chLatin_p, chLatin_l, chLatin_e, chPeriod,
+ chLatin_o, chLatin_r, chLatin_g, chForwardSlash,
+ chLatin_t, chLatin_e, chLatin_s, chLatin_t,
+ chLatin_O, chLatin_b, chLatin_j, chLatin_e, chLatin_c, chLatin_t, chLatin_s, chNull
+};
+
+const XMLCh SimpleXMLObject::NAMESPACE_PREFIX[] = {
+ chLatin_t, chLatin_e, chLatin_s, chLatin_t, chNull
+};
+
+const XMLCh SimpleXMLObject::LOCAL_NAME[] = {
+ chLatin_S, chLatin_i, chLatin_m, chLatin_p, chLatin_l, chLatin_e,
+ chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull
+};
+
+const XMLCh SimpleXMLObject::DERIVED_NAME[] = {
+ chLatin_D, chLatin_e, chLatin_r, chLatin_i, chLatin_v, chLatin_e, chLatin_d,
+ chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull
+};
+
+const XMLCh SimpleXMLObject::TYPE_NAME[] = {
+ chLatin_S, chLatin_i, chLatin_m, chLatin_p, chLatin_l, chLatin_e,
+ chLatin_E, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t,
+ chLatin_T, chLatin_y, chLatin_p, chLatin_e, chNull
+};
+
+const XMLCh SimpleXMLObject::ID_ATTRIB_NAME[] = {
+ chLatin_I, chLatin_d, chNull
+};
+
+class UnmarshallingTest : public CxxTest::TestSuite {
+public:
+ void setUp() {
+ xmltooling::QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME);
+ xmltooling::QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME);
+ XMLObjectBuilder::registerBuilder(qname, new SimpleXMLObjectBuilder());
+ XMLObjectBuilder::registerBuilder(qtype, new SimpleXMLObjectBuilder());
+ }
+
+ void tearDown() {
+ xmltooling::QName qname(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME);
+ xmltooling::QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME);
+ XMLObjectBuilder::deregisterBuilder(qname);
+ XMLObjectBuilder::deregisterBuilder(qtype);
+ }
+
+ void testUnmarshallingWithAttributes() {
+ string path=data_path + "SimpleXMLObjectWithAttribute.xml";
+ ifstream fs(path.c_str());
+ DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
+ TS_ASSERT(doc!=nullptr);
+
+ const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
+ TS_ASSERT(b!=nullptr);
+
+ auto_ptr<SimpleXMLObject> sxObject(
+ dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))
+ );
+ TS_ASSERT(sxObject.get()!=nullptr);
+
+ auto_ptr_XMLCh expected("Firefly");
+ TSM_ASSERT("ID was not expected value", XMLString::equals(expected.get(), sxObject->getId()));
+ }
+
+ void testUnmarshallingWithElementContent() {
+ string path=data_path + "SimpleXMLObjectWithContent.xml";
+ ifstream fs(path.c_str());
+ DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
+ TS_ASSERT(doc!=nullptr);
+
+ const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
+ TS_ASSERT(b!=nullptr);
+
+ auto_ptr<SimpleXMLObject> sxObject(
+ dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))
+ );
+ TS_ASSERT(sxObject.get()!=nullptr);
+
+ auto_ptr_XMLCh expected("Sample Content");
+ TSM_ASSERT("Element content was not expected value", XMLString::equals(expected.get(), sxObject->getValue()));
+ }
+
+ void testUnmarshallingWithChildElements() {
+ string path=data_path + "SimpleXMLObjectWithChildren.xml";
+ ifstream fs(path.c_str());
+ DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
+ TS_ASSERT(doc!=nullptr);
+
+ const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
+ TS_ASSERT(b!=nullptr);
+
+ auto_ptr<SimpleXMLObject> sxObject(
+ dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))
+ );
+ TS_ASSERT(sxObject.get()!=nullptr);
+
+ VectorOf(SimpleXMLObject) kids=sxObject->getSimpleXMLObjects();
+ TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, kids.size());
+ xmltooling::QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME);
+ TSM_ASSERT_EQUALS("Child's schema type was not expected value", qtype, *(kids.back()->getSchemaType()));
+ }
+
+ void testUnmarshallingWithClone() {
+ string path=data_path + "SimpleXMLObjectWithChildren.xml";
+ ifstream fs(path.c_str());
+ DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
+ TS_ASSERT(doc!=nullptr);
+
+ const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
+ TS_ASSERT(b!=nullptr);
+
+ auto_ptr<SimpleXMLObject> sxObject(
+ dynamic_cast<SimpleXMLObject*>(b->buildFromDocument(doc))
+ );
+ TS_ASSERT(sxObject.get()!=nullptr);
+
+ sxObject->releaseThisAndChildrenDOM();
+ auto_ptr<SimpleXMLObject> clonedObject(dynamic_cast<SimpleXMLObject*>(sxObject->clone()));
+
+ VectorOf(SimpleXMLObject) kids=clonedObject->getSimpleXMLObjects();
+ TSM_ASSERT_EQUALS("Number of child elements was not expected value", 3, kids.size());
+ xmltooling::QName qtype(SimpleXMLObject::NAMESPACE,SimpleXMLObject::TYPE_NAME);
+ TSM_ASSERT_EQUALS("Child's schema type was not expected value", qtype, *(kids.back()->getSchemaType()));
+ }
+
+ void testUnmarshallingWithUnknownChild() {
+ string path=data_path + "SimpleXMLObjectWithUnknownChild.xml";
+ ifstream fs(path.c_str());
+ DOMDocument* doc=XMLToolingConfig::getConfig().getParser().parse(fs);
+ TS_ASSERT(doc!=nullptr);
+
+ const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
+ TS_ASSERT(b!=nullptr);
+
+ TS_ASSERT_THROWS(b->buildFromDocument(doc),UnmarshallingException);
+ doc->release();
+ }
+};