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 |
#include <QPen>
|
|
20 |
|
55
|
21 |
#include <QPainter>
|
|
22 |
#include <QImage>
|
|
23 |
#include <QGraphicsScene>
|
|
24 |
#include <hbstyleloader.h>
|
|
25 |
|
45
|
26 |
#include "calendayeventspane.h"
|
|
27 |
|
55
|
28 |
const qreal WIDGET_WIDTH = 300;
|
|
29 |
const qreal WIDGET_HEIGHT = 1000;
|
|
30 |
|
45
|
31 |
class TestCalenEventsPane : public QObject
|
|
32 |
{
|
|
33 |
Q_OBJECT
|
|
34 |
|
|
35 |
public:
|
|
36 |
TestCalenEventsPane();
|
|
37 |
virtual ~TestCalenEventsPane();
|
|
38 |
|
|
39 |
private slots:
|
|
40 |
void initTestCase();
|
|
41 |
void cleanupTestCase();
|
|
42 |
void init();
|
|
43 |
void cleanup();
|
|
44 |
|
|
45 |
void testConstructors();
|
55
|
46 |
void testSetGetTopLineDrawing();
|
|
47 |
void testContentDrawing();
|
45
|
48 |
|
|
49 |
private:
|
|
50 |
CalenDayEventsPane *mEventsPane;
|
|
51 |
};
|
|
52 |
|
|
53 |
/*!
|
|
54 |
Constructor
|
|
55 |
*/
|
|
56 |
TestCalenEventsPane::TestCalenEventsPane() :
|
|
57 |
mEventsPane(NULL)
|
|
58 |
{
|
|
59 |
|
|
60 |
}
|
|
61 |
|
|
62 |
/*!
|
|
63 |
Destructor
|
|
64 |
*/
|
|
65 |
TestCalenEventsPane::~TestCalenEventsPane()
|
|
66 |
{
|
|
67 |
|
|
68 |
}
|
|
69 |
|
|
70 |
/*!
|
|
71 |
Called before testcase
|
|
72 |
*/
|
|
73 |
void TestCalenEventsPane::initTestCase()
|
|
74 |
{
|
55
|
75 |
HbStyleLoader::registerFilePath(":/calendayhourelement.css");
|
|
76 |
HbStyleLoader::registerFilePath(":/calendayhourelement.widgetml");
|
|
77 |
HbStyleLoader::registerFilePath(":/calendayitem.css");
|
|
78 |
HbStyleLoader::registerFilePath(":/calendayitem.widgetml");
|
|
79 |
HbStyleLoader::registerFilePath(":/calendayeventspane.css");
|
45
|
80 |
}
|
|
81 |
|
|
82 |
/*!
|
|
83 |
Called after testcase
|
|
84 |
*/
|
|
85 |
void TestCalenEventsPane::cleanupTestCase()
|
|
86 |
{
|
|
87 |
|
|
88 |
}
|
|
89 |
|
|
90 |
/*!
|
|
91 |
Called before every function
|
|
92 |
*/
|
|
93 |
void TestCalenEventsPane::init()
|
|
94 |
{
|
|
95 |
mEventsPane = new CalenDayEventsPane();
|
|
96 |
}
|
|
97 |
|
|
98 |
/*!
|
|
99 |
Called after everyfunction
|
|
100 |
*/
|
|
101 |
void TestCalenEventsPane::cleanup()
|
|
102 |
{
|
|
103 |
if (mEventsPane) {
|
|
104 |
delete mEventsPane;
|
|
105 |
mEventsPane = NULL;
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
/*!
|
|
110 |
Test function for constructors
|
|
111 |
1. Test if events pane is not initialized
|
|
112 |
2. Test if events pane is correcty created
|
|
113 |
*/
|
|
114 |
void TestCalenEventsPane::testConstructors()
|
|
115 |
{
|
|
116 |
//1)
|
|
117 |
CalenDayEventsPane *testEventsPane = 0;
|
|
118 |
QVERIFY(!testEventsPane);
|
|
119 |
|
|
120 |
//2)
|
|
121 |
testEventsPane = new CalenDayEventsPane();
|
|
122 |
QVERIFY(testEventsPane);
|
|
123 |
delete testEventsPane;
|
|
124 |
}
|
|
125 |
|
55
|
126 |
/*!
|
|
127 |
Test setting and getting info about top line drawing
|
|
128 |
1. Test first set of value
|
|
129 |
2. Test change value
|
|
130 |
*/
|
|
131 |
void TestCalenEventsPane::testSetGetTopLineDrawing()
|
|
132 |
{
|
|
133 |
//1)
|
|
134 |
mEventsPane->setDrawTopLine(true);
|
|
135 |
QCOMPARE(mEventsPane->isTopLineDrawed(),true);
|
|
136 |
//2)
|
|
137 |
mEventsPane->setDrawTopLine(false);
|
|
138 |
QCOMPARE(mEventsPane->isTopLineDrawed(),false);
|
|
139 |
}
|
|
140 |
|
|
141 |
/*!
|
|
142 |
Test drawing content of widget
|
|
143 |
1. Test without top line draw
|
|
144 |
2. Test with top line draw
|
|
145 |
*/
|
|
146 |
void TestCalenEventsPane::testContentDrawing()
|
|
147 |
{
|
|
148 |
mEventsPane->resize(WIDGET_WIDTH,WIDGET_HEIGHT);
|
|
149 |
QGraphicsScene scene;
|
|
150 |
scene.addItem(mEventsPane);
|
|
151 |
|
|
152 |
//resize widget to be bigger than (0,0)
|
|
153 |
QSize size = mEventsPane->size().toSize();
|
|
154 |
QRect viewRectangle(0,10,size.width(),size.height()-20);
|
|
155 |
//create image that will simulate widget where painting should be done
|
|
156 |
QPixmap img(size);
|
|
157 |
//create painter which will be used to paint
|
|
158 |
QPainter painter;
|
|
159 |
|
|
160 |
//1)
|
|
161 |
mEventsPane->setDrawTopLine(false);
|
|
162 |
painter.begin(&img);
|
|
163 |
painter.setViewport(viewRectangle);
|
|
164 |
painter.setRenderHint(QPainter::Antialiasing);
|
|
165 |
//fill image with white color to have better filings with look of "paper"
|
|
166 |
painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::white));
|
|
167 |
scene.render(&painter);
|
|
168 |
painter.end();
|
|
169 |
#ifdef SAVE_IMAGES
|
|
170 |
//save drawed image
|
|
171 |
img.save("c:/unittest/TestCalenEventsPane_testContentDrawing_false.png");
|
|
172 |
#endif
|
|
173 |
|
|
174 |
//2)
|
|
175 |
mEventsPane->setDrawTopLine(true);
|
|
176 |
painter.begin(&img);
|
|
177 |
painter.setViewport(viewRectangle);
|
|
178 |
painter.setRenderHint(QPainter::Antialiasing);
|
|
179 |
//fill image with white color to have better filings with look of "paper"
|
|
180 |
painter.fillRect(0,0,size.width(),size.height(),QColor(Qt::white));
|
|
181 |
scene.render(&painter);
|
|
182 |
painter.end();
|
|
183 |
#ifdef SAVE_IMAGES
|
|
184 |
//save drawed image
|
|
185 |
img.save("c:/unittest/TestCalenEventsPane_testContentDrawing_true.png");
|
|
186 |
#endif
|
|
187 |
|
|
188 |
scene.removeItem(mEventsPane);
|
|
189 |
}
|
|
190 |
|
45
|
191 |
QTEST_MAIN(TestCalenEventsPane);
|
|
192 |
#include "unittest_calendayeventspane.moc"
|