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 |
*
|
55
|
14 |
* Description: Test class for TestCalenDayHourElement
|
45
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include <QGraphicsItem>
|
|
18 |
#include <QtTest/QtTest>
|
|
19 |
|
81
|
20 |
#ifndef __WINSCW__
|
|
21 |
#define private public
|
|
22 |
#define protected public
|
|
23 |
#endif
|
|
24 |
|
55
|
25 |
#include "calendayhourelementtest.h"
|
|
26 |
#include "calendayhourscrollarea.h"
|
|
27 |
|
|
28 |
#include <QPainter>
|
|
29 |
#include <QImage>
|
|
30 |
#include <QPair>
|
|
31 |
#include <QDateTime>
|
|
32 |
|
|
33 |
const qreal WIDGET_WIDTH = 50;
|
|
34 |
const qreal WIDGET_HEIGHT = 150;
|
45
|
35 |
|
|
36 |
class TestCalenDayHourElement : public QObject
|
|
37 |
{
|
|
38 |
Q_OBJECT
|
|
39 |
|
|
40 |
public:
|
|
41 |
TestCalenDayHourElement();
|
|
42 |
virtual ~TestCalenDayHourElement();
|
|
43 |
|
|
44 |
private slots:
|
|
45 |
void initTestCase();
|
|
46 |
void cleanupTestCase();
|
|
47 |
void init();
|
|
48 |
void cleanup();
|
|
49 |
|
|
50 |
void testConstructors();
|
55
|
51 |
void testSetGetTime();
|
|
52 |
void testPaint_data();
|
|
53 |
void testPaint();
|
81
|
54 |
void testLocaleChanged();
|
45
|
55 |
|
|
56 |
private:
|
55
|
57 |
CalenDayHourElementTest *mHourElement;
|
|
58 |
CalenDayHourScrollArea *mContainer;
|
45
|
59 |
QTime mTime;
|
|
60 |
};
|
|
61 |
|
|
62 |
/*!
|
|
63 |
Constructor
|
|
64 |
*/
|
|
65 |
TestCalenDayHourElement::TestCalenDayHourElement() :
|
|
66 |
mHourElement(NULL)
|
|
67 |
{
|
|
68 |
|
|
69 |
}
|
|
70 |
|
|
71 |
/*!
|
|
72 |
Destructor
|
|
73 |
*/
|
|
74 |
TestCalenDayHourElement::~TestCalenDayHourElement()
|
|
75 |
{
|
|
76 |
|
|
77 |
}
|
|
78 |
|
|
79 |
/*!
|
|
80 |
Called before testcase
|
|
81 |
*/
|
|
82 |
void TestCalenDayHourElement::initTestCase()
|
|
83 |
{
|
|
84 |
}
|
|
85 |
|
|
86 |
/*!
|
|
87 |
Called after testcase
|
|
88 |
*/
|
|
89 |
void TestCalenDayHourElement::cleanupTestCase()
|
|
90 |
{
|
|
91 |
|
|
92 |
}
|
|
93 |
|
|
94 |
/*!
|
|
95 |
Called before every function
|
|
96 |
*/
|
|
97 |
void TestCalenDayHourElement::init()
|
|
98 |
{
|
55
|
99 |
mTime = QTime(12,0,0);
|
|
100 |
mContainer = new CalenDayHourScrollArea();
|
|
101 |
mHourElement = new CalenDayHourElementTest(mTime,mContainer);
|
45
|
102 |
}
|
|
103 |
|
|
104 |
/*!
|
|
105 |
Called after everyfunction
|
|
106 |
*/
|
|
107 |
void TestCalenDayHourElement::cleanup()
|
|
108 |
{
|
|
109 |
if (mHourElement) {
|
|
110 |
delete mHourElement;
|
|
111 |
mHourElement = NULL;
|
|
112 |
}
|
|
113 |
}
|
|
114 |
|
|
115 |
/*!
|
|
116 |
Test function for constructors
|
|
117 |
1. Test if content widget is not initialized
|
|
118 |
2. Test if content widget is correcty created
|
|
119 |
*/
|
|
120 |
void TestCalenDayHourElement::testConstructors()
|
|
121 |
{
|
|
122 |
//1)
|
55
|
123 |
CalenDayHourElementTest *testHourElement = 0;
|
45
|
124 |
QVERIFY(!testHourElement);
|
|
125 |
|
55
|
126 |
testHourElement = new CalenDayHourElementTest(mTime,mContainer);
|
45
|
127 |
|
|
128 |
QVERIFY(testHourElement);
|
|
129 |
|
|
130 |
delete testHourElement;
|
|
131 |
}
|
|
132 |
|
55
|
133 |
/*!
|
|
134 |
\brief It test is setting and getting of time works good.
|
|
135 |
|
|
136 |
0)Test if time from constructor works good
|
|
137 |
1)Test set new time
|
|
138 |
2)Change time and test new
|
|
139 |
*/
|
|
140 |
void TestCalenDayHourElement::testSetGetTime()
|
|
141 |
{
|
|
142 |
//0)
|
|
143 |
QVERIFY(mTime == mHourElement->time());
|
|
144 |
|
|
145 |
QTime testValue(15,15,15);
|
|
146 |
//1)
|
|
147 |
mHourElement->setTime(testValue);
|
|
148 |
|
|
149 |
QVERIFY(testValue == mHourElement->time());
|
|
150 |
|
|
151 |
//2)
|
|
152 |
testValue = QTime(10,10,10);
|
|
153 |
|
|
154 |
mHourElement->setTime(testValue);
|
|
155 |
QVERIFY(testValue == mHourElement->time());
|
|
156 |
}
|
|
157 |
|
|
158 |
/*!
|
|
159 |
\brief Test data for \sa testPaint
|
|
160 |
|
|
161 |
Tested data:
|
|
162 |
1)Hour is eual 0
|
|
163 |
2)Hour is bigger than 0
|
|
164 |
3)Test current time
|
|
165 |
*/
|
|
166 |
void TestCalenDayHourElement::testPaint_data()
|
|
167 |
{
|
|
168 |
QTest::addColumn<QDateTime>("testedValue");
|
|
169 |
QTest::addColumn<QString>("testName");
|
|
170 |
|
|
171 |
QTest::newRow("hour = 0") << QDateTime(QDate(2010,06,26),QTime(0,10,0))
|
|
172 |
<< QString("hour = 0");
|
|
173 |
QTest::newRow("hour != 0") << QDateTime(QDate(2010,06,26),QTime(15,15,15))
|
|
174 |
<< QString("hour != 0");
|
|
175 |
QTest::newRow("current time") << QDateTime::currentDateTime()
|
|
176 |
<< QString("current time");
|
|
177 |
}
|
|
178 |
|
|
179 |
/*!
|
|
180 |
\brief Test painting method
|
|
181 |
|
|
182 |
It check painting based on given time.
|
|
183 |
\sa testPaint_data
|
|
184 |
*/
|
|
185 |
void TestCalenDayHourElement::testPaint()
|
|
186 |
{
|
81
|
187 |
//1)
|
55
|
188 |
//get data to test
|
|
189 |
QFETCH(QDateTime, testedValue);
|
|
190 |
QFETCH(QString, testName);
|
|
191 |
|
|
192 |
mHourElement->setTime(testedValue.time());
|
|
193 |
|
|
194 |
//set date to check
|
|
195 |
mContainer->setDateTime(testedValue);
|
|
196 |
|
|
197 |
QStyleOptionGraphicsItem * option = new QStyleOptionGraphicsItem();
|
|
198 |
//preapre drawed area smaller because of drawing lines on corners
|
|
199 |
option->rect = QRect(10,10,WIDGET_WIDTH-20,WIDGET_HEIGHT/2);
|
|
200 |
mHourElement->resize(WIDGET_WIDTH,WIDGET_HEIGHT);
|
|
201 |
QSize size = mHourElement->size().toSize();
|
|
202 |
|
|
203 |
//create image that will simulate widget where painting should be done
|
|
204 |
QImage img(size,QImage::Format_RGB32);
|
|
205 |
//create painter which will be used to paint
|
|
206 |
QPainter painter(&img);
|
|
207 |
//fill image with grey color to have better filings with look of "paper"
|
|
208 |
painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
|
|
209 |
//run paint
|
|
210 |
mHourElement->paint(&painter,option,0);
|
|
211 |
|
|
212 |
#ifdef SAVE_IMAGES
|
|
213 |
//save drawed image
|
81
|
214 |
img.save("c:/unittest/TestCalenDayHourElement_testPaint_" + testName + ".jpg");
|
|
215 |
#endif
|
|
216 |
|
|
217 |
//2)
|
|
218 |
QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
219 |
int currentHour = currentDateTime.time().hour();
|
|
220 |
mHourElement->setTime(QTime(currentHour + 1, 0 ));
|
|
221 |
//fill image with grey color to have better filings with look of "paper"
|
|
222 |
painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
|
|
223 |
//run paint
|
|
224 |
mHourElement->paint(&painter,option,0);
|
|
225 |
|
|
226 |
#ifdef SAVE_IMAGES
|
|
227 |
//save drawed image
|
|
228 |
img.save("c:/unittest/TestCalenDayHourElement_testPaint_" + testName + "2.jpg");
|
|
229 |
#endif
|
|
230 |
|
|
231 |
//3)
|
|
232 |
#ifndef __WINSCW__
|
|
233 |
mHourElement->mContainer = NULL;
|
|
234 |
//fill image with grey color to have better filings with look of "paper"
|
|
235 |
painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::gray));
|
|
236 |
//run paint
|
|
237 |
mHourElement->paint(&painter,option,0);
|
|
238 |
|
|
239 |
#ifdef SAVE_IMAGES
|
|
240 |
//save drawed image
|
|
241 |
img.save("c:/unittest/TestCalenDayHourElement_testPaint_" + testName + "3.jpg");
|
|
242 |
#endif
|
|
243 |
|
|
244 |
#endif
|
|
245 |
}
|
|
246 |
|
|
247 |
/*!
|
|
248 |
Test function for localChanged method
|
|
249 |
*/
|
|
250 |
void TestCalenDayHourElement::testLocaleChanged()
|
|
251 |
{
|
|
252 |
#ifndef __WINSCW__
|
|
253 |
mHourElement->mTimeTextItem->setText(QString(""));
|
|
254 |
mHourElement->localeChanged();
|
|
255 |
QVERIFY(mHourElement->mTimeTextItem->text() != QString(""));
|
55
|
256 |
#endif
|
|
257 |
}
|
|
258 |
|
45
|
259 |
QTEST_MAIN(TestCalenDayHourElement);
|
|
260 |
#include "unittest_calendayhourelement.moc"
|