aboutsummaryrefslogtreecommitdiff
path: root/tests/ut_mcontainer/ut_mcontainer.cpp
blob: b60150d3e66f67ef1fb7b9134782a48a77394c8b (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include <QObject>
#include <QGraphicsLinearLayout>
#include <QGraphicsSceneMouseEvent>
#include <QSignalSpy>

#include <mcontainer.h>
#include "mcontainer_p.h"
#include <mcontainerview.h>
#include "views/mcontainerview_p.h"

#include "ut_mcontainer.h"
#include "mapplication.h"

#include "mcancelevent.h"

void Ut_MContainer::init()
{
    m_subject = new MContainer();
}

void Ut_MContainer::cleanup()
{
    delete m_subject;
    m_subject = 0;
}
MApplication *app;

void Ut_MContainer::initTestCase()
{
    static int argc = 1;
    static char *app_name[1] = { (char *) "./ut_mcontainer" };
    app = new MApplication(argc, app_name);
}

void Ut_MContainer::cleanupTestCase()
{
    delete app;
}

void Ut_MContainer::centralWidget()
{
    // check that there exists centralWidget
    QVERIFY(m_subject->centralWidget() != NULL);
}

void Ut_MContainer::setCentralWidget()
{
    MWidget *tmp = new MWidget();

    m_subject->setCentralWidget(tmp);

    // check that there exists centralWidget
    QVERIFY(m_subject->centralWidget() == tmp);

    delete tmp;
}

void Ut_MContainer::title()
{
    QString myQString("testing title()");

    m_subject->setTitle(myQString);
    QCOMPARE(m_subject->title(), myQString);
}

void Ut_MContainer::text()
{
    QString myQString("testing text()");

    m_subject->setText(myQString);
    QCOMPARE(m_subject->text(), myQString);
}

void Ut_MContainer::iconID()
{
    QString myIconID("testing iconID()");

    m_subject->setIconID(myIconID);
    QCOMPARE(m_subject->iconID(), myIconID);
}

void Ut_MContainer::headerVisible()
{
    // default state
    QVERIFY(m_subject->headerVisible() == true);

    m_subject->setHeaderVisible(false);

    QVERIFY(m_subject->headerVisible() == false);
}

void Ut_MContainer::toggleHeaderVisible()
{
    // default state
    QVERIFY(m_subject->headerVisible() == true);

    m_subject->toggleHeaderVisible();

    QVERIFY(m_subject->headerVisible() == false);

    m_subject->toggleHeaderVisible();

    QVERIFY(m_subject->headerVisible() == true);
}


void Ut_MContainer::toggleProgressIndicatorVisible()
{
    // default state
    QVERIFY(m_subject->isProgressIndicatorVisible() == false);

    m_subject->toggleProgressIndicatorVisible();

    QVERIFY(m_subject->isProgressIndicatorVisible() == true);

    m_subject->toggleProgressIndicatorVisible();

    QVERIFY(m_subject->isProgressIndicatorVisible() == false);
}

void Ut_MContainer::testCreatingViewImmediatelyInLayout()
{
    //Add the container to a layout then force the view to be created by calling minimumSize()
    QGraphicsLinearLayout layout(Qt::Horizontal);
    layout.addItem(m_subject);
    m_subject->minimumSize();

}
void Ut_MContainer::testCreatingViewImmediately()
{
    //Force the view to be created by calling minimumSize()
    //This checks BUG:126088 which causes a segmentation fault
    m_subject->minimumSize();
}

void Ut_MContainer::testCancelEvent()
{
    QSignalSpy spy(m_subject, SIGNAL(headerClicked()));

    QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress);
    m_subject->mousePressEvent(&mouseEvent);

    MCancelEvent event;
    m_subject->cancelEvent(&event);

    QVERIFY(spy.count() == 0);
}

// test all of the set/get with both visible and invisble header, because it should work for instance
// that one sets the e.g. iconID now and makes the header visible later

void Ut_MContainer::setTitleWithHeaderVisible()
{
    m_subject->setHeaderVisible(true);
    m_subject->setTitle("title");

    QCOMPARE(m_subject->title(), QString("title"));
}

void Ut_MContainer::setTitleWithHeaderInvisible()
{
    m_subject->setHeaderVisible(false);
    m_subject->setTitle("title");

    QCOMPARE(m_subject->title(), QString("title"));
}

void Ut_MContainer::setIconIDWithHeaderVisible()
{
    m_subject->setHeaderVisible(true);
    m_subject->setIconID("Icon-close");

    QCOMPARE(m_subject->iconID(), QString("Icon-close"));
}

void Ut_MContainer::setIconIDWithHeaderInvisible()
{
    m_subject->setHeaderVisible(false);
    m_subject->setIconID("Icon-close");

    QCOMPARE(m_subject->iconID(), QString("Icon-close"));
}

void Ut_MContainer::setTextWithHeaderVisible()
{
    m_subject->setHeaderVisible(true);
    m_subject->setText("text");

    QCOMPARE(m_subject->text(), QString("text"));
}

void Ut_MContainer::setTextWithHeaderInvisible()
{
    m_subject->setHeaderVisible(false);
    m_subject->setText("text");

    QCOMPARE(m_subject->text(), QString("text"));
}

void Ut_MContainer::setProgressIndicatorVisible()
{
    m_subject->setProgressIndicatorVisible(true);
    QCOMPARE(m_subject->isProgressIndicatorVisible(), true);
}

void Ut_MContainer::setProgressIndicatorInVisible()
{
    m_subject->setProgressIndicatorVisible(false);
    QCOMPARE(m_subject->isProgressIndicatorVisible(), false);
}

void Ut_MContainer::setProgressIndicatorWithHeaderVisible()
{
    m_subject->setHeaderVisible(true);
    m_subject->setProgressIndicatorVisible(true);
    QCOMPARE(m_subject->isProgressIndicatorVisible(), true);
}

void Ut_MContainer::setProgressIndicatorWithHeaderInvisible()
{
    m_subject->setHeaderVisible(false);
    m_subject->setProgressIndicatorVisible(true);
    QCOMPARE(m_subject->isProgressIndicatorVisible(), true);
}


QTEST_APPLESS_MAIN(Ut_MContainer)