|
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 tests for PhoneUIQtView. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtTest/QtTest> |
|
19 #include <QtGui> |
|
20 #include <QVariant> |
|
21 #include <QKeyEvent> |
|
22 #include <hbapplication.h> |
|
23 #include "phoneuicommandadapter.h" |
|
24 #include "cphoneuicontroller_stub.h" |
|
25 |
|
26 |
|
27 //CONSTANTS |
|
28 |
|
29 |
|
30 #define PHONE_QT_TEST_MAIN(TestObject) \ |
|
31 int main(int argc, char *argv[]) \ |
|
32 { \ |
|
33 HbApplication app(argc, argv); \ |
|
34 TestObject tc; \ |
|
35 QResource::registerResource("../hbcore.rcc"); \ |
|
36 int ret = QTest::qExec(&tc, argc, argv); \ |
|
37 /* Core dump if HbIconLoader instance is not destroyed before the application instance. */ \ |
|
38 /* HbIconLoader uses QCoreApplication::aboutToQuit() signal to destroy itself. */ \ |
|
39 /* app.exec() where the signal is normally emitted is not called here. */ \ |
|
40 /* So, invoking the signal explicitly. */ \ |
|
41 QMetaObject::invokeMethod(&app, "aboutToQuit", Qt::DirectConnection); \ |
|
42 return ret; \ |
|
43 } |
|
44 |
|
45 class TestPhoneCommandAdapter : public QObject |
|
46 { |
|
47 Q_OBJECT |
|
48 |
|
49 public: |
|
50 TestPhoneCommandAdapter (); |
|
51 ~TestPhoneCommandAdapter (); |
|
52 |
|
53 |
|
54 public slots: |
|
55 void initTestCase (); |
|
56 void cleanupTestCase (); |
|
57 void init (); |
|
58 void cleanup (); |
|
59 |
|
60 private slots: |
|
61 void testKeyHandleCommand (); |
|
62 void testLeave (); |
|
63 |
|
64 |
|
65 |
|
66 private: |
|
67 PhoneUiCommandAdapter *m_command_adapter; // class under test |
|
68 CPhoneUIController_Stub *m_uicontrol; |
|
69 |
|
70 }; |
|
71 |
|
72 |
|
73 TestPhoneCommandAdapter::TestPhoneCommandAdapter () |
|
74 { |
|
75 } |
|
76 |
|
77 TestPhoneCommandAdapter::~TestPhoneCommandAdapter () |
|
78 { |
|
79 } |
|
80 |
|
81 void TestPhoneCommandAdapter::initTestCase () |
|
82 { |
|
83 } |
|
84 |
|
85 void TestPhoneCommandAdapter::cleanupTestCase () |
|
86 { |
|
87 } |
|
88 |
|
89 void TestPhoneCommandAdapter::init () |
|
90 { |
|
91 m_uicontrol = new CPhoneUIController_Stub(); |
|
92 m_command_adapter = new PhoneUiCommandAdapter(*m_uicontrol); |
|
93 } |
|
94 |
|
95 void TestPhoneCommandAdapter::cleanup () |
|
96 { |
|
97 delete m_uicontrol; |
|
98 delete m_command_adapter; |
|
99 } |
|
100 |
|
101 void TestPhoneCommandAdapter::testKeyHandleCommand () |
|
102 { |
|
103 int command = 1001; |
|
104 |
|
105 m_command_adapter->handleCommand(command); |
|
106 |
|
107 QVERIFY( command == m_command ); |
|
108 |
|
109 } |
|
110 |
|
111 void TestPhoneCommandAdapter::testLeave () |
|
112 { |
|
113 m_leave = true; |
|
114 int command = 1001; |
|
115 |
|
116 m_command_adapter->handleCommand(command); |
|
117 |
|
118 QVERIFY( 0 == m_command ); |
|
119 m_leave = false; |
|
120 |
|
121 } |
|
122 |
|
123 PHONE_QT_TEST_MAIN(TestPhoneCommandAdapter) |
|
124 #include "unit_tests.moc" |