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>
32 using namespace writerfilter
;
41 Node(QName_t tag
) : prev(NULL
), next(NULL
), tag(tag
) {
44 void append(Node
&node
)
51 class Table
: public Node
54 Table(QName_t tag
):Node(tag
) {};
57 class Row
: public Node
62 Row(QName_t tag
, Table
&parent
) : Node(tag
), parent(parent
) {};
65 class Cell
: public Node
70 Cell(QName_t tag
, Row
&parent
) : Node(tag
), parent(parent
) {};
74 class MyHandler
: public xxml::ContentHandler
82 virtual void startDocument()
89 virtual void endDocument()
93 virtual void startElement(QName_t name
, QName_t attrName
[], const xxml::Value
*attrValue
[], int attrs
)
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());
105 case NS_table::LN_table
:
106 case NS_ss11::LN_Table
:
107 currentTable
=new Table(name
);
109 case NS_table::LN_table_row
:
110 case NS_ss11::LN_Row
:
111 if (currentRow
==NULL
)
112 currentRow
=new Row(name
, *currentTable
);
114 currentRow
->append(*new Row(name
, *currentTable
));
116 case NS_table::LN_table_cell
:
117 case NS_ss11::LN_Cell
:
118 if (currentCell
==NULL
)
119 currentCell
=new Cell(name
, *currentRow
);
121 currentCell
->append(*new Cell(name
, *currentRow
));
127 virtual void endElement(QName_t name
)
129 //printf("</{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name));
133 case NS_table::LN_table
:
134 case NS_ss11::LN_Table
:
135 currentRow
->append(*currentTable
);
138 case NS_table::LN_table_row
:
139 case NS_ss11::LN_Row
:
140 currentCell
->append(*currentRow
);
143 case NS_table::LN_table_cell
:
144 case NS_ss11::LN_Cell
:
149 virtual void characters(const xxml::Value
&value
)
151 //printf("\"%s\"\n", value.getOString().getStr());
157 class TestXXML
: public CppUnit::TestFixture
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
);
177 CPPUNIT_TEST_SUITE_END();
180 //#####################################
181 // register test suites
182 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestXXML
, "TestXXML");