1 /* Copyright 2005 Sun Microsystems, Inc. */
3 #include <cppunit/simpleheader.hxx>
4 #include <odiapi/xxml/XXmlReader.hxx>
8 using namespace writerfilter
;
17 Node(QName_t tag
) : prev(NULL
), next(NULL
), tag(tag
) {
20 void append(Node
&node
)
27 class Table
: public Node
30 Table(QName_t tag
):Node(tag
) {};
33 class Row
: public Node
38 Row(QName_t tag
, Table
&parent
) : Node(tag
), parent(parent
) {};
41 class Cell
: public Node
46 Cell(QName_t tag
, Row
&parent
) : Node(tag
), parent(parent
) {};
50 class MyHandler
: public xxml::ContentHandler
58 virtual void startDocument()
65 virtual void endDocument()
69 virtual void startElement(QName_t name
, QName_t attrName
[], const xxml::Value
*attrValue
[], int attrs
)
72 // printf("<{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name));
73 for(int i
=0;i
<attrs
;i
++)
75 // printf("@{%s}:%s=\"%s\"\n", QName::serializer().getNamespaceUri(attrName[i]), QName::serializer().getLocalName(attrName[i]), attrValue[i]->getOString().getStr());
81 case NS_table::LN_table
:
82 case NS_ss11::LN_Table
:
83 currentTable
=new Table(name
);
85 case NS_table::LN_table_row
:
88 currentRow
=new Row(name
, *currentTable
);
90 currentRow
->append(*new Row(name
, *currentTable
));
92 case NS_table::LN_table_cell
:
93 case NS_ss11::LN_Cell
:
94 if (currentCell
==NULL
)
95 currentCell
=new Cell(name
, *currentRow
);
97 currentCell
->append(*new Cell(name
, *currentRow
));
103 virtual void endElement(QName_t name
)
105 //printf("</{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name));
109 case NS_table::LN_table
:
110 case NS_ss11::LN_Table
:
111 currentRow
->append(*currentTable
);
114 case NS_table::LN_table_row
:
115 case NS_ss11::LN_Row
:
116 currentCell
->append(*currentRow
);
119 case NS_table::LN_table_cell
:
120 case NS_ss11::LN_Cell
:
125 virtual void characters(const xxml::Value
&value
)
127 //printf("\"%s\"\n", value.getOString().getStr());
133 class TestXXML
: public CppUnit::TestFixture
139 std::auto_ptr
<xxml::XXmlReader
> reader
=xxml::XXmlReader::createXXmlReader(handler
);
140 TimeValue t1
; osl_getSystemTime(&t1
);
142 // reader->read("test.xml");
143 // reader->read("C:\\Documents and Settings\\fr156068\\My Documents\\odt\\testfile.xml");
144 reader
->read("C:\\Documents and Settings\\fr156068\\My Documents\\odt\\testfile\\content.xml");
145 TimeValue t2
; osl_getSystemTime(&t2
);
146 printf("Events=%i time=%is time/event=%0.10fs\n", handler
.events
, t2
.Seconds
-t1
.Seconds
, (double)(t2
.Seconds
-t1
.Seconds
)/(double)handler
.events
);
149 CPPUNIT_TEST_SUITE(TestXXML
);
153 CPPUNIT_TEST_SUITE_END();
156 //#####################################
157 // register test suites
158 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestXXML
, "TestXXML");