90
|
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 <QObject>
|
|
20 |
#include <QString>
|
|
21 |
#include <QSignalSpy>
|
|
22 |
#include <QVariantHash>
|
|
23 |
#include <QEventLoop>
|
|
24 |
#include <QTimer>
|
|
25 |
|
|
26 |
#include "t_hsdomainmodel.h"
|
|
27 |
#include "hswallpaperloader.h"
|
|
28 |
#include "hswallpaperloaderthread.h"
|
|
29 |
|
|
30 |
void TestHsDomainModel::testHsWallpaperLoaderConstruction()
|
|
31 |
{
|
|
32 |
{
|
|
33 |
HsWallpaperLoader loader;
|
|
34 |
QVERIFY(!loader.parent());
|
|
35 |
}
|
|
36 |
|
|
37 |
{
|
|
38 |
QObject parent;
|
|
39 |
HsWallpaperLoader loader(&parent);
|
|
40 |
QVERIFY(loader.parent() == &parent);
|
|
41 |
}
|
|
42 |
|
|
43 |
HsWallpaperLoader *loader = new HsWallpaperLoader;
|
|
44 |
QVERIFY(loader);
|
|
45 |
QVERIFY(!loader->parent());
|
|
46 |
delete loader;
|
|
47 |
|
|
48 |
QObject *parent = new QObject();
|
|
49 |
loader = new HsWallpaperLoader(parent);
|
|
50 |
QVERIFY(loader);
|
|
51 |
QVERIFY(loader->parent() == parent);
|
|
52 |
delete parent;
|
|
53 |
}
|
|
54 |
|
|
55 |
void TestHsDomainModel::testHsWallpaperLoaderStartWithFinished()
|
|
56 |
{
|
|
57 |
//Test preparation
|
|
58 |
cleanupTargetWallpaperFiles();
|
|
59 |
|
|
60 |
HsWallpaperLoader *loader = new HsWallpaperLoader;
|
|
61 |
QSignalSpy finishedSpy(loader, SIGNAL(finished()));
|
|
62 |
|
|
63 |
//TEST START WITHOUT THREADS
|
|
64 |
loader->start();
|
|
65 |
QCOMPARE(finishedSpy.count(), 1);
|
|
66 |
QVERIFY(!loader->isRunning());
|
|
67 |
finishedSpy.clear();
|
|
68 |
|
|
69 |
//TEST START WITH ONE THREAD SUCCESSFUL
|
|
70 |
//Check that test file exist
|
|
71 |
QVERIFY(QFile::exists(sourceTestWallpaper()));
|
|
72 |
loader->setSourcePath(sourceTestWallpaper());
|
|
73 |
|
|
74 |
QVariantHash targets;
|
|
75 |
targets.insert(tempTestWallpaper(), QSize(360, 640));
|
|
76 |
loader->setTargets(targets);
|
|
77 |
|
|
78 |
QEventLoop waitFinished;
|
|
79 |
QTimer eventLoopTimer;
|
|
80 |
eventLoopTimer.setInterval(15000);
|
|
81 |
eventLoopTimer.setSingleShot(true);
|
|
82 |
connect(loader, SIGNAL(finished()), &waitFinished, SLOT(quit()));
|
|
83 |
connect(&eventLoopTimer, SIGNAL(timeout()), &waitFinished, SLOT(quit()));
|
|
84 |
loader->start();
|
|
85 |
QVERIFY(loader->isRunning());
|
|
86 |
eventLoopTimer.start();
|
|
87 |
waitFinished.exec();
|
|
88 |
|
|
89 |
QCOMPARE(finishedSpy.count(), 1);
|
|
90 |
QVERIFY(eventLoopTimer.isActive());
|
|
91 |
eventLoopTimer.stop();
|
|
92 |
|
|
93 |
QVERIFY(!loader->isRunning());
|
|
94 |
//Check that temp file is created and result is true
|
|
95 |
QVERIFY(QFile::exists(tempTestWallpaper()));
|
|
96 |
//Clear created temp file
|
|
97 |
cleanupTargetWallpaperFiles();
|
|
98 |
|
|
99 |
delete loader;
|
|
100 |
}
|
|
101 |
|
|
102 |
void TestHsDomainModel::testHsWallpaperLoaderStartWithFailed()
|
|
103 |
{
|
|
104 |
//Test preparation
|
|
105 |
cleanupTargetWallpaperFiles();
|
|
106 |
|
|
107 |
HsWallpaperLoader *loader = new HsWallpaperLoader;
|
|
108 |
QSignalSpy failedSpy(loader, SIGNAL(failed()));
|
|
109 |
|
|
110 |
//TEST START WITH ONE FAILING THREAD AND ONE SUCCESSFUL
|
|
111 |
QVERIFY(QFile::exists(sourceTestWallpaper()));
|
|
112 |
loader->setSourcePath(sourceTestWallpaper());
|
|
113 |
|
|
114 |
QVariantHash targets;
|
|
115 |
targets.insert(tempTestWallpaper(), QSize(360, 640));
|
|
116 |
targets.insert(QString(), QSize(640, 360)); //Save fails for empty string in thread
|
|
117 |
loader->setTargets(targets);
|
|
118 |
|
|
119 |
QEventLoop waitFailed;
|
|
120 |
QTimer eventLoopTimer;
|
|
121 |
eventLoopTimer.setInterval(15000);
|
|
122 |
eventLoopTimer.setSingleShot(true);
|
|
123 |
connect(loader, SIGNAL(failed()), &waitFailed, SLOT(quit()));
|
|
124 |
connect(&eventLoopTimer, SIGNAL(timeout()), &waitFailed, SLOT(quit()));
|
|
125 |
loader->start();
|
|
126 |
QVERIFY(loader->isRunning());
|
|
127 |
eventLoopTimer.start();
|
|
128 |
waitFailed.exec();
|
|
129 |
|
|
130 |
QCOMPARE(failedSpy.count(), 1);
|
|
131 |
QVERIFY(eventLoopTimer.isActive());
|
|
132 |
eventLoopTimer.stop();
|
|
133 |
|
|
134 |
QVERIFY(!loader->isRunning());
|
|
135 |
//Check that temp file is created and result is true
|
|
136 |
QVERIFY(QFile::exists(tempTestWallpaper()));
|
|
137 |
|
|
138 |
//Clear created temp file
|
|
139 |
cleanupTargetWallpaperFiles();
|
|
140 |
delete loader;
|
|
141 |
|
|
142 |
}
|
|
143 |
|
|
144 |
void TestHsDomainModel::testHsWallpaperLoaderCancel()
|
|
145 |
{
|
|
146 |
//Test preparation
|
|
147 |
cleanupTargetWallpaperFiles();
|
|
148 |
|
|
149 |
HsWallpaperLoader *loader = new HsWallpaperLoader;
|
|
150 |
QSignalSpy failedSpy(loader, SIGNAL(failed()));
|
|
151 |
QSignalSpy finishedSpy(loader, SIGNAL(finished()));
|
|
152 |
|
|
153 |
//TEST START WITH ONE FAILING THREAD AND ONE SUCCESSFUL
|
|
154 |
QVERIFY(QFile::exists(sourceTestWallpaper()));
|
|
155 |
loader->setSourcePath(sourceTestWallpaper());
|
|
156 |
|
|
157 |
QVariantHash targets;
|
|
158 |
targets.insert(tempTestWallpaper(), QSize(360, 640));
|
|
159 |
targets.insert(QString(), QSize(640, 360)); //This fails due to empty target file path.
|
|
160 |
loader->setTargets(targets);
|
|
161 |
|
|
162 |
loader->start();
|
|
163 |
QVERIFY(loader->isRunning());
|
|
164 |
loader->cancel();
|
|
165 |
QVERIFY(!loader->isRunning());
|
|
166 |
QCOMPARE(failedSpy.count(), 0);
|
|
167 |
QCOMPARE(finishedSpy.count(), 0);
|
|
168 |
|
|
169 |
//Clear temp file if it was created
|
|
170 |
cleanupTargetWallpaperFiles();
|
|
171 |
|
|
172 |
delete loader;
|
|
173 |
}
|