|
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: Unit test for MpMtpInfoLink |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QGraphicsSceneMouseEvent> |
|
19 |
|
20 #include "stub/inc/hblabel.h" |
|
21 #include "stub/inc/qdesktopservices.h" |
|
22 #include "stub/inc/mpsettingsmanager.h" |
|
23 #include "unittest_mpmtpinfolink.h" |
|
24 |
|
25 |
|
26 // Do this so we can access all member variables. |
|
27 #define private public |
|
28 #define protected public |
|
29 #include "mpmtpinfolink.h" |
|
30 #undef protected |
|
31 #undef private |
|
32 |
|
33 //This so we can test private functions |
|
34 #include "../../src/mpmtpinfolink.cpp" |
|
35 |
|
36 |
|
37 /*! |
|
38 Make our test case a stand-alone executable that runs all the test functions. |
|
39 */ |
|
40 int main(int argc, char *argv[]) |
|
41 { |
|
42 TestMpMtpInfoLink tv; |
|
43 |
|
44 if ( argc > 1 ) { |
|
45 return QTest::qExec( &tv, argc, argv); |
|
46 } |
|
47 else { |
|
48 char *pass[3]; |
|
49 pass[0] = argv[0]; |
|
50 pass[1] = "-o"; |
|
51 pass[2] = "c:\\data\\unittest_mpmtpinfolink.txt"; |
|
52 |
|
53 return QTest::qExec(&tv, 3, pass); |
|
54 } |
|
55 } |
|
56 |
|
57 TestMpMtpInfoLink::TestMpMtpInfoLink() |
|
58 : mTest( 0 ) |
|
59 { |
|
60 } |
|
61 |
|
62 TestMpMtpInfoLink::~TestMpMtpInfoLink() |
|
63 { |
|
64 delete mTest; |
|
65 } |
|
66 |
|
67 /*! |
|
68 Called before the first testfunction is executed. |
|
69 */ |
|
70 void TestMpMtpInfoLink::initTestCase() |
|
71 { |
|
72 } |
|
73 |
|
74 /*! |
|
75 Called after the last testfunction was executed. |
|
76 */ |
|
77 void TestMpMtpInfoLink::cleanupTestCase() |
|
78 { |
|
79 } |
|
80 |
|
81 /*! |
|
82 Called before each testfunction is executed. |
|
83 */ |
|
84 void TestMpMtpInfoLink::init() |
|
85 { |
|
86 mTest = new MpMtpInfoLink(); |
|
87 } |
|
88 |
|
89 /*! |
|
90 Called after every testfunction. |
|
91 */ |
|
92 void TestMpMtpInfoLink::cleanup() |
|
93 { |
|
94 delete mTest; |
|
95 mTest = 0; |
|
96 } |
|
97 |
|
98 /*! |
|
99 Tests constructor. |
|
100 */ |
|
101 void TestMpMtpInfoLink::testConstructor() |
|
102 { |
|
103 QVERIFY(mTest->textWrapping() == Hb::TextWrapAnywhere ); |
|
104 } |
|
105 |
|
106 /*! |
|
107 testMousePressEvent. |
|
108 */ |
|
109 void TestMpMtpInfoLink::testMousePressEvent() |
|
110 { |
|
111 //MpMtpInfoLink::mousePressEvent does nothing, included just to cover all functions. |
|
112 QGraphicsSceneMouseEvent *event = new QGraphicsSceneMouseEvent(); |
|
113 mTest->mousePressEvent( event ); |
|
114 QVERIFY( mTest ); |
|
115 } |
|
116 |
|
117 /*! |
|
118 Tests HandleOpen. |
|
119 */ |
|
120 void TestMpMtpInfoLink::testMouseReleaseEvent() |
|
121 { |
|
122 QGraphicsSceneMouseEvent *event = new QGraphicsSceneMouseEvent(); |
|
123 |
|
124 //Mock label rect: x=10, y=10, width=10, height=10); |
|
125 QPointF releasePointOut(5,5); |
|
126 QPointF releasePointIn(15,15); |
|
127 |
|
128 //Verify releasing the mouse outside the label |
|
129 event->setLastPos( releasePointOut ); |
|
130 mTest->mouseReleaseEvent( event ); |
|
131 QCOMPARE( QDesktopServices::instance()->mOpenUrlCount, 0); |
|
132 //Verify releasing the mouse inside the label |
|
133 event->setLastPos( releasePointIn ); |
|
134 mTest->mouseReleaseEvent( event ); |
|
135 QCOMPARE( QDesktopServices::instance()->mOpenUrlCount, 1); |
|
136 } |
|
137 |
|
138 /*! |
|
139 testSetMtpInfoText |
|
140 */ |
|
141 void TestMpMtpInfoLink::testSetMtpInfoText( ) |
|
142 { |
|
143 //Verify with an url |
|
144 QVERIFY( mTest->plainText().length() == 0 ); |
|
145 QVERIFY( mTest->html().length() > 0 ); |
|
146 |
|
147 } |
|
148 |
|
149 //end of file |