45
|
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: Test class for CalenDayContentWidget
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include <QGraphicsItem>
|
|
18 |
#include <QtTest/QtTest>
|
|
19 |
|
57
|
20 |
#include "hbstyle.h"
|
45
|
21 |
#include "calendayutils.h"
|
55
|
22 |
#include "hbdeviceprofile.h"
|
45
|
23 |
#include "calendaycommonheaders.h"
|
|
24 |
|
|
25 |
// Test variables
|
|
26 |
QRectF gTestWindowRect = QRectF(0, 0, 10, 20);
|
|
27 |
Qt::Orientation gTestOrientation = Qt::Horizontal;
|
55
|
28 |
qreal param_value = 10;
|
57
|
29 |
qreal unitInPix = 1;
|
45
|
30 |
|
|
31 |
class TestCalenDayUtils : public QObject
|
55
|
32 |
{
|
45
|
33 |
Q_OBJECT
|
|
34 |
|
|
35 |
public:
|
55
|
36 |
TestCalenDayUtils();
|
|
37 |
virtual ~TestCalenDayUtils();
|
45
|
38 |
|
|
39 |
private slots:
|
55
|
40 |
void initTestCase();
|
|
41 |
void cleanupTestCase();
|
|
42 |
void init();
|
|
43 |
void cleanup();
|
45
|
44 |
|
55
|
45 |
void testInstance();
|
|
46 |
void testScreenWidth();
|
|
47 |
void testHourElementWidth();
|
|
48 |
void testHourElementHeight();
|
|
49 |
void testContentWidth();
|
|
50 |
|
|
51 |
void testConstructors();
|
|
52 |
void testOrientation();
|
45
|
53 |
|
|
54 |
private:
|
55
|
55 |
CalenDayUtils *mUtils;
|
|
56 |
qreal mUnit;
|
|
57 |
};
|
45
|
58 |
|
|
59 |
/*!
|
|
60 |
Constructor
|
|
61 |
*/
|
|
62 |
TestCalenDayUtils::TestCalenDayUtils() :
|
55
|
63 |
mUtils(NULL)
|
|
64 |
{
|
|
65 |
HbDeviceProfile s;
|
|
66 |
mUnit = s.unitValue();
|
|
67 |
}
|
45
|
68 |
|
|
69 |
/*!
|
|
70 |
Destructor
|
|
71 |
*/
|
|
72 |
TestCalenDayUtils::~TestCalenDayUtils()
|
55
|
73 |
{
|
45
|
74 |
|
55
|
75 |
}
|
45
|
76 |
|
|
77 |
/*!
|
|
78 |
Called before testcase
|
|
79 |
*/
|
|
80 |
void TestCalenDayUtils::initTestCase()
|
55
|
81 |
{
|
|
82 |
}
|
45
|
83 |
|
|
84 |
/*!
|
|
85 |
Called after testcase
|
|
86 |
*/
|
|
87 |
void TestCalenDayUtils::cleanupTestCase()
|
55
|
88 |
{
|
|
89 |
}
|
45
|
90 |
|
|
91 |
/*!
|
|
92 |
Called before every function
|
|
93 |
*/
|
|
94 |
void TestCalenDayUtils::init()
|
55
|
95 |
{
|
|
96 |
mUtils = CalenDayUtils::instance();
|
|
97 |
}
|
45
|
98 |
|
|
99 |
/*!
|
|
100 |
Called after everyfunction
|
|
101 |
*/
|
|
102 |
void TestCalenDayUtils::cleanup()
|
55
|
103 |
{
|
|
104 |
//delete mUtils;
|
|
105 |
}
|
|
106 |
|
|
107 |
void TestCalenDayUtils::testInstance()
|
|
108 |
{
|
|
109 |
CalenDayUtils* utils = CalenDayUtils::instance();
|
|
110 |
QVERIFY(utils);
|
|
111 |
}
|
|
112 |
|
|
113 |
void TestCalenDayUtils::testScreenWidth()
|
|
114 |
{
|
|
115 |
qreal sw = mUtils->screenWidth();
|
|
116 |
QVERIFY(sw == gTestWindowRect.width());
|
|
117 |
}
|
|
118 |
|
|
119 |
void TestCalenDayUtils::testHourElementWidth()
|
|
120 |
{
|
|
121 |
qreal hEW = mUtils->hourElementWidth();
|
|
122 |
qreal myWidth = mUnit * 8.04 + param_value * 2;
|
|
123 |
|
|
124 |
QCOMPARE(hEW, myWidth);
|
|
125 |
|
|
126 |
}
|
|
127 |
|
|
128 |
void TestCalenDayUtils::testHourElementHeight()
|
|
129 |
{
|
|
130 |
|
|
131 |
qreal hEH = mUtils->hourElementHeight();
|
|
132 |
qreal myHeight = mUnit * 3 + param_value * 4;
|
|
133 |
|
|
134 |
QCOMPARE(hEH, myHeight);
|
|
135 |
}
|
|
136 |
|
|
137 |
void TestCalenDayUtils::testContentWidth()
|
|
138 |
{
|
|
139 |
qreal cW = mUtils->contentWidth();
|
|
140 |
qreal myWidth = gTestWindowRect.width() - (mUnit * 8.04 + param_value * 2);
|
|
141 |
|
|
142 |
QCOMPARE(cW, myWidth);
|
|
143 |
}
|
|
144 |
|
45
|
145 |
|
|
146 |
/*!
|
|
147 |
Test function for constructors
|
|
148 |
1. Test if content widget is not initialized
|
|
149 |
2. Test if content widget is correcty created
|
|
150 |
*/
|
|
151 |
void TestCalenDayUtils::testConstructors()
|
55
|
152 |
{
|
|
153 |
//1)
|
|
154 |
CalenDayUtils *testUtils = 0;
|
|
155 |
QVERIFY(!testUtils);
|
|
156 |
|
|
157 |
//2)
|
|
158 |
testUtils = CalenDayUtils::instance();
|
|
159 |
QVERIFY(testUtils);
|
|
160 |
}
|
45
|
161 |
|
|
162 |
|
|
163 |
/*!
|
55
|
164 |
Test function for getting main window's orientation
|
|
165 |
1)test if horizontal orientation is returned
|
|
166 |
2)test if vertical orientation is returned
|
45
|
167 |
*/
|
|
168 |
void TestCalenDayUtils::testOrientation()
|
55
|
169 |
{
|
|
170 |
//1)
|
|
171 |
gTestOrientation = Qt::Horizontal;
|
|
172 |
QCOMPARE(CalenDayUtils::instance()->orientation(), Qt::Horizontal);
|
|
173 |
|
|
174 |
//2)
|
|
175 |
gTestOrientation = Qt::Vertical;
|
|
176 |
QCOMPARE(CalenDayUtils::instance()->orientation(), Qt::Vertical);
|
|
177 |
}
|
|
178 |
|
45
|
179 |
|
|
180 |
QTEST_MAIN(TestCalenDayUtils);
|
|
181 |
#include "unittest_calendayutils.moc"
|