|
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 <QScopedPointer> |
|
19 #include <QModelIndex> |
|
20 |
|
21 #include "caentry.h" |
|
22 #include "caservice.h" |
|
23 #include "hsmenuitemmodel.h" |
|
24 #include "t_allappsstate.h" |
|
25 #include "hsapp_defs.h" |
|
26 #include "hsaddmodeproxymodel.h" |
|
27 #include "t_hsproxymodeltestmockmodel.h" |
|
28 |
|
29 const char MenuStatesTest::TEST_PARAM_NAME[] = "test_param_name"; |
|
30 const char MenuStatesTest::TEST_PARAM_VALUE[] = "test_param_value"; |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 void MenuStatesTest::addModeProxyModel_construction() |
|
36 { |
|
37 #ifdef Q_OS_SYMBIAN |
|
38 #ifdef UT_MEMORY_CHECK |
|
39 __UHEAP_MARK; |
|
40 #endif//UT_MEMORY_CHECK |
|
41 #endif//Q_OS_SYMBIAN |
|
42 { |
|
43 ////clear test entries |
|
44 CaQuery q; |
|
45 q.setAttribute(QString(Hs::widgetParam)+TEST_PARAM_NAME, TEST_PARAM_VALUE); |
|
46 QSharedPointer<CaService> caServiceInstance = CaService::instance(); |
|
47 QList< QSharedPointer<CaEntry> > testEntries = caServiceInstance->getEntries(q); |
|
48 caServiceInstance->removeEntries(testEntries); |
|
49 ////init |
|
50 CaEntry cwrtWidgetWithMiniViewEntry(ItemEntryRole); |
|
51 cwrtWidgetWithMiniViewEntry.setEntryTypeName(Hs::applicationTypeName); |
|
52 cwrtWidgetWithMiniViewEntry.setText("AccuWeather-W3C_TEST"); |
|
53 cwrtWidgetWithMiniViewEntry.setAttribute(Hs::swTypeKey,Hs::HS_CWRT_APP_TYPE); |
|
54 cwrtWidgetWithMiniViewEntry.setAttribute(Hs::widgetUriAttributeName,Hs::HS_WIDGET_URI_ATTRIBUTE_CWRT_VALUE); |
|
55 cwrtWidgetWithMiniViewEntry.setAttribute(QString(Hs::widgetParam)+TEST_PARAM_NAME,TEST_PARAM_VALUE); |
|
56 QSharedPointer<CaEntry> entry = caServiceInstance->createEntry(cwrtWidgetWithMiniViewEntry); |
|
57 QVERIFY(entry.data() != NULL); |
|
58 |
|
59 ////test |
|
60 QVariantHash preferences; |
|
61 preferences.insert(TEST_PARAM_NAME,TEST_PARAM_VALUE); |
|
62 int widgetEntryId = HsAddModeProxyModel::findCwrtWidgetEntryId(preferences); |
|
63 QCOMPARE(widgetEntryId,entry->id()); |
|
64 |
|
65 QScopedPointer<HsAddModeProxyModel> addModeProxyModel; |
|
66 addModeProxyModel.reset( new HsAddModeProxyModel()); |
|
67 |
|
68 QVERIFY(addModeProxyModel->mNotifier.data() != NULL ); |
|
69 QCOMPARE(addModeProxyModel->mQuery.entryTypeNames().contains(Hs::applicationTypeName), QBool(true)); |
|
70 QMap<QString, QString> queryAttributes = addModeProxyModel->mQuery.attributes(); |
|
71 QCOMPARE(queryAttributes.value(Hs::swTypeKey), QString(Hs::HS_CWRT_APP_TYPE)); |
|
72 QCOMPARE(queryAttributes.value(Hs::widgetUriAttributeName), QString(Hs::HS_WIDGET_URI_ATTRIBUTE_CWRT_VALUE)); |
|
73 |
|
74 ////cwrt widget entry present in cache |
|
75 QCOMPARE(addModeProxyModel->mCwrtWidgetCache.keys().contains(entry->id()), QBool(true)); |
|
76 |
|
77 ////notification: remove entry |
|
78 addModeProxyModel->updateEntryStatus(*entry.data(), RemoveChangeType); |
|
79 QCOMPARE(addModeProxyModel->mCwrtWidgetCache.keys().contains(entry->id()), QBool(false)); |
|
80 ////notification: add entry |
|
81 addModeProxyModel->updateEntryStatus(*entry.data(), AddChangeType); |
|
82 QCOMPARE(addModeProxyModel->mCwrtWidgetCache.keys().contains(entry->id()), QBool(true)); |
|
83 |
|
84 ////clear |
|
85 bool removeResult = caServiceInstance->removeEntry(*entry.data()); |
|
86 QCOMPARE( removeResult , true ); |
|
87 } |
|
88 #ifdef Q_OS_SYMBIAN |
|
89 #ifdef UT_MEMORY_CHECK |
|
90 __UHEAP_MARKEND; |
|
91 #endif//UT_MEMORY_CHECK |
|
92 #endif//Q_OS_SYMBIAN |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void MenuStatesTest::addModeProxyModel_filterAcceptsRow() |
|
99 { |
|
100 #ifdef Q_OS_SYMBIAN |
|
101 #ifdef UT_MEMORY_CHECK |
|
102 __UHEAP_MARK; |
|
103 #endif//UT_MEMORY_CHECK |
|
104 #endif//Q_OS_SYMBIAN |
|
105 { |
|
106 ////clear test entries |
|
107 CaQuery q; |
|
108 q.setAttribute(QString(Hs::widgetParam)+TEST_PARAM_NAME, TEST_PARAM_VALUE); |
|
109 QSharedPointer<CaService> caServiceInstance = CaService::instance(); |
|
110 QList< QSharedPointer<CaEntry> > testEntries = caServiceInstance->getEntries(q); |
|
111 caServiceInstance->removeEntries(testEntries); |
|
112 ////init |
|
113 CaEntry cwrtWidgetWithMiniViewEntry(ItemEntryRole); |
|
114 cwrtWidgetWithMiniViewEntry.setEntryTypeName(Hs::applicationTypeName); |
|
115 cwrtWidgetWithMiniViewEntry.setText("AccuWeather-W3C_TEST"); |
|
116 cwrtWidgetWithMiniViewEntry.setAttribute(Hs::swTypeKey,Hs::HS_CWRT_APP_TYPE); |
|
117 cwrtWidgetWithMiniViewEntry.setAttribute(Hs::widgetUriAttributeName,Hs::HS_WIDGET_URI_ATTRIBUTE_CWRT_VALUE); |
|
118 cwrtWidgetWithMiniViewEntry.setAttribute(QString(Hs::widgetParam)+TEST_PARAM_NAME,TEST_PARAM_VALUE); |
|
119 QSharedPointer<CaEntry> entry = caServiceInstance->createEntry(cwrtWidgetWithMiniViewEntry); |
|
120 QVERIFY(entry.data() != NULL); |
|
121 |
|
122 ////test |
|
123 QScopedPointer<HsAddModeProxyModel> addModeProxyModel; |
|
124 addModeProxyModel.reset( new HsAddModeProxyModel()); |
|
125 QCOMPARE(addModeProxyModel->mCwrtWidgetCache.value(entry->id()), false); |
|
126 |
|
127 QScopedPointer<ProxyModelTestMockModel> proxyModelTestMockModel; |
|
128 proxyModelTestMockModel.reset( new ProxyModelTestMockModel(entry->id())); |
|
129 addModeProxyModel->setSourceModel(proxyModelTestMockModel.data()); |
|
130 bool result = addModeProxyModel->filterAcceptsRow(0,QModelIndex()); |
|
131 ///widget is not on HS so we show it |
|
132 QCOMPARE(result, true); |
|
133 |
|
134 QVariantHash preferences; |
|
135 preferences.insert(TEST_PARAM_NAME,TEST_PARAM_VALUE); |
|
136 addModeProxyModel->updateCacheOnAddWidget(Hs::HS_WIDGET_URI_ATTRIBUTE_CWRT_VALUE, preferences); |
|
137 QCOMPARE(addModeProxyModel->mCwrtWidgetCache.value(entry->id()), true); |
|
138 result = addModeProxyModel->filterAcceptsRow(0,QModelIndex()); |
|
139 ///widget is on HS so we do not show it |
|
140 QCOMPARE(result, false); |
|
141 |
|
142 addModeProxyModel->updateCacheOnRemoveWidget(Hs::HS_WIDGET_URI_ATTRIBUTE_CWRT_VALUE, preferences); |
|
143 QCOMPARE(addModeProxyModel->mCwrtWidgetCache.value(entry->id()), false); |
|
144 result = addModeProxyModel->filterAcceptsRow(0,QModelIndex()); |
|
145 ///widget is not on HS so we show it |
|
146 QCOMPARE(result, true); |
|
147 |
|
148 ////clear |
|
149 bool removeResult = caServiceInstance->removeEntry(*entry.data()); |
|
150 QCOMPARE( removeResult , true ); |
|
151 } |
|
152 #ifdef Q_OS_SYMBIAN |
|
153 #ifdef UT_MEMORY_CHECK |
|
154 __UHEAP_MARKEND; |
|
155 #endif//UT_MEMORY_CHECK |
|
156 #endif//Q_OS_SYMBIAN |
|
157 } |