Update ooo320-m1
[ooovba.git] / writerfilter / qa / cppunittests / xxml / testXXML.cxx
blobcb727304549c0fcae1784715b6ec705d9e413821
1 /* Copyright 2005 Sun Microsystems, Inc. */
3 #include <cppunit/simpleheader.hxx>
4 #include <odiapi/xxml/XXmlReader.hxx>
5 #include <osl/time.h>
8 using namespace writerfilter;
10 class Node
12 public:
13 QName_t tag;
14 Node *next;
15 Node *prev;
17 Node(QName_t tag) : prev(NULL), next(NULL), tag(tag) {
20 void append(Node &node)
22 this->next=&node;
23 node.prev=this;
27 class Table : public Node
29 public:
30 Table(QName_t tag):Node(tag) {};
33 class Row : public Node
35 public:
36 Table &parent;
38 Row(QName_t tag, Table &parent) : Node(tag), parent(parent) {};
41 class Cell : public Node
43 public:
44 Row &parent;
46 Cell(QName_t tag, Row &parent) : Node(tag), parent(parent) {};
50 class MyHandler : public xxml::ContentHandler
52 public:
53 int events;
54 Table *currentTable;
55 Row *currentRow;
56 Cell *currentCell;
58 virtual void startDocument()
60 currentTable=NULL;
61 currentRow=NULL;
62 currentCell=NULL;
63 events=1;
65 virtual void endDocument()
67 events++;
69 virtual void startElement(QName_t name, QName_t attrName[], const xxml::Value *attrValue[], int attrs)
71 events++;
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());
76 events++;
79 switch(name)
81 case NS_table::LN_table:
82 case NS_ss11::LN_Table:
83 currentTable=new Table(name);
84 break;
85 case NS_table::LN_table_row:
86 case NS_ss11::LN_Row:
87 if (currentRow==NULL)
88 currentRow=new Row(name, *currentTable);
89 else
90 currentRow->append(*new Row(name, *currentTable));
91 break;
92 case NS_table::LN_table_cell:
93 case NS_ss11::LN_Cell:
94 if (currentCell==NULL)
95 currentCell=new Cell(name, *currentRow);
96 else
97 currentCell->append(*new Cell(name, *currentRow));
98 break;
103 virtual void endElement(QName_t name)
105 //printf("</{%s}:%s>\n", QName::serializer().getNamespaceUri(name), QName::serializer().getLocalName(name));
106 events++;
107 switch(name)
109 case NS_table::LN_table:
110 case NS_ss11::LN_Table:
111 currentRow->append(*currentTable);
112 currentRow=NULL;
113 break;
114 case NS_table::LN_table_row:
115 case NS_ss11::LN_Row:
116 currentCell->append(*currentRow);
117 currentCell=NULL;
118 break;
119 case NS_table::LN_table_cell:
120 case NS_ss11::LN_Cell:
121 break;
125 virtual void characters(const xxml::Value &value)
127 //printf("\"%s\"\n", value.getOString().getStr());
128 events++;
133 class TestXXML : public CppUnit::TestFixture
135 public:
136 void test()
138 MyHandler handler;
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);
150 CPPUNIT_TEST(test);
153 CPPUNIT_TEST_SUITE_END();
156 //#####################################
157 // register test suites
158 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TestXXML, "TestXXML");
160 NOADDITIONAL;