/** * This file is part of the KDE project * Copyright (C) 2008 Kevin Ottens * * 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 #include #include #include #include #include #include #include "testhelpers.h" #ifndef DATA_DIR #error "DATA_DIR is not set. A directory containing test jolie scripts is required for this test" #endif using namespace Jolie; void dump(const Value &value, int level) { QByteArray indent; while (level>0) { indent+=" "; level--; } qDebug() << (indent+value.toByteArray()) << value.toInt() << value.toDouble(); foreach (const QByteArray &name, value.childrenNames()) { QList children = value.children(name); qDebug() << (indent+"Children:") << name; foreach (const Value &child, children) { dump(child, level+1); } } } void dump(const Message &message) { qDebug() << "Resource :" << message.resourcePath(); qDebug() << "Operation:" << message.operationName(); qDebug() << "Fault :" << message.fault().name(); dump(message.fault().data(), 1); qDebug() << "Value :"; dump(message.data(), 1); } class TestMetaService : public QObject { Q_OBJECT MetaService m_metaService; Client *m_client; public: TestMetaService() : QObject() { qRegisterMetaType(); } private slots: void initTestCase() { QVERIFY2(m_metaService.start(), "Looks like you don't have Jolie's metaservice command"); QTest::qWait(1000); m_client = new Client(QString::fromUtf8("localhost"), 9000); } void cleanupTestCase() { delete m_client; QVERIFY(m_metaService.stop()); } void shouldLoadService_data() { QTest::addColumn("resourcePrefix"); QTest::addColumn("fileName"); QTest::newRow("printer service") << QString::fromUtf8("Printer") << QString::fromUtf8("printer.ol"); QTest::newRow("math service") << QString::fromUtf8("Math") << QString::fromUtf8("math.ol"); } void shouldLoadService() { QFETCH(QString, resourcePrefix); QFETCH(QString, fileName); QCOMPARE(m_metaService.loadService(resourcePrefix, QString::fromUtf8(DATA_DIR"/")+fileName), resourcePrefix); } void shouldListServices() { QStringList expected; expected << QString::fromUtf8("Math") << QString::fromUtf8("Printer"); QCOMPARE(m_metaService.loadedServices(), expected); } void shouldPlaceServiceCalls_data() { QTest::addColumn("path"); QTest::addColumn("method"); QTest::addColumn("data"); QTest::addColumn("replyData"); 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); } void shouldPlaceServiceCalls() { QFETCH(QByteArray, path); QFETCH(QByteArray, method); QFETCH(Value, data); QFETCH(Value, replyData); Message message(path, method); message.setData(data); Message reply = m_client->call(message); Message expected("/", method); expected.setData(replyData); sodepCompare(reply, expected); } void shouldUnloadService_data() { QTest::addColumn("serviceName"); QTest::newRow("printer service") << QString::fromUtf8("PrinterService"); QTest::newRow("math service") << QString::fromUtf8("MathService"); } void shouldUnloadService() { QFETCH(QString, serviceName); m_metaService.unloadService(serviceName); } }; QTEST_MAIN(TestMetaService) #include "testmetaservice.moc"