File: TestSections.cpp

package info (click to toggle)
koffice 1%3A2.2.1-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 157,656 kB
  • ctags: 110,762
  • sloc: cpp: 889,358; xml: 22,758; ansic: 6,533; python: 5,224; perl: 2,771; sh: 1,805; yacc: 1,304; ruby: 1,219; sql: 720; lex: 455; makefile: 76
file content (142 lines) | stat: -rw-r--r-- 4,364 bytes parent folder | download
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
#include "TestSections.h"

#include <KoStyleManager.h>
#include <KoTextDocument.h>
#include <KoSectionStyle.h>

#include <QTextDocument>
#include <QTextFrame>
#include <QTextCursor>
#include <QPoint>
#include <QString>
#include <QPen>

void TestSections::init()
{
    m_doc = 0;
    m_table = 0;
    m_layout = 0;
    m_styleManager = 0;
    m_textLayout = 0;
    m_shape = 0;
    m_defaultSectionStyle = 0;
}

void TestSections::initTest(const KoSectionStyle *sectionStyle)
{
    // Mock shape of size 200x1000 pt.
    m_shape = new MockTextShape();
    Q_ASSERT(m_shape);
    m_shape->setSize(QSizeF(200, 1000));

    // Document layout.
    m_layout = m_shape->layout;
    Q_ASSERT(m_layout);

    // Document.
    m_doc = m_layout->document();
    Q_ASSERT(m_doc);
    m_doc->setDefaultFont(QFont("Sans Serif", 12, QFont::Normal, false));

    // Layout state (layout helper).
    m_textLayout = new Layout(m_layout);
    Q_ASSERT(m_textLayout);
    m_layout->setLayout(m_textLayout);

    // Style manager.
    m_styleManager = new KoStyleManager();
    Q_ASSERT(m_styleManager);
    KoTextDocument(m_doc).setStyleManager(m_styleManager);

    // Table style.
    m_defaultSectionStyle = new KoSectionStyle();
    Q_ASSERT(m_defaultSectionStyle);
    m_defaultSectionStyle->setLeftMargin(0.0);
    m_defaultSectionStyle->setRightMargin(0.0);
    
    QString loremIpsum("Lorem ipsum dolor sit amet, XgXgectetuer adiXiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.");

    m_doc->rootFrame()->firstCursorPosition().insertText(loremIpsum);
    
    // Style.
    QTextFrameFormat sectionFormat;
    sectionStyle->applyStyle(sectionFormat);
    QTextFrame *section = m_doc->rootFrame()->firstCursorPosition().insertFrame(sectionFormat);
    
    section->firstCursorPosition().insertText(loremIpsum);
}

void TestSections::cleanupTest()
{
    delete m_styleManager;
    delete m_defaultSectionStyle;
}

void TestSections::testBasicLayout()
{
    KoSectionStyle *sectionStyle = new KoSectionStyle();
    Q_ASSERT(sectionStyle);
    sectionStyle->setLeftMargin(0.0);
    sectionStyle->setRightMargin(0.0);
    
    initTest(sectionStyle);

    m_layout->layout();

    // a block in a section with no special margins or columns should be just as wide
    // as the reference (first) block.
    QTextLayout *blockLayout = m_doc->begin().layout();
    QCOMPARE(blockLayout->lineAt(0).width(), 200.0);

    blockLayout = m_doc->begin().next().layout();
    QCOMPARE(blockLayout->lineAt(0).width(), 200.0);
    cleanupTest();
}

void TestSections::testShrinkByMargin()
{
    KoSectionStyle *sectionStyle = new KoSectionStyle();
    Q_ASSERT(sectionStyle);
    sectionStyle->setLeftMargin(20.0);
    sectionStyle->setRightMargin(20.0);

    initTest(sectionStyle);

    m_layout->layout();

    // a block in a section with margins (and no columns) should be exact amoung less wide
    // as the reference (first) block.
    QTextLayout *blockLayout = m_doc->begin().layout();
    QCOMPARE(blockLayout->lineAt(0).width(), 200.0);

    blockLayout = m_doc->begin().next().layout();
    QEXPECT_FAIL("", "unimplemented", Abort);
    QCOMPARE(blockLayout->lineAt(0).width(), 160.0);
    cleanupTest();
}

void TestSections::testMoveByMargin()
{
    KoSectionStyle *sectionStyle = new KoSectionStyle();
    Q_ASSERT(sectionStyle);
    sectionStyle->setLeftMargin(20.0);
    sectionStyle->setRightMargin(-20.0);

    initTest(sectionStyle);

    m_layout->layout();

    // a block in a section with margins (and no columns) that essentially just moves the block
    // should be just as wide as the reference (first) block.
    QTextLayout *blockLayout = m_doc->begin().layout();
    QCOMPARE(blockLayout->lineAt(0).width(), 200.0);

    blockLayout = m_doc->begin().next().layout();
    QCOMPARE(blockLayout->lineAt(0).width(), 200.0);
    cleanupTest();
}


QTEST_KDEMAIN(TestSections, GUI)

#include <TestSections.moc>