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