1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 25 #include <testshl/simpleheader.hxx> 26 #include <odiapi/core/Node.hxx> 27 #include <odiapi/props/Properties.hxx> 28 29 using namespace odiapi::core; 30 using namespace odiapi::props; 31 using namespace writerfilter; 32 using namespace std; 33 34 class TestCore : public CppUnit::TestFixture 35 { 36 public: testCreateCore()37 void testCreateCore() 38 { 39 PropertyPool::Pointer_t pool = createPropertyPool(); 40 PropertyBag_Pointer_t pb = createPropertyBag(); 41 42 pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); 43 PropertyPoolHandle_Pointer_t ph = pool->insert(pb); 44 45 Node::Pointer_t node = createNode(NS_style::LN_char, ph, "NS_style::LN_char"); 46 47 CPPUNIT_ASSERT_MESSAGE("Create node failed wrong node id", node->getId() == NS_style::LN_char); 48 CPPUNIT_ASSERT_MESSAGE("Create node failed wrong text", node->getText() == "NS_style::LN_char"); 49 CPPUNIT_ASSERT_MESSAGE("Create node failed wrong pool handle", node->getProperties() == ph); 50 } 51 testInsertSibling()52 void testInsertSibling() 53 { 54 PropertyPool::Pointer_t pool = createPropertyPool(); 55 PropertyBag_Pointer_t pb = createPropertyBag(); 56 57 pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); 58 PropertyPoolHandle_Pointer_t ph = pool->insert(pb); 59 60 Node::Pointer_t node1 = createNode(NS_style::LN_char, ph, "Text"); 61 Node::Pointer_t node2 = createNode(NS_style::LN_char, ph, "\\par"); 62 63 node1->insertSibling(node2); 64 65 string postfixSeq = node1->getText(); 66 const Node* n = node1.get(); 67 while (n->hasNext()) 68 { 69 n = &n->getNext(); 70 postfixSeq = postfixSeq + n->getText(); 71 } 72 73 CPPUNIT_ASSERT_MESSAGE("Insert sibling failed", postfixSeq == "Text\\par"); 74 75 Node::Pointer_t node3 = createNode(NS_style::LN_char, ph, "\\span"); 76 77 node1->insertSibling(node3); 78 79 postfixSeq = node1->getText(); 80 n = node1.get(); 81 while (n->hasNext()) 82 { 83 n = &n->getNext(); 84 postfixSeq = postfixSeq + n->getText(); 85 } 86 87 CPPUNIT_ASSERT_MESSAGE("Insert sibling failed", postfixSeq == "Text\\span\\par"); 88 } 89 testAppendChildren()90 void testAppendChildren() 91 { 92 PropertyPool::Pointer_t pool = createPropertyPool(); 93 PropertyBag_Pointer_t pb = createPropertyBag(); 94 95 pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); 96 PropertyPoolHandle_Pointer_t ph = pool->insert(pb); 97 98 Node::Pointer_t node1 = createNode(NS_style::LN_char, ph, "Text"); 99 const Node* pn1 = node1.get(); 100 101 Node::Pointer_t node2 = createNode(NS_style::LN_char, ph, "\\par"); 102 103 node2->appendChildren(node1); 104 105 CPPUNIT_ASSERT_MESSAGE("Append children failed", &node2->getFirstChild() == pn1); 106 107 const Node* n = &node2->getFirstChild(); 108 string postfixSeq = n->getText() + n->getNext().getText(); 109 110 CPPUNIT_ASSERT_MESSAGE("Append children failed", postfixSeq == "Text\\par"); 111 } 112 testCore()113 void testCore() 114 { 115 PropertyPool::Pointer_t pool = createPropertyPool(); 116 PropertyBag_Pointer_t pb = createPropertyBag(); 117 118 pb->insert(createIntegerProperty(NS_fo::LN_font_weight, 12)); 119 PropertyPoolHandle_Pointer_t ph = pool->insert(pb); 120 121 Node::Pointer_t node1 = createNode(NS_style::LN_char, ph, "A"); 122 Node::Pointer_t node2 = createNode(NS_style::LN_char, ph, "\\span"); 123 124 node2->appendChildren(node1); 125 126 Node::Pointer_t node3 = createNode(NS_style::LN_char, ph, "B"); 127 Node::Pointer_t node4 = createNode(NS_style::LN_char, ph, "\\span"); 128 129 node4->appendChildren(node3); 130 131 node2->insertSibling(node4); 132 133 Node::Pointer_t node5 = createNode(NS_style::LN_char, ph, "\\par"); 134 135 node5->appendChildren(node2); 136 137 Node::Pointer_t node6 = createNode(NS_style::LN_char, ph, "C"); 138 Node::Pointer_t node7 = createNode(NS_style::LN_char, ph, "\\span"); 139 140 node7->appendChildren(node6); 141 142 node5->appendChildren(node7); 143 144 145 string postfixSeq = node5->getText(); 146 const Node* n = node5.get(); 147 while (n->hasPrevious()) 148 { 149 n = &n->getPrevious(); 150 postfixSeq = postfixSeq + n->getText(); 151 } 152 153 CPPUNIT_ASSERT_MESSAGE("Insert sibling failed", postfixSeq == "\\par\\spanC\\spanB\\spanA"); 154 } 155 156 CPPUNIT_TEST_SUITE(TestCore); 157 CPPUNIT_TEST(testCreateCore); 158 CPPUNIT_TEST(testInsertSibling); 159 CPPUNIT_TEST(testAppendChildren); 160 CPPUNIT_TEST(testCore); 161 CPPUNIT_TEST_SUITE_END(); 162 }; 163 164 //##################################### 165 // register test suites 166 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestCore, "TestCore"); 167 168 //NOADDITIONAL; 169