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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <QtGui> |
|
19 #include <QtTest/QtTest> |
|
20 #include <QDebug> |
|
21 #include <QIcon> |
|
22 #include <QSignalSpy> |
|
23 #include <e32cmn.h> //KNullDesC |
|
24 #include "mobcnticonmanager.h" |
|
25 #include "ut_mobcnticonmanager.h" |
|
26 |
|
27 const int WAIT_TIME1 = 500; |
|
28 const int WAIT_TIME2 = 900; |
|
29 const QString path1 = "c:\\data\\images\\image1.png"; |
|
30 const QString path2 = "c:\\data\\images\\image2.png"; |
|
31 const QString path3 = "e:\\images\\non.jpeg"; |
|
32 |
|
33 void TestMobCntIconManager::initTestCase() |
|
34 { |
|
35 mIconMgr = new MobCntIconManager(); |
|
36 } |
|
37 |
|
38 void TestMobCntIconManager::cleanupTestCase() |
|
39 { |
|
40 delete mIconMgr; |
|
41 mIconMgr = 0; |
|
42 } |
|
43 |
|
44 void TestMobCntIconManager::init() |
|
45 { |
|
46 initTestCase(); |
|
47 } |
|
48 |
|
49 void TestMobCntIconManager::cleanup() |
|
50 { |
|
51 cleanupTestCase(); |
|
52 } |
|
53 |
|
54 void TestMobCntIconManager::testNonExistingIcon() |
|
55 { |
|
56 QSignalSpy spy(mIconMgr, SIGNAL(contactIconReady(int))); |
|
57 Q_ASSERT(spy.isValid()); |
|
58 QCOMPARE( spy.count(), 0 ); |
|
59 mIcon = mIconMgr->contactIcon(path3, 0); |
|
60 Q_ASSERT(mIcon.isNull()); |
|
61 QTest::qWait( WAIT_TIME1 ); |
|
62 QCOMPARE(spy.count(), 0); |
|
63 } |
|
64 |
|
65 void TestMobCntIconManager::testOneExistingIcon() |
|
66 { |
|
67 QSignalSpy spy(mIconMgr, SIGNAL(contactIconReady(int))); |
|
68 Q_ASSERT(spy.isValid()); |
|
69 QCOMPARE( spy.count(), 0 ); |
|
70 mIcon = mIconMgr->contactIcon(path1, 10); |
|
71 Q_ASSERT(mIcon.isNull()); |
|
72 QTest::qWait( WAIT_TIME1 ); |
|
73 QCOMPARE(spy.count(), 1); |
|
74 QList<QVariant> arguments = spy.takeFirst(); |
|
75 QVERIFY(arguments.at(0).toInt() == 10); |
|
76 mIcon = mIconMgr->contactIcon(path1, 10); |
|
77 Q_ASSERT(!mIcon.isNull()); |
|
78 } |
|
79 |
|
80 void TestMobCntIconManager::testCancel() |
|
81 { |
|
82 QSignalSpy spy(mIconMgr, SIGNAL(contactIconReady(int))); |
|
83 Q_ASSERT(spy.isValid()); |
|
84 QCOMPARE( spy.count(), 0 ); |
|
85 mIcon = mIconMgr->contactIcon(path1, 10); |
|
86 Q_ASSERT(mIcon.isNull()); |
|
87 mIcon = mIconMgr->contactIcon(path2, 11); |
|
88 Q_ASSERT(mIcon.isNull()); |
|
89 mIcon = mIconMgr->contactIcon(path3, 0); |
|
90 Q_ASSERT(mIcon.isNull()); |
|
91 mIconMgr->thumbnailLoad(); |
|
92 mIconMgr->cancel(); |
|
93 QCOMPARE(spy.count(), 0); |
|
94 } |
|
95 |
|
96 void TestMobCntIconManager::testMultipleExistingIcon() |
|
97 { |
|
98 QSignalSpy spy(mIconMgr, SIGNAL(contactIconReady(int))); |
|
99 Q_ASSERT(spy.isValid()); |
|
100 QCOMPARE( spy.count(), 0 ); |
|
101 QIcon icon1; |
|
102 QIcon icon2; |
|
103 icon1 = mIconMgr->contactIcon(path1, 10); |
|
104 Q_ASSERT(icon1.isNull()); |
|
105 icon2 = mIconMgr->contactIcon(path2, 11); |
|
106 Q_ASSERT(icon2.isNull()); |
|
107 QTest::qWait( WAIT_TIME2); |
|
108 qDebug()<<spy.count(); |
|
109 QCOMPARE(spy.count(), 2); |
|
110 QList<QVariant> arguments = spy.takeFirst(); |
|
111 qDebug()<< arguments.at(0).toInt(); |
|
112 QVERIFY(arguments.at(0).toInt() == 10); |
|
113 arguments = spy.takeLast(); |
|
114 qDebug()<< arguments.at(0).toInt(); |
|
115 QVERIFY(arguments.at(0).toInt() == 11 ); |
|
116 mIcon = mIconMgr->contactIcon(path1, 10); |
|
117 Q_ASSERT(!mIcon.isNull()); |
|
118 mIcon = mIcon = mIconMgr->contactIcon(path2, 11); |
|
119 Q_ASSERT(!mIcon.isNull()); |
|
120 } |
|
121 |
|