Provide a more complete automated test which basically does the

following:
 - starts metaservice
 - loads two services
 - call them and check the replies
 - unloads the services
 - stop metaservice

CCMAIL: aseigo@kde.org

svn path=/branches/work/~ervin/sodep/; revision=922830
This commit is contained in:
Kevin Ottens 2009-02-07 16:30:58 +00:00
parent c232abcc72
commit 54e28db2cd
3 changed files with 278 additions and 0 deletions

View File

@ -0,0 +1,28 @@
include_directories(${KDE4_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../sodep)
MACRO(SODEP_UNIT_TESTS)
FOREACH(_testname ${ARGN})
kde4_add_unit_test(${_testname} NOGUI ${_testname}.cpp)
target_link_libraries(${_testname} ${QT_QTCORE_LIBRARY} ${QT_QTTEST_LIBRARY} ${QT_QTNETWORK_LIBRARY} sodep)
add_definitions(-DDATA_DIR="\\"${CMAKE_CURRENT_SOURCE_DIR}\\"")
ENDFOREACH(_testname)
ENDMACRO(SODEP_UNIT_TESTS)
MACRO(SODEP_EXECUTABLE_TESTS)
FOREACH(_testname ${ARGN})
kde4_add_executable(${_testname} NOGUI TEST ${_testname}.cpp)
target_link_libraries(${_testname} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTNETWORK_LIBRARY} sodep)
add_definitions(-DDATA_DIR="\\"${CMAKE_CURRENT_SOURCE_DIR}\\"")
ENDFOREACH(_testname)
ENDMACRO(SODEP_EXECUTABLE_TESTS)
SODEP_UNIT_TESTS(
sodepvaluetest
sodepfaulttest
sodepmessagetest
sodepmetaservicetest
)
SODEP_EXECUTABLE_TESTS(
sodepprintertest
)

View File

@ -0,0 +1,15 @@
inputPort MathService {
Location: "socket://localhost:11000"
Protocol: sodep
RequestResponse:
twice
}
main
{
twice(number)(result) {
result = number * 2
}
}

View File

@ -0,0 +1,235 @@
/**
* 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 <QtNetwork/QTcpSocket>
#include <QtTest/QtTest>
#include <sodepmessage.h>
#include "sodeptesthelpers.h"
#ifndef DATA_DIR
#error "DATA_DIR is not set. A directory containing test jolie scripts is required for this test"
#endif
void dump(const SodepValue &value, int level)
{
QString indent;
while (level>0) {
indent+=" ";
level--;
}
qDebug() << (indent+value.toString()) << value.toInt() << value.toDouble();
foreach (const QString &name, value.childrenNames()) {
QList<SodepValue> children = value.children(name);
qDebug() << (indent+"Children:") << name;
foreach (const SodepValue &child, children) {
dump(child, level+1);
}
}
}
void dump(const SodepMessage &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 SodepMetaServiceTest : public QObject
{
Q_OBJECT
QProcess metaserviceProcess;
private slots:
void initTestCase()
{
metaserviceProcess.start("metaservice");
QVERIFY2(metaserviceProcess.waitForStarted(), "Looks like you don't have Jolie's metaservice command");
QTest::qWait(1000);
}
void cleanupTestCase()
{
QTcpSocket m_socket;
m_socket.connectToHost("localhost", 9000);
QVERIFY(m_socket.waitForConnected(5000));
SodepMessage message("/", "shutdown");
message.writeTo(m_socket);
QTest::qWait(1000);
metaserviceProcess.waitForFinished();
}
void shouldLoadService_data()
{
QTest::addColumn<QString>("resourcePrefix");
QTest::addColumn<QString>("fileName");
QTest::newRow("printer service") << "Printer" << "printer.ol";
QTest::newRow("math service") << "Math" << "math.ol";
}
void shouldLoadService()
{
QFETCH(QString, resourcePrefix);
QFETCH(QString, fileName);
QTcpSocket m_socket;
m_socket.connectToHost("localhost", 9000);
QVERIFY(m_socket.waitForConnected(5000));
SodepMessage message("/", "loadEmbeddedJolieService");
SodepValue value(0);
value.children("resourcePrefix") << SodepValue(resourcePrefix);
value.children("filepath") << SodepValue(QString(DATA_DIR"/")+fileName);
message.setData(value);
message.writeTo(m_socket);
QVERIFY(m_socket.waitForReadyRead(5000));
QTest::qWait(1000);
SodepMessage reply = SodepMessage::readFrom(m_socket);
m_socket.close();
SodepMessage expected("/", "loadEmbeddedJolieService");
expected.setData(SodepValue(resourcePrefix));
sodepCompare(reply, expected);
}
void shouldListServices()
{
QTcpSocket m_socket;
m_socket.connectToHost("localhost", 9000);
QVERIFY(m_socket.waitForConnected(5000));
SodepMessage message("/", "getServices");
message.writeTo(m_socket);
QVERIFY(m_socket.waitForReadyRead(5000));
QTest::qWait(1000);
SodepMessage reply = SodepMessage::readFrom(m_socket);
m_socket.close();
SodepMessage expected("/", "getServices");
SodepValue value;
SodepValue s1;
s1.children("metadata");
s1.children("resourceName") << SodepValue("Math");
SodepValue s2;
s2.children("metadata");
s2.children("resourceName") << SodepValue("Printer");
value.children("service") << s1 << s2;
expected.setData(value);
sodepCompare(reply, expected);
}
void shouldPlaceServiceCalls_data()
{
QTest::addColumn<int>("port");
QTest::addColumn<QString>("method");
QTest::addColumn<SodepValue>("data");
QTest::addColumn<SodepValue>("replyData");
QTest::newRow("printer service") << 10000 << "printInput" << SodepValue("Patapatapon!") << SodepValue("success");
QTest::newRow("math service") << 11000 << "twice" << SodepValue(10.5) << SodepValue(21.0);
}
void shouldPlaceServiceCalls()
{
QFETCH(int, port);
QFETCH(QString, method);
QFETCH(SodepValue, data);
QFETCH(SodepValue, replyData);
QTcpSocket m_socket;
m_socket.connectToHost("localhost", port);
QVERIFY(m_socket.waitForConnected(5000));
SodepMessage message("/", method);
message.setData(data);
message.writeTo(m_socket);
QVERIFY(m_socket.waitForReadyRead(5000));
QTest::qWait(1000);
SodepMessage reply = SodepMessage::readFrom(m_socket);
m_socket.close();
SodepMessage expected("/", method);
expected.setData(replyData);
sodepCompare(reply, expected);
}
void shouldUnloadService_data()
{
QTest::addColumn<QString>("serviceName");
QTest::newRow("printer service") << "PrinterService";
QTest::newRow("math service") << "MathService";
}
void shouldUnloadService()
{
QFETCH(QString, serviceName);
QTcpSocket m_socket;
m_socket.connectToHost("localhost", 9000);
QVERIFY(m_socket.waitForConnected(5000));
SodepMessage message("/", "unloadEmbeddedService");
SodepValue value(serviceName);
message.setData(value);
message.writeTo(m_socket);
QVERIFY(m_socket.waitForReadyRead(5000));
QTest::qWait(1000);
SodepMessage reply = SodepMessage::readFrom(m_socket);
m_socket.close();
SodepMessage expected("/", "unloadEmbeddedService");
sodepCompare(reply, expected);
}
};
QTEST_MAIN(SodepMetaServiceTest)
#include "sodepmetaservicetest.moc"