90
|
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"
|
101
|
32 |
#include "hsdbupdatethread.h"
|
90
|
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);
|
101
|
80 |
|
90
|
81 |
}
|
|
82 |
|
|
83 |
// ---------------------------------------------------------------------------
|
|
84 |
// ---------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
void TestHsDomainModel::cleanupTestCase()
|
|
87 |
{
|
|
88 |
QServiceManager manager;
|
|
89 |
manager.removeService("mockwidgetplugin");
|
|
90 |
manager.removeService("mockwidgetplugintoosmall");
|
|
91 |
manager.removeService("mockwidgetplugintoobig");
|
|
92 |
manager.removeService("mockwidgetplugincheater");
|
|
93 |
HsDatabase::setInstance(0);
|
|
94 |
|
|
95 |
delete HsWidgetComponentRegistry::mInstance;
|
|
96 |
HsWidgetComponentRegistry::mInstance = 0;
|
|
97 |
|
|
98 |
delete HsShortcutService::mInstance;
|
|
99 |
HsShortcutService::mInstance = 0;
|
101
|
100 |
|
90
|
101 |
}
|
|
102 |
|
|
103 |
void TestHsDomainModel::init()
|
|
104 |
{
|
|
105 |
QString dbFile = QDir(DBPATH).absolutePath() + "/" + QString(DBNAME);
|
|
106 |
QString testDbFile = QDir(DBPATH).absolutePath() + "/" + QString(DBNAMECLEAN);
|
|
107 |
QFile::remove(dbFile);
|
|
108 |
QFile::copy(testDbFile, dbFile);
|
|
109 |
|
|
110 |
HsScene::setInstance(new HsScene);
|
|
111 |
|
|
112 |
HsDatabase *db = new HsDatabase;
|
|
113 |
HsDatabase::setInstance(db);
|
|
114 |
db->setConnectionName("homescreen.dbc");
|
|
115 |
db->setDatabaseName(dbFile);
|
|
116 |
db->open();
|
101
|
117 |
|
|
118 |
HsDbUpdateThread *dbUpdateThread = new HsDbUpdateThread("homescreen.dbc",dbFile);
|
|
119 |
HsDbUpdateThread::setInstance(dbUpdateThread);
|
|
120 |
//dbUpdateThread->start();
|
90
|
121 |
mWallpaperTypeScene = true;
|
|
122 |
}
|
|
123 |
|
|
124 |
void TestHsDomainModel::cleanup()
|
|
125 |
{
|
|
126 |
// cleanup all the pages and widgets
|
101
|
127 |
// HsDbUpdateThread::instance()->quit();
|
|
128 |
HsDbUpdateThread::setInstance(0);
|
90
|
129 |
HsDatabase::setInstance(0);
|
|
130 |
QString path = QDir(WIDGET_PLUGIN_PATH).absolutePath();
|
|
131 |
QApplication::addLibraryPath( path );
|
|
132 |
QString dbFile = QDir(DBPATH).absolutePath() + "/" + QString(DBNAME);
|
|
133 |
QFile::remove(dbFile);
|
|
134 |
|
|
135 |
if (HsBackupRestoreObserver::mInstance) {
|
|
136 |
delete HsBackupRestoreObserver::mInstance;
|
|
137 |
HsBackupRestoreObserver::mInstance = 0;
|
|
138 |
}
|
|
139 |
|
|
140 |
delete HsScene::takeInstance();
|
|
141 |
}
|
|
142 |
|
|
143 |
void TestHsDomainModel::createPagesToDatabase(int pageCount)
|
|
144 |
{
|
|
145 |
HsDatabase *db = HsDatabase::instance();
|
|
146 |
for (int i = 0; i < pageCount; ++i) {
|
|
147 |
HsPageData data;
|
|
148 |
data.indexPosition = i;
|
|
149 |
db->insertPage(data);
|
|
150 |
}
|
|
151 |
}
|
|
152 |
|
|
153 |
void TestHsDomainModel::createSceneWithPages(int pageCount,int activePageIndex)
|
|
154 |
{
|
|
155 |
for (int i = 0; i < pageCount; ++i) {
|
|
156 |
HsPageData pageData;
|
|
157 |
pageData.indexPosition = i;
|
|
158 |
HsPage *p = HsPage::createInstance(pageData);
|
|
159 |
HsScene::instance()->addPage(p);
|
|
160 |
}
|
|
161 |
if (activePageIndex < pageCount) {
|
|
162 |
QList<HsPage*> pages = HsScene::instance()->pages();
|
|
163 |
if(activePageIndex < pages.count())
|
|
164 |
HsScene::instance()->setActivePage(pages.at(activePageIndex));
|
|
165 |
}
|
|
166 |
|
|
167 |
}
|
|
168 |
|
|
169 |
void TestHsDomainModel::destroySceneAndPages()
|
|
170 |
{
|
|
171 |
delete HsScene::takeInstance();
|
|
172 |
}
|
|
173 |
|
|
174 |
QString TestHsDomainModel::sourceTestWallpaper()
|
|
175 |
{
|
|
176 |
QString testImage("default_portrait.png");
|
|
177 |
QString fullSource(wallpaperDirectory() + testImage);
|
|
178 |
return QDir::toNativeSeparators(fullSource);
|
|
179 |
}
|
|
180 |
|
|
181 |
QString TestHsDomainModel::targetPortraitTestWallpaper()
|
|
182 |
{
|
|
183 |
QString path = wallpaperDirectory() +
|
|
184 |
"1_portrait." +
|
|
185 |
QFileInfo(sourceTestWallpaper()).suffix();
|
|
186 |
return QDir::toNativeSeparators(path);
|
|
187 |
}
|
|
188 |
|
|
189 |
QString TestHsDomainModel::targetLandscapeTestWallpaper()
|
|
190 |
{
|
|
191 |
QString path = wallpaperDirectory() +
|
|
192 |
"1_landscape." +
|
|
193 |
QFileInfo(sourceTestWallpaper()).suffix();
|
|
194 |
return QDir::toNativeSeparators(path);
|
|
195 |
}
|
|
196 |
|
|
197 |
QString TestHsDomainModel::tempTestWallpaper()
|
|
198 |
{
|
|
199 |
QString tempTestImage("tempdefault_portrait.png");
|
|
200 |
QString fullTarget(wallpaperDirectory() + tempTestImage);
|
|
201 |
return QDir::toNativeSeparators(fullTarget);
|
|
202 |
}
|
|
203 |
|
|
204 |
QString TestHsDomainModel::notExistingTestWallpaper()
|
|
205 |
{
|
|
206 |
QString tempTestImage("notfound.png");
|
|
207 |
QString fullTarget(wallpaperDirectory() + tempTestImage);
|
|
208 |
return QDir::toNativeSeparators(fullTarget);
|
|
209 |
}
|
|
210 |
|
|
211 |
QString TestHsDomainModel::wallpaperDirectory()
|
|
212 |
{
|
|
213 |
QString directory;
|
|
214 |
if (mWallpaperTypeScene) {
|
|
215 |
HsSceneWallpaper wallpaper(HsScene::instance());
|
|
216 |
directory = wallpaper.wallpaperDirectory();
|
|
217 |
} else {
|
|
218 |
HsPage *page = new HsPage();
|
|
219 |
HsPageWallpaper wallpaper(page);
|
|
220 |
directory = wallpaper.wallpaperDirectory();
|
|
221 |
delete page;
|
|
222 |
}
|
|
223 |
|
|
224 |
return directory;
|
|
225 |
}
|
|
226 |
|
|
227 |
void TestHsDomainModel::cleanupTargetWallpaperFiles()
|
|
228 |
{
|
|
229 |
if (QFile::exists(targetPortraitTestWallpaper())) {
|
|
230 |
QFile::remove(targetPortraitTestWallpaper());
|
|
231 |
}
|
|
232 |
|
|
233 |
if (QFile::exists(targetLandscapeTestWallpaper())) {
|
|
234 |
QFile::remove(targetLandscapeTestWallpaper());
|
|
235 |
}
|
|
236 |
|
|
237 |
if (QFile::exists(tempTestWallpaper())) {
|
|
238 |
QFile::remove(tempTestWallpaper());
|
|
239 |
}
|
|
240 |
}
|
|
241 |
|
|
242 |
#ifdef Q_OS_SYMBIAN
|
|
243 |
//QTEST_MAIN corrected since crashes if TRAP not in correct place.
|
|
244 |
//Will be corrected in later (estimate 4.6.0) Qt release for Symbian.
|
|
245 |
int main(int argc, char *argv[])
|
|
246 |
{
|
|
247 |
QApplication app(argc, argv);
|
|
248 |
int error(0);
|
|
249 |
TRAP_IGNORE( QTEST_DISABLE_KEYPAD_NAVIGATION \
|
|
250 |
HbInstance::instance(); \
|
|
251 |
TestHsDomainModel tc; \
|
|
252 |
error = QTest::qExec(&tc, argc, argv););
|
|
253 |
return error;
|
|
254 |
}
|
|
255 |
#else //Q_OS_SYMBIAN
|
|
256 |
int main(int argc, char *argv[])
|
|
257 |
{
|
|
258 |
QApplication app(argc, argv);
|
|
259 |
QTEST_DISABLE_KEYPAD_NAVIGATION
|
|
260 |
HbInstance::instance();
|
|
261 |
TestHsDomainModel tc;
|
|
262 |
return QTest::qExec(&tc, argc, argv);
|
|
263 |
}
|
|
264 |
//QTEST_MAIN(TestHsDomainModel)
|
|
265 |
#endif //Q_OS_SYMBIAN
|