|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "t_hsdomainmodel.h" |
|
20 #include "hswallpaper.h" |
|
21 #include "hsscene.h" |
|
22 #include "hspage.h" |
|
23 |
|
24 void TestHsDomainModel::testHsWallpaperConstruction() |
|
25 { |
|
26 { |
|
27 HsSceneWallpaper wallpaper(HsScene::instance()); |
|
28 QVERIFY(!wallpaper.parent()); |
|
29 } |
|
30 |
|
31 HsPage *page = new HsPage(); |
|
32 page->setDatabaseId(1); |
|
33 { |
|
34 HbWidget parent; |
|
35 HsPageWallpaper wallpaper(page, &parent); |
|
36 QVERIFY(wallpaper.parentItem() == &parent); |
|
37 } |
|
38 |
|
39 HsPageWallpaper *pagewallpaper = new HsPageWallpaper(page); |
|
40 QVERIFY(pagewallpaper); |
|
41 QVERIFY(!pagewallpaper->parent()); |
|
42 delete pagewallpaper; |
|
43 |
|
44 HbWidget *parent = new HbWidget(); |
|
45 HsSceneWallpaper *scenewallpaper = new HsSceneWallpaper(HsScene::instance(), parent); |
|
46 QVERIFY(scenewallpaper); |
|
47 QVERIFY(scenewallpaper->parentItem() == parent); |
|
48 delete parent; |
|
49 |
|
50 delete page; |
|
51 } |
|
52 |
|
53 void TestHsDomainModel::testHsWallpaperSetNRemoveDefaultImage() |
|
54 { |
|
55 //Default image is set already at construction phase while scene DB id |
|
56 //is not set. |
|
57 QVERIFY(QFile::exists(sourceTestWallpaper())); |
|
58 HsSceneWallpaper *wallpaper = new HsSceneWallpaper(HsScene::instance()); |
|
59 QVERIFY(QDir::toNativeSeparators(wallpaper->mPortraitImagePath) == sourceTestWallpaper()); |
|
60 wallpaper->setDefaultImage(); //Coverage improvement. Default image already set at construction phase. |
|
61 QVERIFY(QDir::toNativeSeparators(wallpaper->mPortraitImagePath) == sourceTestWallpaper()); |
|
62 QVERIFY(wallpaper->mIsDefaultImage); |
|
63 wallpaper->remove(); |
|
64 QVERIFY(!wallpaper->mIsDefaultImage); |
|
65 QVERIFY(wallpaper->mPortraitImagePath.isEmpty()); |
|
66 QVERIFY(wallpaper->mLandscapeImagePath.isEmpty()); |
|
67 delete wallpaper; |
|
68 } |
|
69 |
|
70 void TestHsDomainModel::testHsWallpaperSetNRemoveImage() |
|
71 { |
|
72 mWallpaperTypeScene = false; //Use page wallpaper at this test |
|
73 //Prepare test case by checking that source file exists and |
|
74 //deleting any page specific wallpapers existing in target folder |
|
75 QVERIFY(QFile::exists(sourceTestWallpaper())); |
|
76 cleanupTargetWallpaperFiles(); |
|
77 |
|
78 HsPage *page = new HsPage(); |
|
79 page->setDatabaseId(1); |
|
80 //Construction phase sets default image since Id based image does not exist, yet. |
|
81 HsPageWallpaper *wallpaper = new HsPageWallpaper(page); |
|
82 QVERIFY(QDir::toNativeSeparators(wallpaper->mPortraitImagePath) == sourceTestWallpaper()); |
|
83 |
|
84 //TEST EMPTY SOURCE STRING |
|
85 QSignalSpy setImageFailedSpy(wallpaper, SIGNAL(imageSetFailed())); |
|
86 wallpaper->setImage(QString()); |
|
87 QCOMPARE(setImageFailedSpy.count(), 1); |
|
88 |
|
89 QSignalSpy imageSetSpy(wallpaper, SIGNAL(imageSet())); |
|
90 QEventLoop waitFinished; |
|
91 QTimer eventLoopTimer; |
|
92 eventLoopTimer.setInterval(15000); |
|
93 eventLoopTimer.setSingleShot(true); |
|
94 connect(wallpaper, SIGNAL(imageSet()), &waitFinished, SLOT(quit())); |
|
95 connect(&eventLoopTimer, SIGNAL(timeout()), &waitFinished, SLOT(quit())); |
|
96 //TEST SETIMAGE |
|
97 wallpaper->setImage(sourceTestWallpaper()); |
|
98 eventLoopTimer.start(); |
|
99 waitFinished.exec(); |
|
100 |
|
101 QCOMPARE(imageSetSpy.count(), 1); |
|
102 QVERIFY(eventLoopTimer.isActive()); |
|
103 eventLoopTimer.stop(); |
|
104 |
|
105 //Now we have Id based images. |
|
106 QVERIFY(QDir::toNativeSeparators(wallpaper->mPortraitImagePath) == targetPortraitTestWallpaper()); |
|
107 QVERIFY(QDir::toNativeSeparators(wallpaper->mLandscapeImagePath) == targetLandscapeTestWallpaper()); |
|
108 QVERIFY(QFile::exists(targetPortraitTestWallpaper())); |
|
109 QVERIFY(QFile::exists(targetLandscapeTestWallpaper())); |
|
110 |
|
111 //TEST REMOVE |
|
112 wallpaper->remove(); |
|
113 QVERIFY(wallpaper->mPortraitImagePath.isEmpty()); |
|
114 QVERIFY(wallpaper->mLandscapeImagePath.isEmpty()); |
|
115 QVERIFY(!QFile::exists(targetPortraitTestWallpaper())); |
|
116 QVERIFY(!QFile::exists(targetLandscapeTestWallpaper())); |
|
117 |
|
118 delete wallpaper; |
|
119 delete page; |
|
120 } |
|
121 |
|
122 void TestHsDomainModel::testHsWallpaperLoaderFailed() |
|
123 { |
|
124 cleanupTargetWallpaperFiles(); |
|
125 |
|
126 HsPage *page = new HsPage(); |
|
127 page->setDatabaseId(1); |
|
128 //Construction phase sets default image since Id based image does not exist, yet. |
|
129 HsPageWallpaper *wallpaper = new HsPageWallpaper(page); |
|
130 QSignalSpy loaderFailedSpy(wallpaper, SIGNAL(imageSetFailed())); |
|
131 wallpaper->onLoaderFailed(); |
|
132 QCOMPARE(loaderFailedSpy.count(), 1); |
|
133 |
|
134 delete wallpaper; |
|
135 delete page; |
|
136 } |
|
137 |
|
138 void TestHsDomainModel::testHsWallpaperScene() |
|
139 { |
|
140 cleanupTargetWallpaperFiles(); |
|
141 //Construction phase sets default image since Id based image does not exist, yet. |
|
142 HsSceneWallpaper *wallpaper = new HsSceneWallpaper(HsScene::instance()); |
|
143 QVariantHash papers = wallpaper->createTargets("."); |
|
144 QVERIFY(papers.count()==2); |
|
145 wallpaper->setScene(0); |
|
146 QVERIFY(HsScene::instance() == wallpaper->mScene); |
|
147 |
|
148 delete wallpaper; |
|
149 } |
|
150 void TestHsDomainModel::testHsWallpaperPage() |
|
151 { |
|
152 cleanupTargetWallpaperFiles(); |
|
153 |
|
154 HsPage *page = new HsPage(); |
|
155 page->setDatabaseId(1); |
|
156 //Construction phase sets default image since Id based image does not exist, yet. |
|
157 HsPageWallpaper *wallpaper = new HsPageWallpaper(page); |
|
158 wallpaper->setPage(0); |
|
159 QVERIFY(page == wallpaper->mPage); |
|
160 delete wallpaper; |
|
161 delete page; |
|
162 } |
|
163 |
|
164 void TestHsDomainModel::testHsWallpaperSetImages() |
|
165 { |
|
166 HsPageWallpaper wp(0); |
|
167 QSignalSpy spyIS(&wp, SIGNAL(imageSet())); |
|
168 QSignalSpy spyISF(&wp, SIGNAL(imageSetFailed())); |
|
169 |
|
170 wp.setImages(QString(), QString()); |
|
171 |
|
172 QCOMPARE(spyIS.count(), 0); |
|
173 QCOMPARE(spyISF.count(), 1); |
|
174 } |