90
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#ifndef ONLY_MENU_TESTCASES
|
|
19 |
|
|
20 |
#include "t_hsutils.h"
|
|
21 |
#include "hspageindicator.h"
|
|
22 |
#include "hspageindicatoritem.h"
|
|
23 |
|
|
24 |
#include <QGraphicsLayout>
|
|
25 |
#include <QGraphicsLinearLayout>
|
|
26 |
|
|
27 |
void t_hsUtils::testPageIndicatorConstruction()
|
|
28 |
{
|
|
29 |
HsPageIndicator pi(8);
|
|
30 |
QCOMPARE(pi.itemCount(), 0);
|
|
31 |
QCOMPARE(pi.activeItemIndex(), -1);
|
|
32 |
|
|
33 |
pi.initialize(-1, -1);
|
|
34 |
QCOMPARE(pi.itemCount(), 0);
|
|
35 |
QCOMPARE(pi.activeItemIndex(), -1);
|
|
36 |
|
|
37 |
pi.initialize(0, -1);
|
|
38 |
QCOMPARE(pi.itemCount(), 0);
|
|
39 |
QCOMPARE(pi.activeItemIndex(), -1);
|
|
40 |
|
|
41 |
pi.initialize(1, -1);
|
|
42 |
QCOMPARE(pi.itemCount(), 0);
|
|
43 |
QCOMPARE(pi.activeItemIndex(), -1);
|
|
44 |
|
|
45 |
pi.initialize(1, 2);
|
|
46 |
QCOMPARE(pi.itemCount(), 0);
|
|
47 |
QCOMPARE(pi.activeItemIndex(), -1);
|
|
48 |
|
|
49 |
pi.initialize(3, 1);
|
|
50 |
QCOMPARE(pi.itemCount(), 3);
|
|
51 |
QCOMPARE(pi.activeItemIndex(), 1);
|
|
52 |
|
|
53 |
pi.initialize(3, 2);
|
|
54 |
QCOMPARE(pi.itemCount(), 3);
|
|
55 |
QCOMPARE(pi.activeItemIndex(), 2);
|
|
56 |
}
|
|
57 |
|
|
58 |
void t_hsUtils::testPageIndicatorActiveItem()
|
|
59 |
{
|
|
60 |
HsPageIndicator pi(8);
|
|
61 |
pi.initialize(3, 1);
|
|
62 |
QCOMPARE(pi.itemCount(), 3);
|
|
63 |
QCOMPARE(pi.activeItemIndex(), 1);
|
|
64 |
|
|
65 |
pi.setActiveItemIndex(1);
|
|
66 |
QCOMPARE(pi.activeItemIndex(), 1);
|
|
67 |
|
|
68 |
pi.setActiveItemIndex(0);
|
|
69 |
QCOMPARE(pi.activeItemIndex(), 0);
|
|
70 |
|
|
71 |
pi.setActiveItemIndex(2);
|
|
72 |
QCOMPARE(pi.activeItemIndex(), 2);
|
|
73 |
|
|
74 |
pi.setActiveItemIndex(-1);
|
|
75 |
QCOMPARE(pi.activeItemIndex(), 2);
|
|
76 |
|
|
77 |
pi.setActiveItemIndex(3);
|
|
78 |
QCOMPARE(pi.activeItemIndex(), 2);
|
|
79 |
|
|
80 |
QCOMPARE(pi.mItems.at(0)->isActive(), false);
|
|
81 |
QCOMPARE(pi.mItems.at(1)->isActive(), false);
|
|
82 |
QCOMPARE(pi.mItems.at(2)->isActive(), true);
|
|
83 |
}
|
|
84 |
|
|
85 |
void t_hsUtils::testPageIndicatorAddRemoveItem()
|
|
86 |
{
|
|
87 |
HsPageIndicator pi(8);
|
|
88 |
pi.initialize(3, 1);
|
|
89 |
QCOMPARE(pi.itemCount(), 3);
|
|
90 |
QCOMPARE(pi.activeItemIndex(), 1);
|
|
91 |
|
|
92 |
pi.addItem(-1);
|
|
93 |
QCOMPARE(pi.itemCount(), 3);
|
|
94 |
QCOMPARE(pi.activeItemIndex(), 1);
|
|
95 |
|
|
96 |
pi.addItem(4);
|
|
97 |
QCOMPARE(pi.itemCount(), 3);
|
|
98 |
QCOMPARE(pi.activeItemIndex(), 1);
|
|
99 |
|
|
100 |
pi.addItem(0);
|
|
101 |
QCOMPARE(pi.itemCount(), 4);
|
|
102 |
QCOMPARE(pi.activeItemIndex(), 0);
|
|
103 |
|
|
104 |
pi.addItem(4);
|
|
105 |
QCOMPARE(pi.itemCount(), 5);
|
|
106 |
QCOMPARE(pi.activeItemIndex(), 4);
|
|
107 |
|
|
108 |
pi.addItem(6);
|
|
109 |
QCOMPARE(pi.itemCount(), 5);
|
|
110 |
QCOMPARE(pi.activeItemIndex(), 4);
|
|
111 |
|
|
112 |
pi.removeItem(-1);
|
|
113 |
QCOMPARE(pi.itemCount(), 5);
|
|
114 |
QCOMPARE(pi.activeItemIndex(), 4);
|
|
115 |
|
|
116 |
pi.removeItem(5);
|
|
117 |
QCOMPARE(pi.itemCount(), 5);
|
|
118 |
QCOMPARE(pi.activeItemIndex(), 4);
|
|
119 |
|
|
120 |
pi.removeItem(4);
|
|
121 |
QCOMPARE(pi.itemCount(), 4);
|
|
122 |
QCOMPARE(pi.activeItemIndex(), 3);
|
|
123 |
|
|
124 |
pi.removeItem(3);
|
|
125 |
QCOMPARE(pi.itemCount(), 3);
|
|
126 |
QCOMPARE(pi.activeItemIndex(), 2);
|
|
127 |
|
|
128 |
pi.removeItem(0);
|
|
129 |
QCOMPARE(pi.itemCount(), 2);
|
|
130 |
QCOMPARE(pi.activeItemIndex(), 0);
|
|
131 |
}
|
|
132 |
|
|
133 |
void t_hsUtils::testPageIndicatorAnimations()
|
|
134 |
{
|
|
135 |
HsPageIndicator pi(8);
|
|
136 |
pi.initialize(3, 1);
|
|
137 |
pi.setSpacing(8);
|
|
138 |
|
|
139 |
QCOMPARE(pi.isAnimationRunning(), false);
|
|
140 |
pi.setActiveItemIndex(0);
|
|
141 |
QCOMPARE(pi.isAnimationRunning(), true);
|
|
142 |
|
|
143 |
int i = 5;
|
|
144 |
do {
|
|
145 |
QTest::qWait(1000);
|
|
146 |
} while (pi.isAnimationRunning() && --i);
|
|
147 |
if (!i) {
|
|
148 |
QFAIL("testPageIndicatorAnimations() failed");
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
#endif // ONLY_MENU_TESTCASES
|