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 currentRow->append(*currentTable); 133 currentRow=NULL; 134 break; 135 case NS_table::LN_table_row: 136 case NS_ss11::LN_Row: 137 currentCell->append(*currentRow); 138 currentCell=NULL; 139 break; 140 case NS_table::LN_table_cell: 141 case NS_ss11::LN_Cell: 142 break; 143 144 }; 145 } characters(const xxml::Value & value)146 virtual void characters(const xxml::Value &value) 147 { 148 //printf("\"%s\"\n", value.getOString().getStr()); 149 events++; 150 } 151 152 }; 153 154 class TestXXML : public CppUnit::TestFixture 155 { 156 public: test()157 void test() 158 { 159 MyHandler handler; 160 std::auto_ptr<xxml::XXmlReader> reader=xxml::XXmlReader::createXXmlReader(handler); 161 TimeValue t1; osl_getSystemTime(&t1); 162 163 // reader->read("test.xml"); 164 // reader->read("C:\\Documents and Settings\\fr156068\\My Documents\\odt\\testfile.xml"); 165 reader->read("C:\\Documents and Settings\\fr156068\\My Documents\\odt\\testfile\\content.xml"); 166 TimeValue t2; osl_getSystemTime(&t2); 167 printf("Events=%i time=%is time/event=%0.10fs\n", handler.events, t2.Seconds-t1.Seconds, (double)(t2.Seconds-t1.Seconds)/(double)handler.events); 168 } 169 170 CPPUNIT_TEST_SUITE(TestXXML); 171 CPPUNIT_TEST(test); 172 173 174 CPPUNIT_TEST_SUITE_END(); 175 }; 176 177 //##################################### 178 // register test suites 179 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestXXML, "TestXXML"); 180 181 NOADDITIONAL; 182