|
1 /* |
|
2 * Copyright (c) 2010 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: Main test class for hsHomeScreenStatePlugin library. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "t_searchviewbuilder.h" |
|
19 #include <QInputContext> |
|
20 #include <QSortFilterProxyModel> |
|
21 #include <HbAbstractViewItem> |
|
22 #include "hssearchviewbuilder.h" |
|
23 #include "hsmenuviewbuilder.h" |
|
24 #include "hsmainwindow.h" |
|
25 #include "hssearchview.h" |
|
26 #include "caitemmodel.h" |
|
27 |
|
28 class HsMainWindowMock : public HsMainWindow |
|
29 { |
|
30 virtual void setCurrentView(HbView *view) { Q_UNUSED(view); } |
|
31 }; |
|
32 |
|
33 class MockViewItem : public HbAbstractViewItem |
|
34 { |
|
35 virtual HbAbstractViewItem *createItem() |
|
36 { |
|
37 HbAbstractViewItem *item = new MockViewItem; |
|
38 return item; |
|
39 } |
|
40 }; |
|
41 |
|
42 void MenuStatesTest::testSlot() |
|
43 { |
|
44 mSlotActivated = true; |
|
45 } |
|
46 |
|
47 |
|
48 void MenuStatesTest::cleanup() |
|
49 { |
|
50 qApp->processEvents(); |
|
51 } |
|
52 |
|
53 void MenuStatesTest::HsSearchViewBuilder_construction() |
|
54 { |
|
55 HsSearchViewBuilder builder; |
|
56 QVERIFY(builder.mLoadedObjects.count()); |
|
57 } |
|
58 |
|
59 void MenuStatesTest::HsSearchViewBuilder_uiObjects() |
|
60 { |
|
61 HsSearchViewBuilder builder; |
|
62 QVERIFY(builder.searchListView()); |
|
63 QVERIFY(builder.searchPanel()); |
|
64 QVERIFY(builder.searchView()); |
|
65 QVERIFY(builder.searchViewLabel()); |
|
66 } |
|
67 |
|
68 void MenuStatesTest::HsSearchViewBuilder_setSearchLabledContext() |
|
69 { |
|
70 HsSearchViewBuilder builder; |
|
71 builder.setSearchLabledContext(); |
|
72 QVERIFY(builder.mLabledContext); |
|
73 } |
|
74 |
|
75 void MenuStatesTest::HsSearchViewBuilder_loadViewEmptySection() |
|
76 { |
|
77 HsSearchViewBuilder builder; |
|
78 int firstCount = builder.mLoadedObjects.count(); |
|
79 builder.loadViewEmptySection(); |
|
80 QCOMPARE(firstCount, builder.mLoadedObjects.count()); |
|
81 } |
|
82 |
|
83 void MenuStatesTest::HsSearchViewBuilder_loadViewListSection() |
|
84 { |
|
85 HsSearchViewBuilder builder; |
|
86 int firstCount = builder.mLoadedObjects.count(); |
|
87 builder.loadViewListSection(); |
|
88 QCOMPARE(firstCount, builder.mLoadedObjects.count()); |
|
89 } |
|
90 |
|
91 void MenuStatesTest::HsSearchViewBuilder_searchViewConstruction() |
|
92 { |
|
93 HsMenuViewBuilder builder; |
|
94 HsMainWindowMock window; |
|
95 |
|
96 HsSearchView search(builder, HsAllAppsContext, window); |
|
97 |
|
98 QCOMPARE(search.mProxyModel->filterRole(), int(CaItemModel::TextRole)); |
|
99 QCOMPARE(search.mProxyModel->filterKeyColumn(), 0); |
|
100 QCOMPARE(search.mProxyModel->sortRole(), int(CaItemModel::TextRole)); |
|
101 } |
|
102 |
|
103 void MenuStatesTest::HsSearchViewBuilder_activatedProxySlot() |
|
104 { |
|
105 HsMenuViewBuilder builder; |
|
106 HsMainWindowMock window; |
|
107 |
|
108 HsSearchView search(builder, HsAllAppsContext, window); |
|
109 connect(&search, SIGNAL(activated(QModelIndex)), |
|
110 this, SLOT(testSlot())); |
|
111 QModelIndex idx; |
|
112 |
|
113 mSlotActivated = false; |
|
114 search.activatedProxySlot(idx); |
|
115 QCOMPARE(mSlotActivated, true); |
|
116 } |
|
117 |
|
118 void MenuStatesTest::HsSearchViewBuilder_longPressedProxySlot() |
|
119 { |
|
120 HsMenuViewBuilder builder; |
|
121 HsMainWindowMock window; |
|
122 |
|
123 HsSearchView search(builder, HsAllAppsContext, window); |
|
124 connect(&search, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)), |
|
125 this, SLOT(testSlot())); |
|
126 |
|
127 MockViewItem item; |
|
128 QPointF point; |
|
129 |
|
130 mSlotActivated = false; |
|
131 search.longPressedProxySlot(&item, point); |
|
132 QCOMPARE(mSlotActivated, true); |
|
133 } |
|
134 |
|
135 void MenuStatesTest::HsSearchViewBuilder_showHide() |
|
136 { |
|
137 HsMenuViewBuilder builder; |
|
138 HsMainWindowMock window; |
|
139 |
|
140 HsSearchView search(builder, HsAllAppsContext, window); |
|
141 |
|
142 search.setSearchPanelVisible(true); |
|
143 QVERIFY(search.mSearchListView); |
|
144 search.hideSearchPanel(); |
|
145 QVERIFY(!search.mSearchListView); |
|
146 |
|
147 } |
|
148 |
|
149 |
|
150 class MockInputContext: public QInputContext |
|
151 { |
|
152 public: |
|
153 QEvent::Type mEventType; |
|
154 MockInputContext(): mEventType(QEvent::None) {} |
|
155 QString identifierName() { return qApp->inputContext()->identifierName();} |
|
156 bool isComposing() const { return qApp->inputContext()->isComposing();} |
|
157 QString language() { return qApp->inputContext()->language();} |
|
158 void reset() {;} |
|
159 void setFocusWidget(QWidget* widget) {QInputContext::setFocusWidget(widget);} |
|
160 bool filterEvent(const QEvent* event) |
|
161 { |
|
162 mEventType = event->type(); |
|
163 return true; |
|
164 } |
|
165 }; |
|
166 |
|
167 void MenuStatesTest::HsSearchViewBuilder_hideVkb() |
|
168 { |
|
169 HsMenuViewBuilder builder; |
|
170 HsMainWindowMock window; |
|
171 |
|
172 HsSearchView search(builder, HsAllAppsContext, window); |
|
173 |
|
174 MockInputContext *const newInputContext(new MockInputContext()); |
|
175 |
|
176 qApp->setInputContext(newInputContext); |
|
177 |
|
178 search.hideVkb(); |
|
179 |
|
180 QEvent::Type actualEventType = newInputContext->mEventType; |
|
181 qApp->setInputContext(0); |
|
182 |
|
183 QCOMPARE(actualEventType, QEvent::CloseSoftwareInputPanel); |
|
184 } |
|
185 |
|
186 |
|
187 QTEST_MAIN(MenuStatesTest) |