merged tag ooo/DEV300_m102
[LibreOffice.git] / writerfilter / qa / cppunittests / xxml / testXXML.cxx
blob4e5ade4f8d7e1a4c99971d13b6181eee2aa610aa
1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * This file is part of OpenOffice.org.
10 * OpenOffice.org is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License version 3
12 * only, as published by the Free Software Foundation.
14 * OpenOffice.org is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License version 3 for more details
18 * (a copy is included in the LICENSE file that accompanied this code).
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with OpenOffice.org. If not, see
22 * <http://www.openoffice.org/license.html>
23 * for a copy of the LGPLv3 License.
25 ************************************************************************/
27 #include <testshl/simpleheader.hxx>
28 #include <odiapi/xxml/XXmlReader.hxx>
29 #include <osl/time.h>
32 using namespace writerfilter;
34 class Node
36 public:
37 QName_t tag;
38 Node *next;
39 Node *prev;
41 Node(QName_t tag) : prev(NULL), next(NULL), tag(tag) {
44 void append(Node &node)
46 this->next=&node;
47 node.prev=this;
51 class Table : public Node
53 public:
54 Table(QName_t tag):Node(tag) {};
57 class Row : public Node
59 public:
60 Table &parent;
62 Row(QName_t tag, Table &parent) : Node(tag), parent(parent) {};
65 class Cell : public Node
67 public:
68 Row &parent;
70 Cell(QName_t tag, Row &parent) : Node(tag), parent(parent) {};
74 class MyHandler : public xxml::ContentHandler
76 public:
77 int events;
78 Table *currentTable;
79 Row *currentRow;
80 Cell *currentCell;
82 virtual void startDocument()
84 currentTable=NULL;
85 currentRow=NULL;
86 currentCell=NULL;
87 events=1;
89 virtual void endDocument()
91 events++;
93 virtual void startElement(QName_t name, QName_t attrName[], const xxml::Value *attrValue[], int attrs)
95 events++;
96 // printf("<{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name));
97 for(int i=0;i<attrs;i++)
99 // printf("@{%s}:%s=\"%s\"\n", QName::serializer().getNamespaceUri(attrName[i]), QName::serializer().getLocalName(attrName[i]), attrValue[i]->getOString().getStr());
100 events++;
103 switch(name)
105 case NS_table::LN_table:
106 case NS_ss11::LN_Table:
107 currentTable=new Table(name);
108 break;
109 case NS_table::LN_table_row:
110 case NS_ss11::LN_Row:
111 if (currentRow==NULL)
112 currentRow=new Row(name, *currentTable);
113 else
114 currentRow->append(*new Row(name, *currentTable));
115 break;
116 case NS_table::LN_table_cell:
117 case NS_ss11::LN_Cell:
118 if (currentCell==NULL)
119 currentCell=new Cell(name, *currentRow);
120 else
121 currentCell->append(*new Cell(name, *currentRow));
122 break;
127 virtual void endElement(QName_t name)
129 //printf("</{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name));
130 events++;
131 switch(name)
133 case NS_table::LN_table:
134 case NS_ss11::LN_Table:
135 currentRow->append(*currentTable);
136 currentRow=NULL;
137 break;
138 case NS_table::LN_table_row:
139 case NS_ss11::LN_Row:
140 currentCell->append(*currentRow);
141 currentCell=NULL;
142 break;
143 case NS_table::LN_table_cell:
144 case NS_ss11::LN_Cell:
145 break;
149 virtual void characters(const xxml::Value &value)
151 //printf("\"%s\"\n", value.getOString().getStr());
152 events++;
157 class TestXXML : public CppUnit::TestFixture
159 public:
160 void test()
162 MyHandler handler;
163 std::auto_ptr<xxml::XXmlReader> reader=xxml::XXmlReader::createXXmlReader(handler);
164 TimeValue t1; osl_getSystemTime(&t1);
166 // reader->read("test.xml");
167 // reader->read("C:\\Documents and Settings\\fr156068\\My Documents\\odt\\testfile.xml");
168 reader->read("C:\\Documents and Settings\\fr156068\\My Documents\\odt\\testfile\\content.xml");
169 TimeValue t2; osl_getSystemTime(&t2);
170 printf("Events=%i time=%is time/event=%0.10fs\n", handler.events, t2.Seconds-t1.Seconds, (double)(t2.Seconds-t1.Seconds)/(double)handler.events);
173 CPPUNIT_TEST_SUITE(TestXXML);
174 CPPUNIT_TEST(test);
177 CPPUNIT_TEST_SUITE_END();
180 //#####################################
181 // register test suites
182 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestXXML, "TestXXML");
184 NOADDITIONAL;