2009-02-07 17:30:58 +01:00
|
|
|
/**
|
|
|
|
* This file is part of the KDE project
|
|
|
|
* Copyright (C) 2008 Kevin Ottens <ervin@kde.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public License
|
|
|
|
* along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QtCore/QObject>
|
|
|
|
#include <QtCore/QProcess>
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
2009-04-25 16:06:25 +02:00
|
|
|
#include <QtJolie/Client>
|
|
|
|
#include <QtJolie/Message>
|
2009-05-08 10:23:59 +02:00
|
|
|
#include <QtJolie/MetaService>
|
2009-04-25 16:06:25 +02:00
|
|
|
#include <QtJolie/PendingCall>
|
2009-04-25 15:50:35 +02:00
|
|
|
#include "testhelpers.h"
|
2009-02-07 17:30:58 +01:00
|
|
|
|
|
|
|
#ifndef DATA_DIR
|
|
|
|
#error "DATA_DIR is not set. A directory containing test jolie scripts is required for this test"
|
|
|
|
#endif
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
using namespace Jolie;
|
2009-02-07 17:30:58 +01:00
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
class TestMetaService : public QObject
|
2009-02-07 17:30:58 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2009-05-08 10:23:59 +02:00
|
|
|
MetaService m_metaService;
|
2009-04-25 15:50:35 +02:00
|
|
|
Client *m_client;
|
2009-02-08 23:11:14 +01:00
|
|
|
|
|
|
|
public:
|
2009-04-25 15:50:35 +02:00
|
|
|
TestMetaService()
|
2009-04-13 14:39:26 +02:00
|
|
|
: QObject()
|
2009-02-08 23:11:14 +01:00
|
|
|
{
|
|
|
|
}
|
2009-02-07 17:30:58 +01:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase()
|
|
|
|
{
|
2009-05-08 10:23:59 +02:00
|
|
|
QVERIFY2(m_metaService.start(), "Looks like you don't have Jolie's metaservice command");
|
2009-02-07 17:30:58 +01:00
|
|
|
QTest::qWait(1000);
|
2009-02-08 22:12:45 +01:00
|
|
|
|
2009-05-30 10:44:34 +02:00
|
|
|
m_client = new Client(QString::fromUtf8("localhost"), 9000);
|
2009-02-07 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cleanupTestCase()
|
|
|
|
{
|
2009-04-25 14:26:01 +02:00
|
|
|
delete m_client;
|
2009-05-08 10:23:59 +02:00
|
|
|
QVERIFY(m_metaService.stop());
|
2009-02-07 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void shouldLoadService_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("resourcePrefix");
|
|
|
|
QTest::addColumn<QString>("fileName");
|
|
|
|
|
2009-05-30 10:44:34 +02:00
|
|
|
QTest::newRow("printer service") << QString::fromUtf8("Printer") << QString::fromUtf8("printer.ol");
|
|
|
|
QTest::newRow("math service") << QString::fromUtf8("Math") << QString::fromUtf8("math.ol");
|
2009-02-07 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void shouldLoadService()
|
|
|
|
{
|
|
|
|
QFETCH(QString, resourcePrefix);
|
|
|
|
QFETCH(QString, fileName);
|
|
|
|
|
2009-05-30 10:44:34 +02:00
|
|
|
QCOMPARE(m_metaService.loadService(resourcePrefix, QString::fromUtf8(DATA_DIR"/")+fileName),
|
2009-05-08 10:23:59 +02:00
|
|
|
resourcePrefix);
|
2009-02-07 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void shouldListServices()
|
|
|
|
{
|
2009-05-08 10:23:59 +02:00
|
|
|
QStringList expected;
|
2009-05-30 10:44:34 +02:00
|
|
|
expected << QString::fromUtf8("Math") << QString::fromUtf8("Printer");
|
2009-05-08 10:23:59 +02:00
|
|
|
QCOMPARE(m_metaService.loadedServices(), expected);
|
2009-02-07 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void shouldPlaceServiceCalls_data()
|
|
|
|
{
|
2009-05-30 10:44:34 +02:00
|
|
|
QTest::addColumn<QByteArray>("path");
|
|
|
|
QTest::addColumn<QByteArray>("method");
|
2009-04-25 15:50:35 +02:00
|
|
|
QTest::addColumn<Value>("data");
|
|
|
|
QTest::addColumn<Value>("replyData");
|
2009-02-07 17:30:58 +01:00
|
|
|
|
2009-05-30 10:44:34 +02:00
|
|
|
QTest::newRow("printer service") << QByteArray("/Printer") << QByteArray("printInput") << Value("Patapatapon!") << Value("success");
|
|
|
|
QTest::newRow("math service") << QByteArray("/Math") << QByteArray("twice") << Value(10.5) << Value(21.0);
|
2009-02-07 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void shouldPlaceServiceCalls()
|
|
|
|
{
|
2009-05-30 10:44:34 +02:00
|
|
|
QFETCH(QByteArray, path);
|
|
|
|
QFETCH(QByteArray, method);
|
2009-04-25 15:50:35 +02:00
|
|
|
QFETCH(Value, data);
|
|
|
|
QFETCH(Value, replyData);
|
2009-02-07 17:30:58 +01:00
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Message message(path, method);
|
2009-02-07 17:30:58 +01:00
|
|
|
message.setData(data);
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Message reply = m_client->call(message);
|
2009-02-07 17:30:58 +01:00
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Message expected("/", method);
|
2009-02-07 17:30:58 +01:00
|
|
|
expected.setData(replyData);
|
|
|
|
|
|
|
|
sodepCompare(reply, expected);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shouldUnloadService_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QString>("serviceName");
|
|
|
|
|
2009-05-30 10:44:34 +02:00
|
|
|
QTest::newRow("printer service") << QString::fromUtf8("PrinterService");
|
|
|
|
QTest::newRow("math service") << QString::fromUtf8("MathService");
|
2009-02-07 17:30:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void shouldUnloadService()
|
|
|
|
{
|
|
|
|
QFETCH(QString, serviceName);
|
|
|
|
|
2009-05-08 10:23:59 +02:00
|
|
|
m_metaService.unloadService(serviceName);
|
2009-02-07 17:30:58 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
QTEST_MAIN(TestMetaService)
|
2009-02-07 17:30:58 +01:00
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
#include "testmetaservice.moc"
|