aboutsummaryrefslogtreecommitdiff
path: root/tests/ut_mnavigationbarview/ut_mnavigationbarview.cpp
blob: bdca9bbd2d8c28b24e4f9ce22fc96ae66680cf43 (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
/***************************************************************************
**
** 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 "ut_mnavigationbarview.h"

#include "mnavigationbarview_p.h"

#include <QGraphicsLayout>
#include <MLinearLayoutPolicy>
#include <mnavigationbarstyle.h>
#include <MToolBar>

Q_DECLARE_METATYPE(MNavigationBarModel::EscapeButtonModeEnum)

void Ut_MNavigationBarView::init()
{
    controller = new MNavigationBar();
    subject = new MNavigationBarView(controller);
    controller->setView(subject);
    model = controller->model();
}

void Ut_MNavigationBarView::cleanup()
{
    delete controller;
    controller = 0;
}

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


}

void Ut_MNavigationBarView::cleanupTestCase()
{
    delete app;
    app = 0;
}

void Ut_MNavigationBarView::testCustomContentOwnershipTransfer()
{
    // OBS: The ownership of customContent is transfered by
    // MNavigationBarView code.
    // That's why this test is here and not in Ut_MNavigationBar

    QGraphicsWidget *customContent = new QGraphicsWidget;

    controller->setCustomContent(customContent);

    QVERIFY(controller->isAncestorOf(customContent));

    controller->setCustomContent(0);

    QVERIFY(customContent->scene() == 0);
    QVERIFY(customContent->parent() == 0);

    // Clean up
    delete customContent;
}

void Ut_MNavigationBarView::testCustomContentPolicySelection()
{
    QGraphicsWidget *customContent = new QGraphicsWidget;

    QCOMPARE(subject->d_func()->customContentPolicy->isActive(), false);

    controller->setCustomContent(customContent);

    QCOMPARE(subject->d_func()->customContentPolicy->isActive(), true);

    controller->setCustomContent(0);

    QCOMPARE(subject->d_func()->customContentPolicy->isActive(), false);

    // Clean up
    delete customContent;
}

void Ut_MNavigationBarView::testIsEmptyProperty_data()
{
    QTest::addColumn<bool>("hasTitle");
    QTest::addColumn<bool>("hasCloseButton");
    QTest::addColumn<bool>("hasToolBar");
    QTest::addColumn<bool>("toolBarIsEmpty");
    QTest::addColumn<MNavigationBarModel::EscapeButtonModeEnum>("escapeButtonMode");
    QTest::addColumn<bool>("hasCustomContent");
    QTest::addColumn<bool>("isEmptyExpectedValue");

    QTest::newRow("not empty when with custom content")
            << false // hasTitle
            << false // hasCloseButton
            << false // hasToolBar
            << true // toolBarIsEmpty
            << MNavigationBarModel::EscapeButtonClose // escapeButtonMode
            << true // hasCustomContent
            << false /* isEmptyExpectedValue */;

    QTest::newRow("not empty when it has only a title")
            << true // hasTitle
            << false // hasCloseButton
            << false // hasToolBar
            << true // toolBarIsEmpty
            << MNavigationBarModel::EscapeButtonClose // escapeButtonMode
            << false // hasCustomContent
            << false /* isEmptyExpectedValue */;

    QTest::newRow("empty when there's not even a close button")
            << false // hasTitle
            << false // hasCloseButton
            << false // hasToolBar
            << true // toolBarIsEmpty
            << MNavigationBarModel::EscapeButtonClose // escapeButtonMode
            << false // hasCustomContent
            << true /* isEmptyExpectedValue */;

    QTest::newRow("not empty when there's no close button but we are in back mode")
            << false // hasTitle
            << false // hasCloseButton
            << false // hasToolBar
            << true // toolBarIsEmpty
            << MNavigationBarModel::EscapeButtonBack // escapeButtonMode
            << false // hasCustomContent
            << false /* isEmptyExpectedValue */;

    QTest::newRow("not empty when there's only a populated tool bar")
            << false // hasTitle
            << false // hasCloseButton
            << true // hasToolBar
            << false // toolBarIsEmpty
            << MNavigationBarModel::EscapeButtonClose // escapeButtonMode
            << false // hasCustomContent
            << true /* isEmptyExpectedValue */;

    QTest::newRow("empty when there's only an empty tool bar")
            << false // hasTitle
            << false // hasCloseButton
            << true // hasToolBar
            << true // toolBarIsEmpty
            << MNavigationBarModel::EscapeButtonClose // escapeButtonMode
            << false // hasCustomContent
            << true /* isEmptyExpectedValue */;
}

void Ut_MNavigationBarView::testIsEmptyProperty()
{
    MToolBar *toolBar = 0;
    QFETCH(bool, hasTitle);
    QFETCH(bool, hasCloseButton);
    QFETCH(bool, hasToolBar);
    QFETCH(bool, toolBarIsEmpty);
    QFETCH(MNavigationBarModel::EscapeButtonModeEnum, escapeButtonMode);
    QFETCH(bool, hasCustomContent);
    QFETCH(bool, isEmptyExpectedValue);

    MNavigationBarStyle *style = (MNavigationBarStyle *)subject->style().operator->();

    style->setHasTitle(hasTitle);
    style->setHasCloseButton(hasCloseButton);
    subject->applyStyle();

    if (hasToolBar) {
        toolBar = new MToolBar;
        toolBar->setProperty("isEmpty", toolBarIsEmpty);
        model->setToolBar(toolBar);
    }

    model->setEscapeButtonMode(escapeButtonMode);

    if (hasCustomContent) {
        model->setCustomContent(new QGraphicsWidget);
    } else {
        model->setCustomContent(0);
    }

    QCOMPARE(controller->property("isEmpty").toBool(), isEmptyExpectedValue);

    // clean up
    if (toolBar) {
        model->setToolBar(0);
        delete toolBar;
    }
}

void Ut_MNavigationBarView::testDockedToolBarChangingItsIsEmptyProperty()
{
    MToolBar *toolBar = new MToolBar;
    MNavigationBarStyle *style = (MNavigationBarStyle *)subject->style().operator->();

    style->setHasTitle(false);
    style->setHasCloseButton(false);
    subject->applyStyle();

    model->setToolBar(toolBar);
    model->setEscapeButtonMode(MNavigationBarModel::EscapeButtonClose);

    // Since navigation bar is populated only by its docked toolbar, its isEmpty
    // property will follow toolbar's one.

    toolBar->setProperty("isEmpty", true);
    QCOMPARE(controller->property("isEmpty").toBool(), true);

    toolBar->setProperty("isEmpty", false);
    QCOMPARE(controller->property("isEmpty").toBool(), false);

    toolBar->setProperty("isEmpty", true);
    QCOMPARE(controller->property("isEmpty").toBool(), true);

    model->setToolBar(0);
    toolBar->setProperty("isEmpty", false);

    // tool bar is no longer docked, thus navigation bar should no longer follow it
    QCOMPARE(controller->property("isEmpty").toBool(), true);

    // clean up
    delete toolBar;
}

QTEST_APPLESS_MAIN(Ut_MNavigationBarView)