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 #include <testshl/simpleheader.hxx> 25 #include <odiapi/xxml/XXmlReader.hxx> 26 #include <osl/time.h> 27 28 29 using namespace writerfilter; 30 31 class Node 32 { 33 public: 34 QName_t tag; 35 Node *next; 36 Node *prev; 37 Node(QName_t tag)38 Node(QName_t tag) : prev(NULL), next(NULL), tag(tag) { 39 }; 40 append(Node & node)41 void append(Node &node) 42 { 43 this->next=&node; 44 node.prev=this; 45 } 46 }; 47 48 class Table : public Node 49 { 50 public: Table(QName_t tag)51 Table(QName_t tag):Node(tag) {}; 52 }; 53 54 class Row : public Node 55 { 56 public: 57 Table &parent; 58 Row(QName_t tag,Table & parent)59 Row(QName_t tag, Table &parent) : Node(tag), parent(parent) {}; 60 }; 61 62 class Cell : public Node 63 { 64 public: 65 Row &parent; 66 Cell(QName_t tag,Row & parent)67 Cell(QName_t tag, Row &parent) : Node(tag), parent(parent) {}; 68 }; 69 70 71 class MyHandler : public xxml::ContentHandler 72 { 73 public: 74 int events; 75 Table *currentTable; 76 Row *currentRow; 77 Cell *currentCell; 78 startDocument()79 virtual void startDocument() 80 { 81 currentTable=NULL; 82 currentRow=NULL; 83 currentCell=NULL; 84 events=1; 85 } endDocument()86 virtual void endDocument() 87 { 88 events++; 89 } startElement(QName_t name,QName_t attrName[],const xxml::Value * attrValue[],int attrs)90 virtual void startElement(QName_t name, QName_t attrName[], const xxml::Value *attrValue[], int attrs) 91 { 92 events++; 93 // printf("<{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name)); 94 for(int i=0;i<attrs;i++) 95 { 96 // printf("@{%s}:%s=\"%s\"\n", QName::serializer().getNamespaceUri(attrName[i]), QName::serializer().getLocalName(attrName[i]), attrValue[i]->getOString().getStr()); 97 events++; 98 } 99 100 switch(name) 101 { 102 case NS_table::LN_table: 103 case NS_ss11::LN_Table: 104 currentTable=new Table(name); 105 break; 106 case NS_table::LN_table_row: 107 case NS_ss11::LN_Row: 108 if (currentRow==NULL) 109 currentRow=new Row(name, *currentTable); 110 else 111 currentRow->append(*new Row(name, *currentTable)); 112 break; 113 case NS_table::LN_table_cell: 114 case NS_ss11::LN_Cell: 115 if (currentCell==NULL) 116 currentCell=new Cell(name, *currentRow); 117 else 118 currentCell->append(*new Cell(name, *currentRow)); 119 break; 120 121 }; 122 123 } endElement(QName_t name)124 virtual void endElement(QName_t name) 125 { 126 //printf("</{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name)); 127 events++; 128 switch(name) 129 { 130 case NS_table::LN_table: 131 case NS_ss11::LN_Table: 132 if (currentTable != NULL) 133 { 134 currentRow->append(*currentTable); 135 } 136 currentRow=NULL; 137 break; 138 case NS_table::LN_table_row: 139 case NS_ss11::LN_Row: 140 if (currentRow != NULL) 141 currentCell->append(*currentRow); 142 currentCell=NULL; 143 break; 144 case NS_table::LN_table_cell: 145 case NS_ss11::LN_Cell: 146 break; 147 148 }; 149 } characters(const xxml::Value & value)150 virtual void characters(const xxml::Value &value) 151 { 152 //printf("\"%s\"\n", value.getOString().getStr()); 153 events++; 154 } 155 156 }; 157 158 class TestXXML : public CppUnit::TestFixture 159 { 160 public: test()161 void test() 162 { 163 MyHandler handler; 164 std::auto_ptr<xxml::XXmlReader> reader=xxml::XXmlReader::createXXmlReader(handler); 165 TimeValue t1; osl_getSystemTime(&t1); 166 167 // reader->read("test.xml"); 168 // reader->read("C:\\Documents and Settings\\fr156068\\My Documents\\odt\\testfile.xml"); 169 reader->read("C:\\Documents and Settings\\fr156068\\My Documents\\odt\\testfile\\content.xml"); 170 TimeValue t2; osl_getSystemTime(&t2); 171 printf("Events=%i time=%is time/event=%0.10fs\n", handler.events, t2.Seconds-t1.Seconds, (double)(t2.Seconds-t1.Seconds)/(double)handler.events); 172 } 173 174 CPPUNIT_TEST_SUITE(TestXXML); 175 CPPUNIT_TEST(test); 176 177 178 CPPUNIT_TEST_SUITE_END(); 179 }; 180 181 //##################################### 182 // register test suites 183 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestXXML, "TestXXML"); 184 185 NOADDITIONAL; 186