00001 #include "xmlwritertest.h"
00002
00003 #include "KoXmlWriter.h"
00004
00005 #include <QApplication>
00006 #include <QFile>
00007 #include <QDateTime>
00008
00009 #include <Q3CString>
00010
00011 static const int numParagraphs = 30000;
00012 void speedTest()
00013 {
00014 QTime time;
00015 time.start();
00016 QString paragText = QString::fromUtf8( "This is the text of the paragraph. I'm including a euro sign to test encoding issues: €" );
00017 Q3CString styleName = "Heading 1";
00018
00019 QFile out( QString::fromLatin1( "out5.xml" ) );
00020 if ( out.open(QIODevice::WriteOnly) )
00021 {
00022 KoXmlWriter writer( &out );
00023 writer.startDocument( "rootelem" );
00024 writer.startElement( "rootelem" );
00025 for ( int i = 0 ; i < numParagraphs ; ++i )
00026 {
00027 writer.startElement( "paragraph" );
00028 writer.addAttribute( "text:style-name", styleName );
00029 writer.addTextNode( paragText );
00030 writer.endElement();
00031 }
00032 writer.endElement();
00033 writer.endDocument();
00034 }
00035 out.close();
00036 qDebug( "writing %i XML elements using KoXmlWriter: %i ms", numParagraphs, time.elapsed() );
00037 }
00038
00039 int main( int argc, char** argv ) {
00040 QApplication app( argc, argv, QApplication::Tty );
00041
00042 TEST_BEGIN( 0, 0 );
00043 TEST_END( "framework test", "<r/>\n" );
00044
00045 TEST_BEGIN( "-//KDE//DTD kword 1.3//EN", "http://www.koffice.org/DTD/kword-1.3.dtd" );
00046 TEST_END( "doctype test", "<!DOCTYPE r PUBLIC \"-//KDE//DTD kword 1.3//EN\" \"http://www.koffice.org/DTD/kword-1.3.dtd\">\n<r/>\n" );
00047
00048 TEST_BEGIN( 0, 0 );
00049 writer.addAttribute( "a", "val" );
00050 writer.addAttribute( "b", "<\">" );
00051 writer.addAttribute( "c", -42 );
00052 writer.addAttribute( "d", 1234.56789012345 );
00053 writer.addAttributePt( "e", 1234.56789012345 );
00054 TEST_END( "attributes test", "<r a=\"val\" b=\"<">\" c=\"-42\" d=\"1234.56789012345\" e=\"1234.56789012345pt\"/>\n" );
00055
00056 TEST_BEGIN( 0, 0 );
00057 writer.startElement( "m" );
00058 writer.endElement();
00059 TEST_END( "empty element test", "<r>\n <m/>\n</r>\n" );
00060
00061 TEST_BEGIN( 0, 0 );
00062 writer.startElement( "a" );
00063 writer.startElement( "b" );
00064 writer.startElement( "c" );
00065 writer.endElement();
00066 writer.endElement();
00067 writer.endElement();
00068 TEST_END( "indent test", "<r>\n <a>\n <b>\n <c/>\n </b>\n </a>\n</r>\n" );
00069
00070 TEST_BEGIN( 0, 0 );
00071 writer.startElement( "a" );
00072 writer.startElement( "b", false );
00073 writer.startElement( "c" );
00074 writer.endElement();
00075 writer.addTextNode( "te" );
00076 writer.addTextNode( "xt" );
00077 writer.endElement();
00078 writer.endElement();
00079 TEST_END( "textnode test", "<r>\n <a>\n <b><c/>text</b>\n </a>\n</r>\n" );
00080
00081 TEST_BEGIN( 0, 0 );
00082 writer.startElement( "p", false );
00083 writer.addTextSpan( QString::fromLatin1( " \t\n foo " ) );
00084 writer.endElement();
00085 TEST_END( "textspan test", "<r>\n"
00086 " <p><text:s text:c=\"3\"/><text:tab/><text:line-break/> foo<text:s text:c=\"2\"/></p>\n"
00087 "</r>\n" );
00088
00089 TEST_BEGIN( 0, 0 );
00090 writer.startElement( "p", false );
00091 QMap<int, int> tabCache;
00092 tabCache.insert( 3, 0 );
00093 writer.addTextSpan( QString::fromUtf8( " \t\n foö " ), tabCache );
00094 writer.endElement();
00095 TEST_END( "textspan with tabcache", "<r>\n"
00096 " <p><text:s text:c=\"3\"/><text:tab text:tab-ref=\"1\"/><text:line-break/> foö<text:s text:c=\"2\"/></p>\n"
00097 "</r>\n" );
00098
00099 TEST_BEGIN( 0, 0 );
00100 writer.startElement( "p", false );
00101 writer.addProcessingInstruction( "opendocument foobar" );
00102 writer.addTextSpan( QString::fromLatin1( "foo" ) );
00103 writer.endElement();
00104 TEST_END( "processinginstruction test", "<r>\n"
00105 " <p><?opendocument foobar?>foo</p>\n"
00106 "</r>\n" );
00107
00108 TEST_BEGIN( 0, 0 );
00109 writer.addManifestEntry( QString::fromLatin1( "foo/bar/blah" ), QString::fromLatin1( "mime/type" ) );
00110 TEST_END( "addManifestEntry", "<r>\n <manifest:file-entry manifest:media-type=\"mime/type\" manifest:full-path=\"foo/bar/blah\"/>\n</r>\n" );
00111
00112 int sz = 15000;
00113 Q3CString x( sz );
00114 x.fill( 'x', sz );
00115 x += '&';
00116 Q3CString expected = "<r a=\"";
00117 expected += x + "amp;\"/>\n";
00118 TEST_BEGIN( 0, 0 );
00119 writer.addAttribute( "a", x );
00120 TEST_END( "escaping long cstring", expected.data() );
00121
00122 QString longPath;
00123 for ( uint i = 0 ; i < 1000 ; ++i )
00124 longPath += QString::fromLatin1( "M10 10L20 20 " );
00125 expected = "<r a=\"";
00126 expected += longPath.utf8() + "\"/>\n";
00127 TEST_BEGIN( 0, 0 );
00128 writer.addAttribute( "a", longPath );
00129 TEST_END( "escaping long qstring", expected.data() );
00130
00131
00132 TEST_BEGIN( 0, 0 );
00133 bool val = true;
00134 int num = 1;
00135 double numdouble = 5.0;
00136 writer.addConfigItem( QString::fromLatin1( "TestConfigBool" ), val );
00137 writer.addConfigItem( QString::fromLatin1( "TestConfigInt" ), num );
00138 writer.addConfigItem( QString::fromLatin1( "TestConfigDouble" ), numdouble );
00139 TEST_END( "test config", "<r>\n"
00140 " <config:config-item config:name=\"TestConfigBool\" config:type=\"boolean\">true</config:config-item>\n"
00141 " <config:config-item config:name=\"TestConfigInt\" config:type=\"int\">1</config:config-item>\n"
00142 " <config:config-item config:name=\"TestConfigDouble\" config:type=\"double\">5</config:config-item>\n"
00143 "</r>\n" );
00144
00145 speedTest();
00146 }