summaryrefslogtreecommitdiffstats
path: root/lib/store/tests/xmlwritertest.cpp
blob: d4fc14f47705349e8b9637d7929748b6a5386915 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "xmlwritertest.h"

#include "KoXmlWriter.h"

#include <tqapplication.h>
#include <tqfile.h>
#include <tqdatetime.h>

static const int numParagraphs = 30000;
void speedTest()
{
    TQTime time;
    time.start();
    TQString paragText = TQString::fromUtf8( "This is the text of the paragraph. I'm including a euro sign to test encoding issues: €" );
    TQCString styleName = "Heading 1";

    TQFile out( TQString::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();
    tqDebug( "writing %i XML elements using KoXmlWriter: %i ms", numParagraphs, time.elapsed() );
}

int main( int argc, char** argv ) {
    TQApplication app( argc, argv, TQApplication::Tty );

    TEST_BEGIN( 0, 0 );
    TEST_END( "framework test", "<r/>\n" );

    TEST_BEGIN( "-//KDE//DTD kword 1.3//EN", "http://www.koffice.org/DTD/kword-1.3.dtd" );
    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" );

    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", "<r a=\"val\" b=\"&lt;&quot;&gt;\" c=\"-42\" d=\"1234.56789012345\" e=\"1234.56789012345pt\"/>\n" );

    TEST_BEGIN( 0, 0 );
    writer.startElement( "m" );
    writer.endElement();
    TEST_END( "empty element test", "<r>\n <m/>\n</r>\n" );

    TEST_BEGIN( 0, 0 );
    writer.startElement( "a" );
    writer.startElement( "b" );
    writer.startElement( "c" );
    writer.endElement();
    writer.endElement();
    writer.endElement();
    TEST_END( "indent test", "<r>\n <a>\n  <b>\n   <c/>\n  </b>\n </a>\n</r>\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", "<r>\n <a>\n  <b><c/>text</b>\n </a>\n</r>\n" );

    TEST_BEGIN( 0, 0 );
    writer.startElement( "p", false /*no indent*/ );
    writer.addTextSpan( TQString::fromLatin1( "   \t\n foo  " ) );
    writer.endElement();
    TEST_END( "textspan test", "<r>\n"
              " <p><text:s text:c=\"3\"/><text:tab/><text:line-break/> foo<text:s text:c=\"2\"/></p>\n"
              "</r>\n" );

    TEST_BEGIN( 0, 0 );
    writer.startElement( "p", false /*no indent*/ );
    TQMap<int, int> tabCache;
    tabCache.insert( 3, 0 );
    writer.addTextSpan( TQString::fromUtf8( "   \t\n foö  " ), tabCache );
    writer.endElement();
    TEST_END( "textspan with tabcache", "<r>\n"
              " <p><text:s text:c=\"3\"/><text:tab text:tab-ref=\"1\"/><text:line-break/> foö<text:s text:c=\"2\"/></p>\n"
              "</r>\n" );

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

    TEST_BEGIN( 0, 0 );
    writer.addManifestEntry( TQString::fromLatin1( "foo/bar/blah" ), TQString::fromLatin1( "mime/type" ) );
    TEST_END( "addManifestEntry", "<r>\n <manifest:file-entry manifest:media-type=\"mime/type\" manifest:full-path=\"foo/bar/blah\"/>\n</r>\n" );

    int sz = 15000;  // must be more than KoXmlWriter::s_escapeBufferLen
    TQCString x( sz );
    x.fill( 'x', sz );
    x += '&';
    TQCString expected = "<r a=\"";
    expected += x + "amp;\"/>\n";
    TEST_BEGIN( 0, 0 );
    writer.addAttribute( "a", x );
    TEST_END( "escaping long cstring", expected.data() );

    TQString longPath;
    for ( uint i = 0 ; i < 1000 ; ++i )
        longPath += TQString::fromLatin1( "M10 10L20 20 " );
    expected = "<r a=\"";
    expected += longPath.utf8() + "\"/>\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( TQString::fromLatin1( "TestConfigBool" ), val );
    writer.addConfigItem( TQString::fromLatin1( "TestConfigInt" ), num );
    writer.addConfigItem( TQString::fromLatin1( "TestConfigDouble" ), numdouble );
    TEST_END( "test config", "<r>\n"
                             " <config:config-item config:name=\"TestConfigBool\" config:type=\"boolean\">true</config:config-item>\n"
                             " <config:config-item config:name=\"TestConfigInt\" config:type=\"int\">1</config:config-item>\n"
                             " <config:config-item config:name=\"TestConfigDouble\" config:type=\"double\">5</config:config-item>\n"
                             "</r>\n" );

    speedTest();
}