|
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: |
|
15 * test application for qt control panel public apis. |
|
16 */ |
|
17 #include "ut_cpviewlauncher.h" |
|
18 |
|
19 #include "cpviewlauncher.h" |
|
20 #include "cpbasesettingview.h" |
|
21 |
|
22 #include <QtTest/QtTest> |
|
23 #include <hbdataform.h> |
|
24 #include <hbpushbutton.h> |
|
25 #include <HbMainWindow> |
|
26 #include <QSignalSpy> |
|
27 #include <QList> |
|
28 |
|
29 /*! |
|
30 \class TestCpViewLauncher |
|
31 \brief This class is used for the unit test for class CpViewLauncher.\n |
|
32 CpViewLauncher class is used for add a HbView into current HbMainWindow, \n |
|
33 and set the new added HbView instance as current view object, then completed \n |
|
34 related signal/slot setting.\n |
|
35 This unit test is supported by QTest.\n |
|
36 There are total 3 test cases in this unit.\n |
|
37 */ |
|
38 |
|
39 /*! |
|
40 * init function called by QTest framework. |
|
41 */ |
|
42 void TestCpViewLauncher::initTestCase() |
|
43 { |
|
44 } |
|
45 |
|
46 /*! |
|
47 * cleanup function used by QTest framework. |
|
48 */ |
|
49 void TestCpViewLauncher::cleanupTestCase() |
|
50 { |
|
51 QCoreApplication::processEvents(); |
|
52 } |
|
53 |
|
54 /*! |
|
55 * Test Case Description:\n |
|
56 * 1. Fucntion Name: \n |
|
57 static void launchView(HbView *view);\n |
|
58 |
|
59 2. Function Descrition: \n |
|
60 Launch an exist CpBaseSettingView object, add the CpBaseSettingView object into HbMainWindow.\n |
|
61 3. Input Parameters: \n |
|
62 @param: HbView *view\n |
|
63 |
|
64 4. Expected result: \n |
|
65 View can't be launched for there is no HbMainWindow created.\n |
|
66 */ |
|
67 void TestCpViewLauncher::testLaunchViewNoMainWindow() |
|
68 { |
|
69 CpBaseSettingView * pView1 = new CpBaseSettingView(0); |
|
70 QVERIFY( pView1 != 0 ); |
|
71 HbDataForm *pForm = new HbDataForm(0); |
|
72 QVERIFY( pForm != 0 ); |
|
73 |
|
74 pView1->setWidget(pForm); |
|
75 HbDataForm *pForm1 = qobject_cast<HbDataForm *>(pView1->widget()); |
|
76 QVERIFY( pForm1 != 0); |
|
77 QVERIFY( pForm1 == pForm ); |
|
78 |
|
79 CpBaseSettingView * pView2 = new CpBaseSettingView(pForm); |
|
80 QVERIFY( pView2 != 0 ); |
|
81 |
|
82 QObject::connect(this, SIGNAL(callAboutToClose()), pView1, SIGNAL(aboutToClose())); |
|
83 QObject::connect(this, SIGNAL(callAboutToClose()), pView2, SIGNAL(aboutToClose())); |
|
84 |
|
85 CpViewLauncher::launchView(pView1); |
|
86 CpViewLauncher::launchView(pView2); |
|
87 |
|
88 emit callAboutToClose(); |
|
89 emit callAboutToClose(); |
|
90 |
|
91 delete pView1; |
|
92 delete pView2; |
|
93 } |
|
94 |
|
95 /*! |
|
96 * Test Case Description:\n |
|
97 * 1. Fucntion Name: \n |
|
98 static void launchView(HbView *view);\n |
|
99 |
|
100 2. Function Descrition: \n |
|
101 Launch an exist CpBaseSettingView object, add the CpBaseSettingView object into HbMainWindow.\n |
|
102 3. Pre-condition: \n |
|
103 HbMainWindow object created correctly. |
|
104 |
|
105 4. Input: a pointer to CpBaseSettingView object\n |
|
106 @param: HbView *view\n |
|
107 |
|
108 5. Expected result: \n |
|
109 View launched successfully.\n |
|
110 */ |
|
111 void TestCpViewLauncher::testLaunchViewWithMainWindow() |
|
112 { |
|
113 mainWindow = new HbMainWindow; |
|
114 QVERIFY( mainWindow != 0 ); |
|
115 |
|
116 mainWindow->show(); |
|
117 |
|
118 CpBaseSettingView * pView1 = new CpBaseSettingView(0); |
|
119 QVERIFY( pView1 != 0 ); |
|
120 HbDataForm *pForm = new HbDataForm(0); |
|
121 QVERIFY( pForm != 0 ); |
|
122 |
|
123 pView1->setWidget(pForm); |
|
124 HbDataForm *pForm1 = qobject_cast<HbDataForm *>(pView1->widget()); |
|
125 QVERIFY( pForm1 != 0); |
|
126 QVERIFY( pForm1 == pForm ); |
|
127 |
|
128 CpBaseSettingView * pView2 = new CpBaseSettingView(pForm); |
|
129 QVERIFY( pView2 != 0 ); |
|
130 |
|
131 QObject::connect(this, SIGNAL(callAboutToClose()), pView1, SIGNAL(aboutToClose())); |
|
132 QObject::connect(this, SIGNAL(callAboutToClose()), pView2, SIGNAL(aboutToClose())); |
|
133 |
|
134 QObject::connect(this, SIGNAL(callAboutToClose()), qApp, SLOT(quit())); |
|
135 |
|
136 CpViewLauncher::launchView(pView1); |
|
137 CpViewLauncher::launchView(pView2); |
|
138 |
|
139 emit callAboutToClose(); |
|
140 emit callAboutToClose(); |
|
141 |
|
142 delete mainWindow; |
|
143 mainWindow = 0; |
|
144 } |
|
145 |
|
146 /*! |
|
147 * Test Case Description:\n |
|
148 * 1. Fucntion Name: \n |
|
149 static void launchView(HbView *view);\n |
|
150 |
|
151 2. Function Descrition: \n |
|
152 Launch an exist CpBaseSettingView object, add the CpBaseSettingView object into HbMainWindow.\n |
|
153 3. Input Parameters: \n |
|
154 @param: 0\n |
|
155 4. Expected result: \n |
|
156 launchView do nothing for the 0 parameter.\n |
|
157 */ |
|
158 void TestCpViewLauncher::testLaunchViewNoView() |
|
159 { |
|
160 HbPushButton *widget = new HbPushButton(); |
|
161 QVERIFY(widget != 0); |
|
162 CpBaseSettingView *pView1 = new CpBaseSettingView(widget); |
|
163 QVERIFY(pView1!=0); |
|
164 HbPushButton *button = qobject_cast<HbPushButton *>(pView1->widget()); |
|
165 QVERIFY(button != 0); |
|
166 QVERIFY(button == widget); |
|
167 |
|
168 CpViewLauncher::launchView(0); |
|
169 |
|
170 delete pView1; |
|
171 } |
|
172 |
|
173 QTEST_MAIN(TestCpViewLauncher) |