|
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: Main test class for domain model. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <qservicemanager.h> |
|
19 #include <hbinstance.h> |
|
20 #include "t_hsdomainmodel.h" |
|
21 #include "hsdatabase.h" |
|
22 #include "hspage.h" |
|
23 #include "hsscene.h" |
|
24 #include "hsdomainmodeldatastructures.h" |
|
25 #include "hswidgetpositioningonwidgetadd.h" |
|
26 #include "hswidgetcomponentregistry.h" |
|
27 #include "hsbackuprestoreobserver.h" |
|
28 #include "hsshortcutservice.h" |
|
29 #include "caservice.h" |
|
30 #include "hsconfiguration.h" |
|
31 #include "hswallpaper.h" |
|
32 |
|
33 QTM_USE_NAMESPACE |
|
34 |
|
35 #ifdef Q_OS_SYMBIAN |
|
36 #include <e32base.h> |
|
37 #endif |
|
38 |
|
39 const char WIDGET_PLUGIN_PATH[] = "./hsresources/plugins/widgetplugins/"; |
|
40 const char WIDGET_PLUGIN_XML[] = "mockwidgetplugin.xml"; |
|
41 const char WIDGET_PLUGIN_TOOSMALL_XML[] = "mockwidgetplugintoosmall.xml"; |
|
42 const char WIDGET_PLUGIN_TOOBIG_XML[] = "mockwidgetplugintoobig.xml"; |
|
43 const char WIDGET_PLUGIN_CHEATER_XML[] = "mockwidgetplugincheater.xml"; |
|
44 const char DBPATH[]= "./"; |
|
45 const char DBNAME[] = "hsdomainmodeltest2.db"; |
|
46 const char DBNAMECLEAN[] = "hsdomainmodeltest.db"; |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 void TestHsDomainModel::initTestCase() |
|
52 { |
|
53 mCaService = CaService::instance(); |
|
54 QString path = QDir(WIDGET_PLUGIN_PATH).absolutePath(); |
|
55 QApplication::addLibraryPath(path); |
|
56 QServiceManager manager; |
|
57 if (!manager.addService(QDir(WIDGET_PLUGIN_PATH).absolutePath().append("/").append(WIDGET_PLUGIN_XML))) { |
|
58 QServiceManager::Error err = manager.error(); |
|
59 qDebug() << "TestHsDomainModel::initTestCase register mockwidgetplugin failed" << err; |
|
60 } |
|
61 if (!manager.addService(QDir(WIDGET_PLUGIN_PATH).absolutePath().append("/").append(WIDGET_PLUGIN_TOOSMALL_XML))) { |
|
62 QServiceManager::Error err = manager.error(); |
|
63 qDebug() << "TestHsDomainModel::initTestCase register mockwidgetplugintoosmall failed" << err; |
|
64 } |
|
65 |
|
66 if (!manager.addService(QDir(WIDGET_PLUGIN_PATH).absolutePath().append("/").append(WIDGET_PLUGIN_TOOBIG_XML))) { |
|
67 QServiceManager::Error err = manager.error(); |
|
68 qDebug() << "TestHsDomainModel::initTestCase register mockwidgetplugintoobig failed" << err; |
|
69 } |
|
70 |
|
71 if (!manager.addService(QDir(WIDGET_PLUGIN_PATH).absolutePath().append("/").append(WIDGET_PLUGIN_CHEATER_XML))) { |
|
72 QServiceManager::Error err = manager.error(); |
|
73 qDebug() << "TestHsDomainModel::initTestCase register mockwidgetplugincheater failed" << err; |
|
74 } |
|
75 |
|
76 HsConfiguration::setInstance(new HsConfiguration); |
|
77 |
|
78 HsWidgetPositioningOnWidgetAdd::setInstance( |
|
79 new HsAnchorPointInBottomRight); |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 void TestHsDomainModel::cleanupTestCase() |
|
86 { |
|
87 QServiceManager manager; |
|
88 manager.removeService("mockwidgetplugin"); |
|
89 manager.removeService("mockwidgetplugintoosmall"); |
|
90 manager.removeService("mockwidgetplugintoobig"); |
|
91 manager.removeService("mockwidgetplugincheater"); |
|
92 HsDatabase::setInstance(0); |
|
93 |
|
94 delete HsWidgetComponentRegistry::mInstance; |
|
95 HsWidgetComponentRegistry::mInstance = 0; |
|
96 |
|
97 delete HsShortcutService::mInstance; |
|
98 HsShortcutService::mInstance = 0; |
|
99 } |
|
100 |
|
101 void TestHsDomainModel::init() |
|
102 { |
|
103 QString dbFile = QDir(DBPATH).absolutePath() + "/" + QString(DBNAME); |
|
104 QString testDbFile = QDir(DBPATH).absolutePath() + "/" + QString(DBNAMECLEAN); |
|
105 QFile::remove(dbFile); |
|
106 QFile::copy(testDbFile, dbFile); |
|
107 |
|
108 HsScene::setInstance(new HsScene); |
|
109 |
|
110 HsDatabase *db = new HsDatabase; |
|
111 HsDatabase::setInstance(db); |
|
112 db->setConnectionName("homescreen.dbc"); |
|
113 db->setDatabaseName(dbFile); |
|
114 db->open(); |
|
115 |
|
116 mWallpaperTypeScene = true; |
|
117 } |
|
118 |
|
119 void TestHsDomainModel::cleanup() |
|
120 { |
|
121 // cleanup all the pages and widgets |
|
122 HsDatabase::setInstance(0); |
|
123 QString path = QDir(WIDGET_PLUGIN_PATH).absolutePath(); |
|
124 QApplication::addLibraryPath( path ); |
|
125 QString dbFile = QDir(DBPATH).absolutePath() + "/" + QString(DBNAME); |
|
126 QFile::remove(dbFile); |
|
127 |
|
128 if (HsBackupRestoreObserver::mInstance) { |
|
129 delete HsBackupRestoreObserver::mInstance; |
|
130 HsBackupRestoreObserver::mInstance = 0; |
|
131 } |
|
132 |
|
133 delete HsScene::takeInstance(); |
|
134 } |
|
135 |
|
136 void TestHsDomainModel::createPagesToDatabase(int pageCount) |
|
137 { |
|
138 HsDatabase *db = HsDatabase::instance(); |
|
139 for (int i = 0; i < pageCount; ++i) { |
|
140 HsPageData data; |
|
141 data.indexPosition = i; |
|
142 db->insertPage(data); |
|
143 } |
|
144 } |
|
145 |
|
146 void TestHsDomainModel::createSceneWithPages(int pageCount,int activePageIndex) |
|
147 { |
|
148 for (int i = 0; i < pageCount; ++i) { |
|
149 HsPageData pageData; |
|
150 pageData.indexPosition = i; |
|
151 HsPage *p = HsPage::createInstance(pageData); |
|
152 HsScene::instance()->addPage(p); |
|
153 } |
|
154 if (activePageIndex < pageCount) { |
|
155 QList<HsPage*> pages = HsScene::instance()->pages(); |
|
156 if(activePageIndex < pages.count()) |
|
157 HsScene::instance()->setActivePage(pages.at(activePageIndex)); |
|
158 } |
|
159 |
|
160 } |
|
161 |
|
162 void TestHsDomainModel::destroySceneAndPages() |
|
163 { |
|
164 delete HsScene::takeInstance(); |
|
165 } |
|
166 |
|
167 QString TestHsDomainModel::sourceTestWallpaper() |
|
168 { |
|
169 QString testImage("default_portrait.png"); |
|
170 QString fullSource(wallpaperDirectory() + testImage); |
|
171 return QDir::toNativeSeparators(fullSource); |
|
172 } |
|
173 |
|
174 QString TestHsDomainModel::targetPortraitTestWallpaper() |
|
175 { |
|
176 QString path = wallpaperDirectory() + |
|
177 "1_portrait." + |
|
178 QFileInfo(sourceTestWallpaper()).suffix(); |
|
179 return QDir::toNativeSeparators(path); |
|
180 } |
|
181 |
|
182 QString TestHsDomainModel::targetLandscapeTestWallpaper() |
|
183 { |
|
184 QString path = wallpaperDirectory() + |
|
185 "1_landscape." + |
|
186 QFileInfo(sourceTestWallpaper()).suffix(); |
|
187 return QDir::toNativeSeparators(path); |
|
188 } |
|
189 |
|
190 QString TestHsDomainModel::tempTestWallpaper() |
|
191 { |
|
192 QString tempTestImage("tempdefault_portrait.png"); |
|
193 QString fullTarget(wallpaperDirectory() + tempTestImage); |
|
194 return QDir::toNativeSeparators(fullTarget); |
|
195 } |
|
196 |
|
197 QString TestHsDomainModel::notExistingTestWallpaper() |
|
198 { |
|
199 QString tempTestImage("notfound.png"); |
|
200 QString fullTarget(wallpaperDirectory() + tempTestImage); |
|
201 return QDir::toNativeSeparators(fullTarget); |
|
202 } |
|
203 |
|
204 QString TestHsDomainModel::wallpaperDirectory() |
|
205 { |
|
206 QString directory; |
|
207 if (mWallpaperTypeScene) { |
|
208 HsSceneWallpaper wallpaper(HsScene::instance()); |
|
209 directory = wallpaper.wallpaperDirectory(); |
|
210 } else { |
|
211 HsPage *page = new HsPage(); |
|
212 HsPageWallpaper wallpaper(page); |
|
213 directory = wallpaper.wallpaperDirectory(); |
|
214 delete page; |
|
215 } |
|
216 |
|
217 return directory; |
|
218 } |
|
219 |
|
220 void TestHsDomainModel::cleanupTargetWallpaperFiles() |
|
221 { |
|
222 if (QFile::exists(targetPortraitTestWallpaper())) { |
|
223 QFile::remove(targetPortraitTestWallpaper()); |
|
224 } |
|
225 |
|
226 if (QFile::exists(targetLandscapeTestWallpaper())) { |
|
227 QFile::remove(targetLandscapeTestWallpaper()); |
|
228 } |
|
229 |
|
230 if (QFile::exists(tempTestWallpaper())) { |
|
231 QFile::remove(tempTestWallpaper()); |
|
232 } |
|
233 } |
|
234 |
|
235 #ifdef Q_OS_SYMBIAN |
|
236 //QTEST_MAIN corrected since crashes if TRAP not in correct place. |
|
237 //Will be corrected in later (estimate 4.6.0) Qt release for Symbian. |
|
238 int main(int argc, char *argv[]) |
|
239 { |
|
240 QApplication app(argc, argv); |
|
241 int error(0); |
|
242 TRAP_IGNORE( QTEST_DISABLE_KEYPAD_NAVIGATION \ |
|
243 HbInstance::instance(); \ |
|
244 TestHsDomainModel tc; \ |
|
245 error = QTest::qExec(&tc, argc, argv);); |
|
246 return error; |
|
247 } |
|
248 #else //Q_OS_SYMBIAN |
|
249 int main(int argc, char *argv[]) |
|
250 { |
|
251 QApplication app(argc, argv); |
|
252 QTEST_DISABLE_KEYPAD_NAVIGATION |
|
253 HbInstance::instance(); |
|
254 TestHsDomainModel tc; |
|
255 return QTest::qExec(&tc, argc, argv); |
|
256 } |
|
257 //QTEST_MAIN(TestHsDomainModel) |
|
258 #endif //Q_OS_SYMBIAN |