19 |
19 |
20 #include "hbstyle.h" |
20 #include "hbstyle.h" |
21 #include "calendayutils.h" |
21 #include "calendayutils.h" |
22 #include "hbdeviceprofile.h" |
22 #include "hbdeviceprofile.h" |
23 #include "calendaycommonheaders.h" |
23 #include "calendaycommonheaders.h" |
|
24 #include "agendaentry.h" |
24 |
25 |
25 // Test variables |
26 // Test variables |
26 QRectF gTestWindowRect = QRectF(0, 0, 10, 20); |
27 QRectF gTestWindowRect = QRectF(0, 0, 10, 20); |
27 Qt::Orientation gTestOrientation = Qt::Horizontal; |
28 Qt::Orientation gTestOrientation = Qt::Horizontal; |
28 qreal param_value = 10; |
29 qreal param_value = 10; |
29 qreal unitInPix = 1; |
30 qreal unitInPix = 1; |
30 |
31 |
31 class TestCalenDayUtils : public QObject |
32 class TestCalenDayUtils : public QObject |
32 { |
33 { |
33 Q_OBJECT |
34 Q_OBJECT |
34 |
35 |
35 public: |
36 public: |
36 TestCalenDayUtils(); |
37 TestCalenDayUtils(); |
37 virtual ~TestCalenDayUtils(); |
38 virtual ~TestCalenDayUtils(); |
38 |
39 |
39 private slots: |
40 private slots: |
40 void initTestCase(); |
41 void initTestCase(); |
41 void cleanupTestCase(); |
42 void cleanupTestCase(); |
42 void init(); |
43 void init(); |
43 void cleanup(); |
44 void cleanup(); |
44 |
45 |
45 void testInstance(); |
46 void testInstance(); |
46 void testScreenWidth(); |
47 void testScreenWidth(); |
47 void testHourElementWidth(); |
48 void testHourElementWidth(); |
48 void testHourElementHeight(); |
49 void testHourElementHeight(); |
49 void testContentWidth(); |
50 void testContentWidth(); |
50 |
51 void testMinEventHeight(); |
51 void testConstructors(); |
52 void testMainWindow(); |
52 void testOrientation(); |
53 void testGetEventValidStartEndTime(); |
|
54 |
|
55 void testConstructors(); |
|
56 void testOrientation(); |
53 |
57 |
54 private: |
58 private: |
55 CalenDayUtils *mUtils; |
59 CalenDayUtils *mUtils; |
56 qreal mUnit; |
60 qreal mUnit; |
57 }; |
61 }; |
58 |
62 |
59 /*! |
63 /*! |
60 Constructor |
64 Constructor |
61 */ |
65 */ |
62 TestCalenDayUtils::TestCalenDayUtils() : |
66 TestCalenDayUtils::TestCalenDayUtils() : |
63 mUtils(NULL) |
67 mUtils(NULL) |
64 { |
68 { |
65 HbDeviceProfile s; |
69 HbDeviceProfile s; |
66 mUnit = s.unitValue(); |
70 mUnit = s.unitValue(); |
67 } |
71 } |
68 |
72 |
69 /*! |
73 /*! |
70 Destructor |
74 Destructor |
71 */ |
75 */ |
72 TestCalenDayUtils::~TestCalenDayUtils() |
76 TestCalenDayUtils::~TestCalenDayUtils() |
73 { |
77 { |
74 |
78 |
75 } |
79 } |
76 |
80 |
77 /*! |
81 /*! |
78 Called before testcase |
82 Called before testcase |
79 */ |
83 */ |
80 void TestCalenDayUtils::initTestCase() |
84 void TestCalenDayUtils::initTestCase() |
81 { |
85 { |
82 } |
86 } |
83 |
87 |
84 /*! |
88 /*! |
85 Called after testcase |
89 Called after testcase |
86 */ |
90 */ |
87 void TestCalenDayUtils::cleanupTestCase() |
91 void TestCalenDayUtils::cleanupTestCase() |
88 { |
92 { |
89 } |
93 } |
90 |
94 |
91 /*! |
95 /*! |
92 Called before every function |
96 Called before every function |
93 */ |
97 */ |
94 void TestCalenDayUtils::init() |
98 void TestCalenDayUtils::init() |
95 { |
99 { |
96 mUtils = CalenDayUtils::instance(); |
100 mUtils = CalenDayUtils::instance(); |
97 } |
101 } |
98 |
102 |
99 /*! |
103 /*! |
100 Called after everyfunction |
104 Called after everyfunction |
101 */ |
105 */ |
102 void TestCalenDayUtils::cleanup() |
106 void TestCalenDayUtils::cleanup() |
103 { |
107 { |
104 //delete mUtils; |
108 //delete mUtils; |
105 } |
109 } |
106 |
110 |
107 void TestCalenDayUtils::testInstance() |
111 void TestCalenDayUtils::testInstance() |
108 { |
112 { |
109 CalenDayUtils* utils = CalenDayUtils::instance(); |
113 CalenDayUtils* utils = CalenDayUtils::instance(); |
110 QVERIFY(utils); |
114 QVERIFY(utils); |
111 } |
115 } |
112 |
116 |
113 void TestCalenDayUtils::testScreenWidth() |
117 void TestCalenDayUtils::testScreenWidth() |
114 { |
118 { |
115 qreal sw = mUtils->screenWidth(); |
119 qreal sw = mUtils->screenWidth(); |
116 QVERIFY(sw == gTestWindowRect.width()); |
120 QVERIFY(sw == gTestWindowRect.width()); |
117 } |
121 } |
118 |
122 |
119 void TestCalenDayUtils::testHourElementWidth() |
123 void TestCalenDayUtils::testHourElementWidth() |
120 { |
124 { |
121 qreal hEW = mUtils->hourElementWidth(); |
125 qreal hEW = mUtils->hourElementWidth(); |
122 qreal myWidth = mUnit * 8.04 + param_value * 2; |
126 qreal myWidth = mUnit * 8.04 + param_value * 2; |
123 |
127 |
124 QCOMPARE(hEW, myWidth); |
128 QCOMPARE(hEW, myWidth); |
125 |
129 |
126 } |
130 } |
127 |
131 |
128 void TestCalenDayUtils::testHourElementHeight() |
132 void TestCalenDayUtils::testHourElementHeight() |
129 { |
133 { |
130 |
134 |
131 qreal hEH = mUtils->hourElementHeight(); |
135 qreal hEH = mUtils->hourElementHeight(); |
132 qreal myHeight = mUnit* 4.1 + param_value * 2 + param_value * 2; |
136 qreal myHeight = mUnit * 4.1 + param_value * 2 + param_value * 2; |
133 |
137 |
134 QCOMPARE(hEH, myHeight); |
138 QCOMPARE(hEH, myHeight); |
135 } |
139 } |
136 |
140 |
137 void TestCalenDayUtils::testContentWidth() |
141 void TestCalenDayUtils::testContentWidth() |
138 { |
142 { |
139 qreal cW = mUtils->contentWidth(); |
143 qreal cW = mUtils->contentWidth(); |
140 qreal myWidth = gTestWindowRect.width() - (mUnit * 8.04 + param_value * 2); |
144 qreal myWidth = gTestWindowRect.width() - (mUnit * 8.04 + param_value * 2); |
141 |
145 |
142 QCOMPARE(cW, myWidth); |
146 QCOMPARE(cW, myWidth); |
143 } |
147 } |
144 |
148 |
|
149 /*! |
|
150 Test function for minimum event's height |
|
151 */ |
|
152 void TestCalenDayUtils::testMinEventHeight() |
|
153 { |
|
154 qreal minH = mUtils->minEventHeight(); |
|
155 qreal myH = param_value + param_value + param_value; |
|
156 |
|
157 QCOMPARE(minH, myH); |
|
158 } |
|
159 |
|
160 /*! |
|
161 Test function for main window getter |
|
162 */ |
|
163 void TestCalenDayUtils::testMainWindow() |
|
164 { |
|
165 HbMainWindow *window = NULL; |
|
166 QVERIFY(!window); |
|
167 |
|
168 window = mUtils->mainWindow(); |
|
169 QVERIFY(window); |
|
170 } |
|
171 |
|
172 /*! |
|
173 Test function for getEventValidStartEndTime function |
|
174 1) start and end time are in current day: event start - end |
|
175 2) start time is yesterday, end time is in current day: event 0.00 - end |
|
176 3) start time is yesterday, end time is tomorrow: event 0.00 - 23.59 |
|
177 */ |
|
178 void TestCalenDayUtils::testGetEventValidStartEndTime() |
|
179 { |
|
180 QDateTime currentDate(QDate(2010, 9, 5), QTime(8, 15)); |
|
181 |
|
182 //1) |
|
183 QDateTime inStart = currentDate.addSecs(-3600); // currentTime - 1 hour |
|
184 QDateTime inEnd = currentDate.addSecs(3600); // currentTime + 1 hour |
|
185 |
|
186 AgendaEntry entry; |
|
187 entry.setStartAndEndTime(inStart, inEnd); |
|
188 |
|
189 QDateTime outStart; |
|
190 QDateTime outEnd; |
|
191 mUtils->getEventValidStartEndTime(outStart, outEnd, entry, currentDate); |
|
192 QCOMPARE(outStart, inStart); |
|
193 QCOMPARE(outEnd, inEnd); |
|
194 |
|
195 //2) |
|
196 inStart = currentDate.addDays(-1); // currentTime - 1 day |
|
197 inEnd = currentDate.addSecs(3600); // currentTime + 1 hour |
|
198 |
|
199 entry.setStartAndEndTime(inStart, inEnd); |
|
200 |
|
201 mUtils->getEventValidStartEndTime(outStart, outEnd, entry, currentDate); |
|
202 QCOMPARE(outStart, QDateTime(currentDate.date(), QTime(0, 0, 0, 0))); |
|
203 QCOMPARE(outEnd, inEnd); |
|
204 |
|
205 //3) |
|
206 inStart = currentDate.addDays(-1); // currentTime - 1 day |
|
207 inEnd = currentDate.addDays(1); // currentTime + 1 day |
|
208 |
|
209 entry.setStartAndEndTime(inStart, inEnd); |
|
210 |
|
211 mUtils->getEventValidStartEndTime(outStart, outEnd, entry, currentDate); |
|
212 QCOMPARE(outStart, QDateTime(currentDate.date(), QTime(0, 0, 0, 0))); |
|
213 QCOMPARE(outEnd, QDateTime(currentDate.date(), QTime(23, 59, 0, 0))); |
|
214 } |
145 |
215 |
146 /*! |
216 /*! |
147 Test function for constructors |
217 Test function for constructors |
148 1. Test if content widget is not initialized |
218 1. Test if content widget is not initialized |
149 2. Test if content widget is correcty created |
219 2. Test if content widget is correcty created |
150 */ |
220 */ |
151 void TestCalenDayUtils::testConstructors() |
221 void TestCalenDayUtils::testConstructors() |
152 { |
222 { |
153 //1) |
223 //1) |
154 CalenDayUtils *testUtils = 0; |
224 CalenDayUtils *testUtils = 0; |
155 QVERIFY(!testUtils); |
225 QVERIFY(!testUtils); |
156 |
226 |
157 //2) |
227 //2) |
158 testUtils = CalenDayUtils::instance(); |
228 testUtils = CalenDayUtils::instance(); |
159 QVERIFY(testUtils); |
229 QVERIFY(testUtils); |
160 } |
230 } |
161 |
|
162 |
231 |
163 /*! |
232 /*! |
164 Test function for getting main window's orientation |
233 Test function for getting main window's orientation |
165 1)test if horizontal orientation is returned |
234 1)test if horizontal orientation is returned |
166 2)test if vertical orientation is returned |
235 2)test if vertical orientation is returned |
167 */ |
236 */ |
168 void TestCalenDayUtils::testOrientation() |
237 void TestCalenDayUtils::testOrientation() |
169 { |
238 { |
170 //1) |
239 //1) |
171 gTestOrientation = Qt::Horizontal; |
240 gTestOrientation = Qt::Horizontal; |
172 QCOMPARE(CalenDayUtils::instance()->orientation(), Qt::Horizontal); |
241 QCOMPARE(CalenDayUtils::instance()->orientation(), Qt::Horizontal); |
173 |
242 |
174 //2) |
243 //2) |
175 gTestOrientation = Qt::Vertical; |
244 gTestOrientation = Qt::Vertical; |
176 QCOMPARE(CalenDayUtils::instance()->orientation(), Qt::Vertical); |
245 QCOMPARE(CalenDayUtils::instance()->orientation(), Qt::Vertical); |
177 } |
246 } |
178 |
|
179 |
247 |
180 QTEST_MAIN(TestCalenDayUtils); |
248 QTEST_MAIN(TestCalenDayUtils); |
181 #include "unittest_calendayutils.moc" |
249 #include "unittest_calendayutils.moc" |