From 8362bf63dea22bbf6736609b0f49c152f975eb63 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 20 Jan 2010 01:29:50 +0000 Subject: Added old abandoned KDE3 version of koffice git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- lib/store/tests/xmlwritertest.cpp | 144 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 lib/store/tests/xmlwritertest.cpp (limited to 'lib/store/tests/xmlwritertest.cpp') diff --git a/lib/store/tests/xmlwritertest.cpp b/lib/store/tests/xmlwritertest.cpp new file mode 100644 index 000000000..dad86f8f4 --- /dev/null +++ b/lib/store/tests/xmlwritertest.cpp @@ -0,0 +1,144 @@ +#include "xmlwritertest.h" + +#include "KoXmlWriter.h" + +#include +#include +#include + +static const int numParagraphs = 30000; +void speedTest() +{ + QTime time; + time.start(); + QString paragText = QString::fromUtf8( "This is the text of the paragraph. I'm including a euro sign to test encoding issues: €" ); + QCString styleName = "Heading 1"; + + QFile out( QString::fromLatin1( "out5.xml" ) ); + if ( out.open(IO_WriteOnly) ) + { + KoXmlWriter writer( &out ); + writer.startDocument( "rootelem" ); + writer.startElement( "rootelem" ); + for ( int i = 0 ; i < numParagraphs ; ++i ) + { + writer.startElement( "paragraph" ); + writer.addAttribute( "text:style-name", styleName ); + writer.addTextNode( paragText ); + writer.endElement(); + } + writer.endElement(); + writer.endDocument(); + } + out.close(); + qDebug( "writing %i XML elements using KoXmlWriter: %i ms", numParagraphs, time.elapsed() ); +} + +int main( int argc, char** argv ) { + QApplication app( argc, argv, QApplication::Tty ); + + TEST_BEGIN( 0, 0 ); + TEST_END( "framework test", "\n" ); + + TEST_BEGIN( "-//KDE//DTD kword 1.3//EN", "http://www.koffice.org/DTD/kword-1.3.dtd" ); + TEST_END( "doctype test", "\n\n" ); + + TEST_BEGIN( 0, 0 ); + writer.addAttribute( "a", "val" ); + writer.addAttribute( "b", "<\">" ); + writer.addAttribute( "c", -42 ); + writer.addAttribute( "d", 1234.56789012345 ); + writer.addAttributePt( "e", 1234.56789012345 ); + TEST_END( "attributes test", "\n" ); + + TEST_BEGIN( 0, 0 ); + writer.startElement( "m" ); + writer.endElement(); + TEST_END( "empty element test", "\n \n\n" ); + + TEST_BEGIN( 0, 0 ); + writer.startElement( "a" ); + writer.startElement( "b" ); + writer.startElement( "c" ); + writer.endElement(); + writer.endElement(); + writer.endElement(); + TEST_END( "indent test", "\n \n \n \n \n \n\n" ); + + TEST_BEGIN( 0, 0 ); + writer.startElement( "a" ); + writer.startElement( "b", false /*no indent*/ ); + writer.startElement( "c" ); + writer.endElement(); + writer.addTextNode( "te" ); + writer.addTextNode( "xt" ); + writer.endElement(); + writer.endElement(); + TEST_END( "textnode test", "\n \n text\n \n\n" ); + + TEST_BEGIN( 0, 0 ); + writer.startElement( "p", false /*no indent*/ ); + writer.addTextSpan( QString::fromLatin1( " \t\n foo " ) ); + writer.endElement(); + TEST_END( "textspan test", "\n" + "

foo

\n" + "
\n" ); + + TEST_BEGIN( 0, 0 ); + writer.startElement( "p", false /*no indent*/ ); + QMap tabCache; + tabCache.insert( 3, 0 ); + writer.addTextSpan( QString::fromUtf8( " \t\n foö " ), tabCache ); + writer.endElement(); + TEST_END( "textspan with tabcache", "\n" + "

foö

\n" + "
\n" ); + + TEST_BEGIN( 0, 0 ); + writer.startElement( "p", false /*no indent*/ ); + writer.addProcessingInstruction( "opendocument foobar" ); + writer.addTextSpan( QString::fromLatin1( "foo" ) ); + writer.endElement(); + TEST_END( "processinginstruction test", "\n" + "

foo

\n" + "
\n" ); + + TEST_BEGIN( 0, 0 ); + writer.addManifestEntry( QString::fromLatin1( "foo/bar/blah" ), QString::fromLatin1( "mime/type" ) ); + TEST_END( "addManifestEntry", "\n \n\n" ); + + int sz = 15000; // must be more than KoXmlWriter::s_escapeBufferLen + QCString x( sz ); + x.fill( 'x', sz ); + x += '&'; + QCString expected = "\n"; + TEST_BEGIN( 0, 0 ); + writer.addAttribute( "a", x ); + TEST_END( "escaping long cstring", expected.data() ); + + QString longPath; + for ( uint i = 0 ; i < 1000 ; ++i ) + longPath += QString::fromLatin1( "M10 10L20 20 " ); + expected = "\n"; + TEST_BEGIN( 0, 0 ); + writer.addAttribute( "a", longPath ); + TEST_END( "escaping long qstring", expected.data() ); + + + TEST_BEGIN( 0, 0 ); + bool val = true; + int num = 1; + double numdouble = 5.0; + writer.addConfigItem( QString::fromLatin1( "TestConfigBool" ), val ); + writer.addConfigItem( QString::fromLatin1( "TestConfigInt" ), num ); + writer.addConfigItem( QString::fromLatin1( "TestConfigDouble" ), numdouble ); + TEST_END( "test config", "\n" + " true\n" + " 1\n" + " 5\n" + "\n" ); + + speedTest(); +} -- cgit v1.2.3