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