|
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 "unittest_activityserviceplugin.h" |
|
19 |
|
20 #include <QtTest/QtTest> |
|
21 #include <QScopedPointer> |
|
22 #include <QDebug> |
|
23 |
|
24 #include <qservicemanager.h> |
|
25 |
|
26 #include <afstorageglobals.h> |
|
27 |
|
28 #include <tstestutils.h> |
|
29 |
|
30 void TestActivityServicePlugin::initTestCase() |
|
31 { |
|
32 QServiceManager manager; |
|
33 if (!manager.findServices().contains("ActivityService")) { |
|
34 qDebug() << "ActivityService not found"; |
|
35 QVERIFY(QFile::exists(":/activityserviceplugin.xml")); |
|
36 if (!manager.addService(":/activityserviceplugin.xml")) { |
|
37 QFAIL(qPrintable(QString("Failed to add ActivityService: %1").arg(manager.error()))); |
|
38 } |
|
39 QVERIFY(manager.findServices().contains("ActivityService")); |
|
40 } |
|
41 } |
|
42 |
|
43 void TestActivityServicePlugin::testActivityClientCreation() |
|
44 { |
|
45 QServiceManager manager; |
|
46 QObject *activityClient = manager.loadInterface("com.nokia.qt.activities.ActivityClient"); |
|
47 if (!activityClient) qDebug() << "error:" << manager.error(); |
|
48 QVERIFY(activityClient); |
|
49 QCOMPARE(activityClient->metaObject()->className(), "AfClient"); |
|
50 delete activityClient; |
|
51 } |
|
52 |
|
53 void TestActivityServicePlugin::testActivityManagerCreation() |
|
54 { |
|
55 QServiceManager manager; |
|
56 QObject *activityManager = manager.loadInterface("com.nokia.qt.activities.ActivityManager"); |
|
57 if (!activityManager) qDebug() << "error:" << manager.error(); |
|
58 QVERIFY(activityManager); |
|
59 QCOMPARE(activityManager->metaObject()->className(), "AfManager"); |
|
60 delete activityManager; |
|
61 } |
|
62 |
|
63 void TestActivityServicePlugin::testInvalidInterfaceCreation() |
|
64 { |
|
65 QServiceManager manager; |
|
66 QObject *invalidInterface = manager.loadInterface("com.nokia.qt.activities.BlahBlahBlah"); |
|
67 QVERIFY(!invalidInterface); |
|
68 } |
|
69 |
|
70 void TestActivityServicePlugin::testActivityManagerEmitsDataChangeSignalAfterSavingThroughStorage() |
|
71 { |
|
72 QServiceManager manager; |
|
73 QScopedPointer<QObject> activityManager(manager.loadInterface("com.nokia.qt.activities.ActivityManager")); |
|
74 QVERIFY(activityManager.data()); |
|
75 |
|
76 QScopedPointer<QObject> activityStorage(manager.loadInterface("com.nokia.qt.activities.Storage")); |
|
77 QVERIFY(activityStorage.data()); |
|
78 |
|
79 QSignalSpy dataChangedSpy(activityManager.data(), SIGNAL(dataChanged())); |
|
80 QVERIFY(dataChangedSpy.isValid()); |
|
81 QCOMPARE(dataChangedSpy.count(), 0); |
|
82 |
|
83 { |
|
84 QPixmap screenshot(128, 128); |
|
85 screenshot.fill(Qt::red); |
|
86 QVERIFY(!screenshot.isNull()); |
|
87 QVariantHash metadata; |
|
88 metadata.insert(ActivityScreenshotKeyword, screenshot); |
|
89 |
|
90 bool invokeResult; |
|
91 bool saveResult; |
|
92 invokeResult = QMetaObject::invokeMethod( |
|
93 activityStorage.data(), |
|
94 "saveActivity", |
|
95 Q_RETURN_ARG(bool, saveResult), |
|
96 Q_ARG(QString, "Test"), |
|
97 Q_ARG(QVariant, "TestData"), |
|
98 Q_ARG(QVariantHash, metadata)); |
|
99 |
|
100 QVERIFY(invokeResult); |
|
101 QVERIFY(saveResult); |
|
102 } |
|
103 |
|
104 QVERIFY(dataChangedSpy.count() > 0 || TsTestUtils::waitForSignal(activityManager.data(), SIGNAL(dataChanged()), 1500)); |
|
105 } |