aboutsummaryrefslogtreecommitdiff
path: root/tests/ut_mremoteaction
diff options
context:
space:
mode:
authorTomas Junnonen <tomas.junnonen@nokia.com>2010-04-12 13:50:25 +0300
committerTomas Junnonen <tomas.junnonen@nokia.com>2010-04-12 13:52:31 +0300
commitda73676c8a5af66b55523a9cdfbfbea2baa88a2a (patch)
tree0a3b8933a1817c152116da5fa8a7b5cdd8102e60 /tests/ut_mremoteaction
parent8832674482d3b9a7fcf77b0cfdcb8e6fe4960b4d (diff)
Changes: Renamed dui to meegotouch
By: Holger, Daniel, Janne RevBy: Tomas, Holger
Diffstat (limited to 'tests/ut_mremoteaction')
-rw-r--r--tests/ut_mremoteaction/.gitignore1
-rw-r--r--tests/ut_mremoteaction/ut_mremoteaction.cpp150
-rw-r--r--tests/ut_mremoteaction/ut_mremoteaction.h56
-rw-r--r--tests/ut_mremoteaction/ut_mremoteaction.pro23
4 files changed, 230 insertions, 0 deletions
diff --git a/tests/ut_mremoteaction/.gitignore b/tests/ut_mremoteaction/.gitignore
new file mode 100644
index 00000000..f1ab6d54
--- /dev/null
+++ b/tests/ut_mremoteaction/.gitignore
@@ -0,0 +1 @@
+ut_duiremoteaction
diff --git a/tests/ut_mremoteaction/ut_mremoteaction.cpp b/tests/ut_mremoteaction/ut_mremoteaction.cpp
new file mode 100644
index 00000000..1b7091cc
--- /dev/null
+++ b/tests/ut_mremoteaction/ut_mremoteaction.cpp
@@ -0,0 +1,150 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#include "ut_mremoteaction.h"
+#include <QDBusInterface>
+#include <maction_stub.h>
+#include "maction_p.h"
+
+bool Ut_MRemoteAction::captureCalls = false;
+QString Ut_MRemoteAction::callServiceName;
+QString Ut_MRemoteAction::callObjectPath;
+QString Ut_MRemoteAction::callInterface;
+QList<QString> Ut_MRemoteAction::callMethods;
+QList< QList<QVariant> > Ut_MRemoteAction::callArguments;
+
+// MActionPrivate stubs
+MActionPrivate::MActionPrivate()
+{
+}
+
+MActionPrivate::~MActionPrivate()
+{
+}
+
+// QDBusInterface stubs (used by MRemoteAction)
+QDBusInterface::QDBusInterface(const QString &service, const QString &path, const QString &interface, const QDBusConnection &connection, QObject *parent) : QDBusAbstractInterface(service, path, interface.toUtf8().constData(), connection, parent)
+{
+ Ut_MRemoteAction::callServiceName = service;
+ Ut_MRemoteAction::callObjectPath = path;
+ Ut_MRemoteAction::callInterface = interface;
+}
+
+QDBusInterface::~QDBusInterface()
+{
+}
+
+// QDBusAbstractInterface stubs (used by MRemoteAction)
+QDBusMessage QDBusAbstractInterface::callWithArgumentList(QDBus::CallMode, const QString &method, const QList<QVariant> &args)
+{
+ if (Ut_MRemoteAction::captureCalls) {
+ Ut_MRemoteAction::callMethods.append(method);
+ Ut_MRemoteAction::callArguments.append(args);
+ }
+
+ return QDBusMessage();
+}
+
+void Ut_MRemoteAction::init()
+{
+ captureCalls = false;
+ callServiceName = QString();
+ callObjectPath = QString();
+ callInterface = QString();
+ callMethods.clear();
+ callArguments.clear();
+}
+
+void Ut_MRemoteAction::cleanup()
+{
+}
+
+void Ut_MRemoteAction::initTestCase()
+{
+}
+
+void Ut_MRemoteAction::cleanupTestCase()
+{
+}
+
+void Ut_MRemoteAction::testSerialization()
+{
+ // Create two arguments as QVariants
+ QVariant arg1("arg1");
+ QVariant arg2(2);
+
+ // Serialize the QVariants into QBuffers
+ QBuffer buffer1;
+ QBuffer buffer2;
+ buffer1.open(QIODevice::ReadWrite);
+ buffer2.open(QIODevice::ReadWrite);
+ QDataStream stream1(&buffer1);
+ QDataStream stream2(&buffer2);
+ stream1 << arg1;
+ stream2 << arg2;
+ buffer1.close();
+ buffer2.close();
+
+ // Encode the contents of the QBuffers in Base64
+ QString arg1String(buffer1.buffer().toBase64().data());
+ QString arg2String(buffer2.buffer().toBase64().data());
+
+ // Test that an empty action serializes into an empty action
+ MRemoteAction action1;
+ QCOMPARE(action1.toString(), QString());
+
+ // Test that a class deserialized from a string serializes into the same string
+ QString action2String("serviceName objectPath interface methodName ");
+ action2String.append(arg1String);
+ action2String.append(' ');
+ action2String.append(arg2String);
+ MRemoteAction action2(action2String);
+ QCOMPARE(action2.toString(), action2String);
+
+ // Test that passing the parameters separately will result in the same string
+ QList<QVariant> args;
+ args.append(arg1);
+ args.append(arg2);
+ MRemoteAction action3("serviceName", "objectPath", "interface", "methodName", args);
+ QCOMPARE(action3.toString(), action2String);
+}
+
+void Ut_MRemoteAction::testTrigger()
+{
+ // Create an action with a method call and some QVariant arguments
+ QList<QVariant> args;
+ args.append(QVariant("arg1"));
+ args.append(QVariant(2));
+ MRemoteAction action("serviceName", "objectPath", "interface", "methodName", args);
+ captureCalls = true;
+ action.trigger();
+
+ // Make sure the corrent method was called with the corrent arguments
+ QCOMPARE(callServiceName, QString("serviceName"));
+ QCOMPARE(callObjectPath, QString("objectPath"));
+ QCOMPARE(callInterface, QString("interface"));
+ QCOMPARE(callMethods.count(), 1);
+ QCOMPARE(callMethods.at(0), QString("methodName"));
+ QCOMPARE(callArguments.count(), 1);
+ QCOMPARE(callArguments.at(0).count(), 2);
+ QCOMPARE(callArguments.at(0).at(0), QVariant("arg1"));
+ QCOMPARE(callArguments.at(0).at(1), QVariant(2));
+}
+
+QTEST_MAIN(Ut_MRemoteAction)
diff --git a/tests/ut_mremoteaction/ut_mremoteaction.h b/tests/ut_mremoteaction/ut_mremoteaction.h
new file mode 100644
index 00000000..2f64c6a0
--- /dev/null
+++ b/tests/ut_mremoteaction/ut_mremoteaction.h
@@ -0,0 +1,56 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#ifndef UT_MREMOTEACTION_H
+#define UT_MREMOTEACTION_H
+
+#include <QtTest/QtTest>
+#include <QObject>
+#include <QString>
+#include <QList>
+#include <QVariant>
+
+// the real unit/MRemoteAction class declaration
+#include <mremoteaction.h>
+
+Q_DECLARE_METATYPE(MRemoteAction *);
+
+class Ut_MRemoteAction : public QObject
+{
+ Q_OBJECT
+
+public:
+ static bool captureCalls;
+ static QString callServiceName;
+ static QString callObjectPath;
+ static QString callInterface;
+ static QList<QString> callMethods;
+ static QList< QList<QVariant> > callArguments;
+
+private slots:
+ void init();
+ void cleanup();
+ void initTestCase();
+ void cleanupTestCase();
+
+ void testSerialization();
+ void testTrigger();
+};
+
+#endif
diff --git a/tests/ut_mremoteaction/ut_mremoteaction.pro b/tests/ut_mremoteaction/ut_mremoteaction.pro
new file mode 100644
index 00000000..53914b72
--- /dev/null
+++ b/tests/ut_mremoteaction/ut_mremoteaction.pro
@@ -0,0 +1,23 @@
+include(../common_top.pri)
+TARGET = ut_mremoteaction
+INCLUDEPATH += $$MSRCDIR/corelib/core
+
+TEST_SOURCES = \
+ $$MSRCDIR/corelib/core/mremoteaction.cpp \
+
+# unit test and unit
+SOURCES += \
+ ut_mremoteaction.cpp \
+ $$TEST_SOURCES \
+
+# service classes
+SOURCES += \
+ $$STUBSDIR/stubbase.cpp \
+
+# unit test and unit
+HEADERS += \
+ ut_mremoteaction.h \
+ $$MSRCDIR/corelib/core/maction.h \
+ $$MSRCDIR/corelib/core/mremoteaction.h
+
+include(../common_bot.pri)