Kill the public Sodep class prefix. Now use a Jolie namespace.

svn path=/branches/work/~ervin/qtjolie/; revision=959030
This commit is contained in:
Kevin Ottens 2009-04-25 13:50:35 +00:00
parent cac82a3792
commit e3a59c40e2
23 changed files with 442 additions and 358 deletions

View File

@ -4,7 +4,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${QT_INCLUDE_DIR}) ${QT_INCLUDE_DIR})
set(qtjolie_LIB_SRCS sodepclient.cpp sodepclientthread.cpp sodepvalue.cpp sodepfault.cpp sodepmessage.cpp sodeppendingcall.cpp) set(qtjolie_LIB_SRCS client.cpp clientthread.cpp value.cpp fault.cpp message.cpp pendingcall.cpp)
kde4_add_library(QtJolie SHARED ${qtjolie_LIB_SRCS}) kde4_add_library(QtJolie SHARED ${qtjolie_LIB_SRCS})
@ -16,9 +16,9 @@ install(TARGETS QtJolie
set_target_properties(QtJolie PROPERTIES VERSION 1.0.0 SOVERSION 1) set_target_properties(QtJolie PROPERTIES VERSION 1.0.0 SOVERSION 1)
install(FILES install(FILES
sodepclient.h client.h
sodepvalue.h value.h
sodepfault.h fault.h
sodepmessage.h message.h
sodeppendingcall.h pendingcall.h
DESTINATION ${INCLUDE_INSTALL_DIR}) DESTINATION ${INCLUDE_INSTALL_DIR}/qtjolie)

View File

@ -18,59 +18,61 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include "sodepclient.h" #include "client.h"
#include "sodepclient_p.h" #include "client_p.h"
#include "sodepclientthread_p.h" #include "clientthread_p.h"
#include "sodepmessage.h" #include "message.h"
#include "sodeppendingcall.h" #include "pendingcall.h"
using namespace Jolie;
SodepClient::SodepClient(const QString &hostName, quint16 port) Client::Client(const QString &hostName, quint16 port)
: d(new SodepClientPrivate(this)) : d(new ClientPrivate(this))
{ {
d->readerThread = new SodepClientThread(hostName, port, d); d->readerThread = new ClientThread(hostName, port, d);
d->readerThread->start(); d->readerThread->start();
} }
SodepClient::~SodepClient() Client::~Client()
{ {
delete d->readerThread; delete d->readerThread;
delete d; delete d;
} }
SodepClient::Error SodepClient::error() const Client::Error Client::error() const
{ {
return d->error; return d->error;
} }
QString SodepClient::errorString() const QString Client::errorString() const
{ {
return d->errorString; return d->errorString;
} }
SodepPendingCall SodepClient::asyncCall(const SodepMessage &message) PendingCall Client::asyncCall(const Message &message)
{ {
Q_ASSERT(!d->pendingCalls.contains(message.id())); Q_ASSERT(!d->pendingCalls.contains(message.id()));
d->pendingCalls[message.id()] = new SodepPendingCallPrivate(message); d->pendingCalls[message.id()] = new PendingCallPrivate(message);
d->readerThread->sendMessage(message); d->readerThread->sendMessage(message);
return SodepPendingCall(d->pendingCalls[message.id()]); return PendingCall(d->pendingCalls[message.id()]);
} }
SodepMessage SodepClient::call(const SodepMessage &message) Message Client::call(const Message &message)
{ {
SodepPendingCall pending = asyncCall(message); PendingCall pending = asyncCall(message);
pending.waitForFinished(); pending.waitForFinished();
return pending.reply(); return pending.reply();
} }
void SodepClient::callNoReply(const SodepMessage &message) void Client::callNoReply(const Message &message)
{ {
d->readerThread->sendMessage(message); d->readerThread->sendMessage(message);
} }
void SodepClientPrivate::messageReceived(const SodepMessage &message) void ClientPrivate::messageReceived(const Message &message)
{ {
QExplicitlySharedDataPointer<SodepPendingCallPrivate> pending = pendingCalls.take(message.id()); QExplicitlySharedDataPointer<PendingCallPrivate> pending = pendingCalls.take(message.id());
pending->setReply(message); pending->setReply(message);
} }

View File

@ -18,19 +18,21 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef SODEPCLIENT_H #ifndef QTJOLIE_CLIENT_H
#define SODEPCLIENT_H #define QTJOLIE_CLIENT_H
#include <QtCore/QtGlobal> #include <QtCore/QtGlobal>
class QIODevice; class QIODevice;
class QObject; class QObject;
class SodepClientPrivate; namespace Jolie
class SodepMessage; {
class SodepPendingCall; class ClientPrivate;
class Message;
class PendingCall;
class Q_DECL_EXPORT SodepClient class Q_DECL_EXPORT Client
{ {
public: public:
enum Error enum Error
@ -40,19 +42,22 @@ public:
UnkownError UnkownError
}; };
explicit SodepClient(const QString &hostName, quint16 port); explicit Client(const QString &hostName, quint16 port);
~SodepClient(); ~Client();
Error error() const; Error error() const;
QString errorString() const; QString errorString() const;
SodepPendingCall asyncCall(const SodepMessage &message); PendingCall asyncCall(const Message &message);
SodepMessage call(const SodepMessage &message); Message call(const Message &message);
void callNoReply(const SodepMessage &message); void callNoReply(const Message &message);
private: private:
friend class SodepClientPrivate; friend class ClientPrivate;
SodepClientPrivate * const d; ClientPrivate * const d;
}; };
} // namespace Jolie
#endif #endif

View File

@ -18,36 +18,42 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef SODEPCLIENT_P_H #ifndef QTJOLIE_CLIENT_P_H
#define SODEPCLIENT_P_H #define QTJOLIE_CLIENT_P_H
#include "sodepclient.h" #include "client.h"
#include "sodeppendingcall_p.h" #include "pendingcall_p.h"
#include <QtCore/QMap> #include <QtCore/QMap>
#include <QtCore/QObject> #include <QtCore/QObject>
class SodepClientThread; namespace Jolie
{
class SodepClientPrivate : public QObject class ClientThread;
class ClientPrivate : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
SodepClientPrivate(SodepClient *client) ClientPrivate(Client *client)
: q(client), : q(client),
error(SodepClient::NoError) {} error(Client::NoError) {}
public slots: public slots:
void messageReceived(const SodepMessage &message); void messageReceived(const Jolie::Message &message);
private: private:
friend class SodepClient; friend class Client;
SodepClient * const q; Client * const q;
SodepClientThread *readerThread; ClientThread *readerThread;
SodepClient::Error error; Client::Error error;
QString errorString; QString errorString;
QMap<int, QExplicitlySharedDataPointer<SodepPendingCallPrivate> > pendingCalls; QMap<int, QExplicitlySharedDataPointer<PendingCallPrivate> > pendingCalls;
}; };
} // namespace Jolie
#endif #endif

View File

@ -18,28 +18,30 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include "sodepclientthread_p.h" #include "clientthread_p.h"
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtNetwork/QTcpSocket> #include <QtNetwork/QTcpSocket>
#include "sodepclient_p.h" #include "client_p.h"
#include "sodepmessage.h" #include "message.h"
#include "sodephelpers_p.h" #include "sodephelpers_p.h"
SodepClientThread::SodepClientThread(const QString &hostName, quint16 port, SodepClientPrivate *client) using namespace Jolie;
ClientThread::ClientThread(const QString &hostName, quint16 port, ClientPrivate *client)
: QThread(), m_hostName(hostName), m_port(port), m_socket(0), m_client(client) : QThread(), m_hostName(hostName), m_port(port), m_socket(0), m_client(client)
{ {
moveToThread(this); moveToThread(this);
} }
SodepClientThread::~SodepClientThread() ClientThread::~ClientThread()
{ {
quit(); quit();
wait(); wait();
} }
void SodepClientThread::sendMessage(const SodepMessage &message) void ClientThread::sendMessage(const Message &message)
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
@ -47,7 +49,7 @@ void SodepClientThread::sendMessage(const SodepMessage &message)
QTimer::singleShot(0, this, SLOT(writeMessageQueue())); QTimer::singleShot(0, this, SLOT(writeMessageQueue()));
} }
void SodepClientThread::writeMessageQueue() void ClientThread::writeMessageQueue()
{ {
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
@ -56,13 +58,13 @@ void SodepClientThread::writeMessageQueue()
} }
} }
void SodepClientThread::readMessage() void ClientThread::readMessage()
{ {
if (m_socket->bytesAvailable()==0) { if (m_socket->bytesAvailable()==0) {
return; return;
} }
SodepMessage message = sodepReadMessage(*m_socket); Message message = sodepReadMessage(*m_socket);
emit messageReceived(message); emit messageReceived(message);
if (m_socket->bytesAvailable()>0) { if (m_socket->bytesAvailable()>0) {
@ -70,14 +72,14 @@ void SodepClientThread::readMessage()
} }
} }
void SodepClientThread::run() void ClientThread::run()
{ {
m_socket = new QTcpSocket; m_socket = new QTcpSocket;
connect(m_socket, SIGNAL(readyRead()), connect(m_socket, SIGNAL(readyRead()),
this, SLOT(readMessage()), Qt::QueuedConnection); this, SLOT(readMessage()), Qt::QueuedConnection);
connect(this, SIGNAL(messageReceived(SodepMessage)), connect(this, SIGNAL(messageReceived(Jolie::Message)),
m_client, SLOT(messageReceived(SodepMessage))); m_client, SLOT(messageReceived(Jolie::Message)));
m_socket->connectToHost(m_hostName, m_port); m_socket->connectToHost(m_hostName, m_port);
m_socket->waitForConnected(30000); m_socket->waitForConnected(30000);
@ -89,4 +91,4 @@ void SodepClientThread::run()
delete m_socket; delete m_socket;
} }
#include "sodepclientthread_p.moc" #include "clientthread_p.moc"

View File

@ -18,8 +18,8 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef SODEPCLIENTTHREAD_P_H #ifndef QTJOLIE_CLIENTTHREAD_P_H
#define SODEPCLIENTTHREAD_P_H #define QTJOLIE_CLIENTTHREAD_P_H
#include <QtCore/QThread> #include <QtCore/QThread>
#include <QtCore/QMutex> #include <QtCore/QMutex>
@ -27,23 +27,25 @@
class QAbstractSocket; class QAbstractSocket;
class SodepMessage; namespace Jolie
class SodepClientPrivate; {
class Message;
class ClientPrivate;
class SodepClientThread : public QThread class ClientThread : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SodepClientThread(const QString &hostName, quint16 port, SodepClientPrivate *client); explicit ClientThread(const QString &hostName, quint16 port, ClientPrivate *client);
~SodepClientThread(); ~ClientThread();
void run(); void run();
void sendMessage(const SodepMessage &message); void sendMessage(const Message &message);
signals: signals:
void messageReceived(const SodepMessage &message); void messageReceived(const Jolie::Message &message);
private slots: private slots:
void readMessage(); void readMessage();
@ -54,11 +56,14 @@ private:
quint16 m_port; quint16 m_port;
QAbstractSocket *m_socket; QAbstractSocket *m_socket;
SodepClientPrivate *m_client; ClientPrivate *m_client;
QQueue<SodepMessage> m_messageQueue; QQueue<Message> m_messageQueue;
QMutex m_mutex; QMutex m_mutex;
}; };
} // namespace Jolie
#endif #endif

View File

@ -18,61 +18,68 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include "sodepfault.h" #include "fault.h"
#include <QtCore/QString> #include <QtCore/QString>
#include "sodephelpers_p.h" #include "sodephelpers_p.h"
class SodepFaultPrivate namespace Jolie
{
class FaultPrivate
{ {
public: public:
QString name; QString name;
SodepValue data; Value data;
}; };
SodepFault::SodepFault() } // namespace Jolie
: d(new SodepFaultPrivate)
using namespace Jolie;
Fault::Fault()
: d(new FaultPrivate)
{ {
} }
SodepFault::SodepFault(const QString &name, const SodepValue &data) Fault::Fault(const QString &name, const Value &data)
: d(new SodepFaultPrivate) : d(new FaultPrivate)
{ {
d->name = name; d->name = name;
d->data = data; d->data = data;
} }
SodepFault::SodepFault(const SodepFault &other) Fault::Fault(const Fault &other)
: d(new SodepFaultPrivate) : d(new FaultPrivate)
{ {
*d = *other.d; *d = *other.d;
} }
SodepFault::~SodepFault() Fault::~Fault()
{ {
delete d; delete d;
} }
SodepFault &SodepFault::operator=(const SodepFault &other) Fault &Fault::operator=(const Fault &other)
{ {
*d = *other.d; *d = *other.d;
return *this; return *this;
} }
QString SodepFault::name() const QString Fault::name() const
{ {
return d->name; return d->name;
} }
SodepValue SodepFault::data() const Value Fault::data() const
{ {
return d->data; return d->data;
} }
bool SodepFault::isValid() const bool Fault::isValid() const
{ {
return !d->name.isEmpty(); return !d->name.isEmpty();
} }

View File

@ -18,32 +18,37 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef SODEPFAULT_H #ifndef QTJOLIE_FAULT_H
#define SODEPFAULT_H #define QTJOLIE_FAULT_H
#include <qtjolie/sodepvalue.h> #include <qtjolie/value.h>
class SodepFaultPrivate; namespace Jolie
{
class FaultPrivate;
class Q_DECL_EXPORT SodepFault class Q_DECL_EXPORT Fault
{ {
public: public:
SodepFault(); Fault();
explicit SodepFault(const QString &name, const SodepValue &data = SodepValue()); explicit Fault(const QString &name, const Value &data = Value());
SodepFault(const SodepFault &other); Fault(const Fault &other);
~SodepFault(); ~Fault();
SodepFault &operator=(const SodepFault &other); Fault &operator=(const Fault &other);
QString name() const; QString name() const;
SodepValue data() const; Value data() const;
bool isValid() const; bool isValid() const;
private: private:
SodepFaultPrivate * const d; FaultPrivate * const d;
}; };
} // namespace Jolie
#endif #endif

View File

@ -18,31 +18,38 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include "sodepmessage.h" #include "message.h"
#include <QtCore/QString> #include <QtCore/QString>
#include "sodephelpers_p.h" #include "sodephelpers_p.h"
class SodepMessagePrivate namespace Jolie
{
class MessagePrivate
{ {
public: public:
SodepMessagePrivate() : id(0) {} MessagePrivate() : id(0) {}
qint64 id; qint64 id;
QString resourcePath; QString resourcePath;
QString operationName; QString operationName;
SodepFault fault; Fault fault;
SodepValue data; Value data;
}; };
SodepMessage::SodepMessage() } // namespace Jolie
: d(new SodepMessagePrivate)
using namespace Jolie;
Message::Message()
: d(new MessagePrivate)
{ {
} }
SodepMessage::SodepMessage(const QString &resourcePath, const QString &operationName, qint64 id) Message::Message(const QString &resourcePath, const QString &operationName, qint64 id)
: d(new SodepMessagePrivate) : d(new MessagePrivate)
{ {
static qint64 lastId = 0; static qint64 lastId = 0;
@ -55,60 +62,60 @@ SodepMessage::SodepMessage(const QString &resourcePath, const QString &operation
d->operationName = operationName; d->operationName = operationName;
} }
SodepMessage::SodepMessage(const SodepMessage &other) Message::Message(const Message &other)
: d(new SodepMessagePrivate) : d(new MessagePrivate)
{ {
*d = *other.d; *d = *other.d;
} }
SodepMessage::~SodepMessage() Message::~Message()
{ {
delete d; delete d;
} }
SodepMessage &SodepMessage::operator=(const SodepMessage &other) Message &Message::operator=(const Message &other)
{ {
*d = *other.d; *d = *other.d;
return *this; return *this;
} }
qint64 SodepMessage::id() const qint64 Message::id() const
{ {
return d->id; return d->id;
} }
QString SodepMessage::resourcePath() const QString Message::resourcePath() const
{ {
return d->resourcePath; return d->resourcePath;
} }
QString SodepMessage::operationName() const QString Message::operationName() const
{ {
return d->operationName; return d->operationName;
} }
SodepFault SodepMessage::fault() const Fault Message::fault() const
{ {
return d->fault; return d->fault;
} }
void SodepMessage::setFault(const SodepFault &fault) void Message::setFault(const Fault &fault)
{ {
d->fault = fault; d->fault = fault;
} }
SodepValue SodepMessage::data() const Value Message::data() const
{ {
return d->data; return d->data;
} }
void SodepMessage::setData(const SodepValue &data) void Message::setData(const Value &data)
{ {
d->data = data; d->data = data;
} }
bool SodepMessage::isValid() bool Message::isValid()
{ {
return !d->resourcePath.isEmpty() && !d->operationName.isEmpty(); return !d->resourcePath.isEmpty() && !d->operationName.isEmpty();
} }

View File

@ -18,41 +18,46 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef SODEPMESSAGE_H #ifndef QTJOLIE_MESSAGE_H
#define SODEPMESSAGE_H #define QTJOLIE_MESSAGE_H
#include <qtjolie/sodepvalue.h> #include <qtjolie/value.h>
#include <qtjolie/sodepfault.h> #include <qtjolie/fault.h>
class SodepMessagePrivate; namespace Jolie
{
class MessagePrivate;
class Q_DECL_EXPORT SodepMessage class Q_DECL_EXPORT Message
{ {
public: public:
SodepMessage(); Message();
explicit SodepMessage(const QString &resourcePath, explicit Message(const QString &resourcePath,
const QString &operationName, const QString &operationName,
qint64 id = 0); qint64 id = 0);
SodepMessage(const SodepMessage &other); Message(const Message &other);
~SodepMessage(); ~Message();
SodepMessage &operator=(const SodepMessage &other); Message &operator=(const Message &other);
qint64 id() const; qint64 id() const;
QString resourcePath() const; QString resourcePath() const;
QString operationName() const; QString operationName() const;
SodepFault fault() const; Fault fault() const;
void setFault(const SodepFault &fault); void setFault(const Fault &fault);
SodepValue data() const; Value data() const;
void setData(const SodepValue &data); void setData(const Value &data);
bool isValid(); bool isValid();
private: private:
SodepMessagePrivate * const d; MessagePrivate * const d;
}; };
} // namespace Jolie
#endif #endif

View File

@ -18,62 +18,64 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include "sodeppendingcall.h" #include "pendingcall.h"
#include "sodeppendingcall_p.h" #include "pendingcall_p.h"
using namespace Jolie;
SodepPendingCall::SodepPendingCall(const SodepPendingCall &other) PendingCall::PendingCall(const PendingCall &other)
: d(other.d) : d(other.d)
{ {
} }
SodepPendingCall::SodepPendingCall(QExplicitlySharedDataPointer<SodepPendingCallPrivate> dd) PendingCall::PendingCall(QExplicitlySharedDataPointer<PendingCallPrivate> dd)
: d(dd) : d(dd)
{ {
} }
SodepPendingCall::~SodepPendingCall() PendingCall::~PendingCall()
{ {
} }
SodepPendingCall &SodepPendingCall::operator=(const SodepPendingCall &other) PendingCall &PendingCall::operator=(const PendingCall &other)
{ {
d = other.d; d = other.d;
return *this; return *this;
} }
bool SodepPendingCall::isFinished() const bool PendingCall::isFinished() const
{ {
return d->isFinished; return d->isFinished;
} }
SodepMessage SodepPendingCall::reply() const Message PendingCall::reply() const
{ {
return d->reply; return d->reply;
} }
void SodepPendingCall::waitForFinished() void PendingCall::waitForFinished()
{ {
SodepPendingCallWaiter waiter; PendingCallWaiter waiter;
waiter.waitForFinished(d.data()); waiter.waitForFinished(d.data());
} }
void SodepPendingCallPrivate::setReply(const SodepMessage &message) void PendingCallPrivate::setReply(const Message &message)
{ {
Q_ASSERT(message.id()==id); Q_ASSERT(message.id()==id);
isFinished = true; isFinished = true;
reply = message; reply = message;
foreach (SodepPendingCallWaiter *waiter, waiters) { foreach (PendingCallWaiter *waiter, waiters) {
waiter->eventLoop.quit(); waiter->eventLoop.quit();
} }
waiters.clear(); waiters.clear();
} }
void SodepPendingCallWaiter::waitForFinished(SodepPendingCallPrivate *pendingCall) void PendingCallWaiter::waitForFinished(PendingCallPrivate *pendingCall)
{ {
pendingCall->waiters << this; pendingCall->waiters << this;
eventLoop.exec(); eventLoop.exec();
} }

View File

@ -18,35 +18,40 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef SODEPPENDINGCALL_H #ifndef QTJOLIE_PENDINGCALL_H
#define SODEPPENDINGCALL_H #define QTJOLIE_PENDINGCALL_H
#include <QtCore/QExplicitlySharedDataPointer> #include <QtCore/QExplicitlySharedDataPointer>
class SodepClient; namespace Jolie
class SodepPendingCallPrivate; {
class SodepMessage; class Client;
class PendingCallPrivate;
class Message;
class Q_DECL_EXPORT SodepPendingCall class Q_DECL_EXPORT PendingCall
{ {
public: public:
SodepPendingCall(const SodepPendingCall &other); PendingCall(const PendingCall &other);
~SodepPendingCall(); ~PendingCall();
SodepPendingCall &operator=(const SodepPendingCall &other); PendingCall &operator=(const PendingCall &other);
bool isFinished() const; bool isFinished() const;
SodepMessage reply() const; Message reply() const;
void waitForFinished(); void waitForFinished();
private: private:
friend class SodepClient; friend class Client;
SodepPendingCall(); // Not defined PendingCall(); // Not defined
SodepPendingCall(QExplicitlySharedDataPointer<SodepPendingCallPrivate> dd); PendingCall(QExplicitlySharedDataPointer<PendingCallPrivate> dd);
QExplicitlySharedDataPointer<SodepPendingCallPrivate> d; QExplicitlySharedDataPointer<PendingCallPrivate> d;
}; };
} // namespace Jolie
#endif #endif

View File

@ -18,44 +18,49 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef SODEPPENDINGCALL_P_H #ifndef QTJOLIE_PENDINGCALL_P_H
#define SODEPPENDINGCALL_P_H #define QTJOLIE_PENDINGCALL_P_H
#include <QtCore/QEventLoop> #include <QtCore/QEventLoop>
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QSharedData> #include <QtCore/QSharedData>
#include "sodepmessage.h" #include "message.h"
class SodepPendingCallPrivate; namespace Jolie
{
class SodepPendingCallWaiter class PendingCallPrivate;
class PendingCallWaiter
{ {
public: public:
void waitForFinished(SodepPendingCallPrivate *pendingCall); void waitForFinished(PendingCallPrivate *pendingCall);
private: private:
friend class SodepPendingCallPrivate; friend class PendingCallPrivate;
QEventLoop eventLoop; QEventLoop eventLoop;
}; };
class SodepPendingCallPrivate : public QSharedData class PendingCallPrivate : public QSharedData
{ {
public: public:
SodepPendingCallPrivate(const SodepMessage &message) PendingCallPrivate(const Message &message)
: id(message.id()), isFinished(false) {} : id(message.id()), isFinished(false) {}
void setReply(const SodepMessage &message); void setReply(const Message &message);
private: private:
friend class SodepPendingCall; friend class PendingCall;
friend class SodepPendingCallWaiter; friend class PendingCallWaiter;
qint64 id; qint64 id;
bool isFinished; bool isFinished;
SodepMessage reply; Message reply;
QList<SodepPendingCallWaiter*> waiters; QList<PendingCallWaiter*> waiters;
}; };
} // namespace Jolie
#endif #endif

View File

@ -18,16 +18,19 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef SODEPHELPERS_P_H #ifndef QTJOLIE_SODEPHELPERS_P_H
#define SODEPHELPERS_P_H #define QTJOLIE_SODEPHELPERS_P_H
#include <QtCore/QIODevice> #include <QtCore/QIODevice>
#include <QtCore/QString> #include <QtCore/QString>
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include "sodepvalue.h" #include "value.h"
#include "sodepfault.h" #include "fault.h"
#include "sodepmessage.h" #include "message.h"
namespace Jolie
{
inline void sodepWrite(QIODevice &io, double value) inline void sodepWrite(QIODevice &io, double value)
{ {
@ -72,7 +75,7 @@ inline void sodepWrite(QIODevice &io, const QString &value)
io.write(data); io.write(data);
} }
inline void sodepWrite(QIODevice &io, const SodepValue &value) inline void sodepWrite(QIODevice &io, const Value &value)
{ {
if (value.isDouble()) { if (value.isDouble()) {
io.putChar(3); io.putChar(3);
@ -92,7 +95,7 @@ inline void sodepWrite(QIODevice &io, const SodepValue &value)
foreach (const QString &name, value.childrenNames()) { foreach (const QString &name, value.childrenNames()) {
sodepWrite(io, name); sodepWrite(io, name);
QList<SodepValue> values = value.children(name); QList<Value> values = value.children(name);
qint32 valueCount = values.size(); qint32 valueCount = values.size();
sodepWrite(io, valueCount); sodepWrite(io, valueCount);
for (int j=0; j<valueCount; ++j) { for (int j=0; j<valueCount; ++j) {
@ -102,7 +105,7 @@ inline void sodepWrite(QIODevice &io, const SodepValue &value)
} }
inline void sodepWrite(QIODevice &io, const SodepFault &fault) inline void sodepWrite(QIODevice &io, const Fault &fault)
{ {
if (!fault.isValid()) { if (!fault.isValid()) {
io.putChar(0); io.putChar(0);
@ -114,7 +117,7 @@ inline void sodepWrite(QIODevice &io, const SodepFault &fault)
sodepWrite(io, fault.data()); sodepWrite(io, fault.data());
} }
inline void sodepWrite(QIODevice &io, const SodepMessage &message) inline void sodepWrite(QIODevice &io, const Message &message)
{ {
sodepWrite(io, message.id()); sodepWrite(io, message.id());
sodepWrite(io, message.resourcePath()); sodepWrite(io, message.resourcePath());
@ -198,9 +201,9 @@ inline QString sodepReadString(QIODevice &io)
return result; return result;
} }
inline SodepValue sodepReadValue(QIODevice &io) inline Value sodepReadValue(QIODevice &io)
{ {
SodepValue result; Value result;
while (io.bytesAvailable()<1) { while (io.bytesAvailable()<1) {
io.waitForReadyRead(-1); io.waitForReadyRead(-1);
@ -211,15 +214,15 @@ inline SodepValue sodepReadValue(QIODevice &io)
switch(code) { switch(code) {
case 3: { case 3: {
result = SodepValue(sodepReadDouble(io)); result = Value(sodepReadDouble(io));
break; break;
} }
case 2: { case 2: {
result = SodepValue(sodepReadInt32(io)); result = Value(sodepReadInt32(io));
break; break;
} }
case 1: { case 1: {
result = SodepValue(sodepReadString(io)); result = Value(sodepReadString(io));
break; break;
} }
default: default:
@ -240,7 +243,7 @@ inline SodepValue sodepReadValue(QIODevice &io)
return result; return result;
} }
inline SodepFault sodepReadFault(QIODevice &io) inline Fault sodepReadFault(QIODevice &io)
{ {
while (io.bytesAvailable()<1) { while (io.bytesAvailable()<1) {
io.waitForReadyRead(-1); io.waitForReadyRead(-1);
@ -250,22 +253,22 @@ inline SodepFault sodepReadFault(QIODevice &io)
io.getChar(&code); io.getChar(&code);
if (code!=1) { if (code!=1) {
return SodepFault(); return Fault();
} }
QString name = sodepReadString(io); QString name = sodepReadString(io);
SodepValue data = sodepReadValue(io); Value data = sodepReadValue(io);
return SodepFault(name, data); return Fault(name, data);
} }
inline SodepMessage sodepReadMessage(QIODevice &io) inline Message sodepReadMessage(QIODevice &io)
{ {
qint64 id = sodepReadInt64(io); qint64 id = sodepReadInt64(io);
QString resourcePath = sodepReadString(io); QString resourcePath = sodepReadString(io);
QString operationName = sodepReadString(io); QString operationName = sodepReadString(io);
SodepMessage result(resourcePath, operationName, id); Message result(resourcePath, operationName, id);
result.setFault(sodepReadFault(io)); result.setFault(sodepReadFault(io));
result.setData(sodepReadValue(io)); result.setData(sodepReadValue(io));
@ -273,4 +276,7 @@ inline SodepMessage sodepReadMessage(QIODevice &io)
return result; return result;
} }
} // namespace Jolie
#endif #endif

View File

@ -18,77 +18,84 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include "sodepvalue.h" #include "value.h"
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtCore/QVariant> #include <QtCore/QVariant>
#include "sodephelpers_p.h" #include "sodephelpers_p.h"
class SodepValuePrivate namespace Jolie
{
class ValuePrivate
{ {
public: public:
QVariant content; QVariant content;
QMap<QString, QList<SodepValue> > children; QMap<QString, QList<Value> > children;
}; };
SodepValue::SodepValue() } // namespace Jolie
: d(new SodepValuePrivate)
using namespace Jolie;
Value::Value()
: d(new ValuePrivate)
{ {
} }
SodepValue::SodepValue(const QString &content) Value::Value(const QString &content)
: d(new SodepValuePrivate) : d(new ValuePrivate)
{ {
d->content = content; d->content = content;
} }
SodepValue::SodepValue(qint32 content) Value::Value(qint32 content)
: d(new SodepValuePrivate) : d(new ValuePrivate)
{ {
d->content = content; d->content = content;
} }
SodepValue::SodepValue(double content) Value::Value(double content)
: d(new SodepValuePrivate) : d(new ValuePrivate)
{ {
d->content = content; d->content = content;
} }
SodepValue::SodepValue(const SodepValue &other) Value::Value(const Value &other)
: d(new SodepValuePrivate) : d(new ValuePrivate)
{ {
*d = *other.d; *d = *other.d;
} }
SodepValue::~SodepValue() Value::~Value()
{ {
delete d; delete d;
} }
SodepValue &SodepValue::operator=(const SodepValue &other) Value &Value::operator=(const Value &other)
{ {
*d = *other.d; *d = *other.d;
return *this; return *this;
} }
QStringList SodepValue::childrenNames() const QStringList Value::childrenNames() const
{ {
return d->children.keys(); return d->children.keys();
} }
QList<SodepValue> & SodepValue::children(const QString &name) QList<Value> & Value::children(const QString &name)
{ {
return d->children[name]; return d->children[name];
} }
const QList<SodepValue> & SodepValue::children(const QString &name) const const QList<Value> & Value::children(const QString &name) const
{ {
return d->children[name]; return d->children[name];
} }
QString SodepValue::toString() const QString Value::toString() const
{ {
if (isString()) { if (isString()) {
return d->content.toString(); return d->content.toString();
@ -97,7 +104,7 @@ QString SodepValue::toString() const
} }
} }
qint32 SodepValue::toInt() const qint32 Value::toInt() const
{ {
if (isInt()) { if (isInt()) {
return d->content.toInt(); return d->content.toInt();
@ -106,7 +113,7 @@ qint32 SodepValue::toInt() const
} }
} }
double SodepValue::toDouble() const double Value::toDouble() const
{ {
if (isDouble()) { if (isDouble()) {
return d->content.toDouble(); return d->content.toDouble();
@ -115,22 +122,23 @@ double SodepValue::toDouble() const
} }
} }
bool SodepValue::isString() const bool Value::isString() const
{ {
return d->content.type()==QVariant::String; return d->content.type()==QVariant::String;
} }
bool SodepValue::isInt() const bool Value::isInt() const
{ {
return d->content.type()==QVariant::Int; return d->content.type()==QVariant::Int;
} }
bool SodepValue::isDouble() const bool Value::isDouble() const
{ {
return d->content.type()==QVariant::Double; return d->content.type()==QVariant::Double;
} }
bool SodepValue::isValid() const bool Value::isValid() const
{ {
return isString() || isInt() || isDouble(); return isString() || isInt() || isDouble();
} }

View File

@ -18,32 +18,34 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#ifndef SODEPVALUE_H #ifndef QTJOLIE_VALUE_H
#define SODEPVALUE_H #define QTJOLIE_VALUE_H
#include <QtCore/QIODevice> #include <QtCore/QIODevice>
#include <QtCore/QList> #include <QtCore/QList>
class SodepValuePrivate; namespace Jolie
{
class ValuePrivate;
class Q_DECL_EXPORT SodepValue class Q_DECL_EXPORT Value
{ {
public: public:
SodepValue(); Value();
explicit SodepValue(const QString &content); explicit Value(const QString &content);
explicit SodepValue(qint32 content); explicit Value(qint32 content);
explicit SodepValue(double content); explicit Value(double content);
SodepValue(const SodepValue &other); Value(const Value &other);
~SodepValue(); ~Value();
SodepValue &operator=(const SodepValue &other); Value &operator=(const Value &other);
QStringList childrenNames() const; QStringList childrenNames() const;
QList<SodepValue> &children(const QString &name); QList<Value> &children(const QString &name);
const QList<SodepValue> &children(const QString &name) const; const QList<Value> &children(const QString &name) const;
QString toString() const; QString toString() const;
qint32 toInt() const; qint32 toInt() const;
@ -56,7 +58,10 @@ public:
bool isValid() const; bool isValid() const;
private: private:
SodepValuePrivate * const d; ValuePrivate * const d;
}; };
} // namespace Jolie
#endif #endif

View File

@ -17,12 +17,12 @@ MACRO(SODEP_EXECUTABLE_TESTS)
ENDMACRO(SODEP_EXECUTABLE_TESTS) ENDMACRO(SODEP_EXECUTABLE_TESTS)
SODEP_UNIT_TESTS( SODEP_UNIT_TESTS(
sodepvaluetest testvalue
sodepfaulttest testfault
sodepmessagetest testmessage
sodepmetaservicetest testmetaservice
) )
SODEP_EXECUTABLE_TESTS( SODEP_EXECUTABLE_TESTS(
sodepprintertest testprinter
) )

View File

@ -21,17 +21,19 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <qtjolie/sodepfault.h> #include <qtjolie/fault.h>
#include "sodeptesthelpers.h" #include "testhelpers.h"
class SodepFaultTest : public QObject using namespace Jolie;
class TestFault : public QObject
{ {
Q_OBJECT Q_OBJECT
private slots: private slots:
void shouldHandleInvalids() void shouldHandleInvalids()
{ {
SodepFault f; Fault f;
QCOMPARE(f.name(), QString()); QCOMPARE(f.name(), QString());
QVERIFY(!f.data().isValid()); QVERIFY(!f.data().isValid());
@ -40,7 +42,7 @@ private slots:
} }
void shouldVerifyInitialState() void shouldVerifyInitialState()
{ {
SodepFault f1("blup"), f2("blop", SodepValue(42)); Fault f1("blup"), f2("blop", Value(42));
QCOMPARE(f1.name(), QString("blup")); QCOMPARE(f1.name(), QString("blup"));
QVERIFY(!f1.data().isValid()); QVERIFY(!f1.data().isValid());
@ -58,18 +60,18 @@ private slots:
void shouldBeSerializable_data() void shouldBeSerializable_data()
{ {
SodepValue v(42); Value v(42);
QByteArray vSerial = QByteArray::fromHex("020000002A00000000"); QByteArray vSerial = QByteArray::fromHex("020000002A00000000");
QTest::addColumn<SodepFault>("original"); QTest::addColumn<Fault>("original");
QTest::addColumn<QByteArray>("serialized"); QTest::addColumn<QByteArray>("serialized");
QTest::newRow("empty fault") << SodepFault() QTest::newRow("empty fault") << Fault()
<< QByteArray::fromHex("00"); << QByteArray::fromHex("00");
QTest::newRow("no value fault") << SodepFault("foo") QTest::newRow("no value fault") << Fault("foo")
<< QByteArray::fromHex("0100000003")+QByteArray("foo") << QByteArray::fromHex("0100000003")+QByteArray("foo")
+ QByteArray::fromHex("0000000000"); + QByteArray::fromHex("0000000000");
QTest::newRow("value fault") << SodepFault("bar", v) QTest::newRow("value fault") << Fault("bar", v)
<< QByteArray::fromHex("0100000003")+QByteArray("bar") << QByteArray::fromHex("0100000003")+QByteArray("bar")
+ vSerial; + vSerial;
} }
@ -78,9 +80,9 @@ private slots:
{ {
QBuffer buffer; QBuffer buffer;
QFETCH(SodepFault, original); QFETCH(Fault, original);
QFETCH(QByteArray, serialized); QFETCH(QByteArray, serialized);
SodepFault result; Fault result;
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
sodepWrite(buffer, original); sodepWrite(buffer, original);
@ -95,6 +97,6 @@ private slots:
} }
}; };
QTEST_MAIN(SodepFaultTest) QTEST_MAIN(TestFault)
#include "sodepfaulttest.moc" #include "testfault.moc"

View File

@ -23,14 +23,14 @@
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <qtjolie/sodepfault.h> #include <qtjolie/fault.h>
#include <qtjolie/sodepmessage.h> #include <qtjolie/message.h>
#include <qtjolie/sodepvalue.h> #include <qtjolie/value.h>
#include <qtjolie/sodephelpers_p.h> #include <qtjolie/sodephelpers_p.h>
Q_DECLARE_METATYPE(SodepValue); Q_DECLARE_METATYPE(Jolie::Value);
inline void sodepCompare(const SodepValue &v1, const SodepValue &v2) inline void sodepCompare(const Jolie::Value &v1, const Jolie::Value &v2)
{ {
QCOMPARE(v1.isValid(), v2.isValid()); QCOMPARE(v1.isValid(), v2.isValid());
@ -47,8 +47,8 @@ inline void sodepCompare(const SodepValue &v1, const SodepValue &v2)
QCOMPARE(v1Names, v2Names); QCOMPARE(v1Names, v2Names);
foreach (const QString &name, v1Names) { foreach (const QString &name, v1Names) {
QList<SodepValue> v1Values = v1.children(name); QList<Jolie::Value> v1Values = v1.children(name);
QList<SodepValue> v2Values = v2.children(name); QList<Jolie::Value> v2Values = v2.children(name);
QCOMPARE(v1Values.size(), v2Values.size()); QCOMPARE(v1Values.size(), v2Values.size());
@ -58,18 +58,18 @@ inline void sodepCompare(const SodepValue &v1, const SodepValue &v2)
} }
} }
Q_DECLARE_METATYPE(SodepFault); Q_DECLARE_METATYPE(Jolie::Fault);
inline void sodepCompare(const SodepFault &f1, const SodepFault &f2) inline void sodepCompare(const Jolie::Fault &f1, const Jolie::Fault &f2)
{ {
QCOMPARE(f1.isValid(), f2.isValid()); QCOMPARE(f1.isValid(), f2.isValid());
QCOMPARE(f1.name(), f2.name()); QCOMPARE(f1.name(), f2.name());
sodepCompare(f1.data(), f2.data()); sodepCompare(f1.data(), f2.data());
} }
Q_DECLARE_METATYPE(SodepMessage); Q_DECLARE_METATYPE(Jolie::Message);
inline void sodepCompare(const SodepMessage &m1, const SodepMessage &m2) inline void sodepCompare(const Jolie::Message &m1, const Jolie::Message &m2)
{ {
QCOMPARE(m1.resourcePath(), m2.resourcePath()); QCOMPARE(m1.resourcePath(), m2.resourcePath());
QCOMPARE(m1.operationName(), m2.operationName()); QCOMPARE(m1.operationName(), m2.operationName());

View File

@ -21,18 +21,20 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <qtjolie/sodepmessage.h> #include <qtjolie/message.h>
#include "sodeptesthelpers.h" #include "testhelpers.h"
class SodepMessageTest : public QObject using namespace Jolie;
class TestMessage : public QObject
{ {
Q_OBJECT Q_OBJECT
private slots: private slots:
void shouldVerifyInitialState() void shouldVerifyInitialState()
{ {
SodepMessage m1("/foo", "bar", 1); Message m1("/foo", "bar", 1);
SodepMessage m2("/pata/pata", "pon", 2); Message m2("/pata/pata", "pon", 2);
QCOMPARE(m1.resourcePath(), QString("/foo")); QCOMPARE(m1.resourcePath(), QString("/foo"));
QCOMPARE(m1.operationName(), QString("bar")); QCOMPARE(m1.operationName(), QString("bar"));
@ -51,23 +53,23 @@ private slots:
void shouldBeSerializable_data() void shouldBeSerializable_data()
{ {
SodepValue v(42); Value v(42);
QByteArray vSerial = QByteArray::fromHex("020000002A00000000"); QByteArray vSerial = QByteArray::fromHex("020000002A00000000");
SodepFault f("foo"); Fault f("foo");
QByteArray fSerial = QByteArray::fromHex("0100000003")+QByteArray("foo") QByteArray fSerial = QByteArray::fromHex("0100000003")+QByteArray("foo")
+ QByteArray::fromHex("0000000000"); + QByteArray::fromHex("0000000000");
QTest::addColumn<SodepMessage>("original"); QTest::addColumn<Message>("original");
QTest::addColumn<QByteArray>("serialized"); QTest::addColumn<QByteArray>("serialized");
QTest::newRow("no payload message") << SodepMessage("/pata", "pon", 1) QTest::newRow("no payload message") << Message("/pata", "pon", 1)
<< QByteArray::fromHex("0000000000000001") << QByteArray::fromHex("0000000000000001")
+ QByteArray::fromHex("00000005")+QByteArray("/pata") + QByteArray::fromHex("00000005")+QByteArray("/pata")
+ QByteArray::fromHex("00000003")+QByteArray("pon") + QByteArray::fromHex("00000003")+QByteArray("pon")
+ QByteArray::fromHex("00") + QByteArray::fromHex("00")
+ QByteArray::fromHex("0000000000"); + QByteArray::fromHex("0000000000");
SodepMessage payload("/pata", "pon", 1); Message payload("/pata", "pon", 1);
payload.setFault(f); payload.setFault(f);
payload.setData(v); payload.setData(v);
QTest::newRow("payload message") << payload QTest::newRow("payload message") << payload
@ -77,7 +79,7 @@ private slots:
+ fSerial + fSerial
+ vSerial; + vSerial;
SodepMessage payloadId("/pata", "pon", 42); Message payloadId("/pata", "pon", 42);
payloadId.setFault(f); payloadId.setFault(f);
payloadId.setData(v); payloadId.setData(v);
QTest::newRow("payload and id message") << payloadId QTest::newRow("payload and id message") << payloadId
@ -92,9 +94,9 @@ private slots:
{ {
QBuffer buffer; QBuffer buffer;
QFETCH(SodepMessage, original); QFETCH(Message, original);
QFETCH(QByteArray, serialized); QFETCH(QByteArray, serialized);
SodepMessage result; Message result;
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
sodepWrite(buffer, original); sodepWrite(buffer, original);
@ -109,6 +111,6 @@ private slots:
} }
}; };
QTEST_MAIN(SodepMessageTest) QTEST_MAIN(TestMessage)
#include "sodepmessagetest.moc" #include "testmessage.moc"

View File

@ -22,17 +22,18 @@
#include <QtCore/QProcess> #include <QtCore/QProcess>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <qtjolie/sodepclient.h> #include <qtjolie/client.h>
#include <qtjolie/sodepmessage.h> #include <qtjolie/message.h>
#include <qtjolie/sodeppendingcall.h> #include <qtjolie/pendingcall.h>
#include "sodeptesthelpers.h" #include "testhelpers.h"
#ifndef DATA_DIR #ifndef DATA_DIR
#error "DATA_DIR is not set. A directory containing test jolie scripts is required for this test" #error "DATA_DIR is not set. A directory containing test jolie scripts is required for this test"
#endif #endif
using namespace Jolie;
void dump(const SodepValue &value, int level) void dump(const Value &value, int level)
{ {
QString indent; QString indent;
@ -43,15 +44,15 @@ void dump(const SodepValue &value, int level)
qDebug() << (indent+value.toString()) << value.toInt() << value.toDouble(); qDebug() << (indent+value.toString()) << value.toInt() << value.toDouble();
foreach (const QString &name, value.childrenNames()) { foreach (const QString &name, value.childrenNames()) {
QList<SodepValue> children = value.children(name); QList<Value> children = value.children(name);
qDebug() << (indent+"Children:") << name; qDebug() << (indent+"Children:") << name;
foreach (const SodepValue &child, children) { foreach (const Value &child, children) {
dump(child, level+1); dump(child, level+1);
} }
} }
} }
void dump(const SodepMessage &message) void dump(const Message &message)
{ {
qDebug() << "Resource :" << message.resourcePath(); qDebug() << "Resource :" << message.resourcePath();
qDebug() << "Operation:" << message.operationName(); qDebug() << "Operation:" << message.operationName();
@ -61,18 +62,18 @@ void dump(const SodepMessage &message)
dump(message.data(), 1); dump(message.data(), 1);
} }
class SodepMetaServiceTest : public QObject class TestMetaService : public QObject
{ {
Q_OBJECT Q_OBJECT
QProcess m_metaserviceProcess; QProcess m_metaserviceProcess;
SodepClient *m_client; Client *m_client;
public: public:
SodepMetaServiceTest() TestMetaService()
: QObject() : QObject()
{ {
qRegisterMetaType<SodepMessage>(); qRegisterMetaType<Message>();
} }
private slots: private slots:
@ -82,12 +83,12 @@ private slots:
QVERIFY2(m_metaserviceProcess.waitForStarted(), "Looks like you don't have Jolie's metaservice command"); QVERIFY2(m_metaserviceProcess.waitForStarted(), "Looks like you don't have Jolie's metaservice command");
QTest::qWait(1000); QTest::qWait(1000);
m_client = new SodepClient("localhost", 9000); m_client = new Client("localhost", 9000);
} }
void cleanupTestCase() void cleanupTestCase()
{ {
SodepMessage message("/", "shutdown"); Message message("/", "shutdown");
m_client->callNoReply(message); m_client->callNoReply(message);
delete m_client; delete m_client;
@ -108,34 +109,34 @@ private slots:
QFETCH(QString, resourcePrefix); QFETCH(QString, resourcePrefix);
QFETCH(QString, fileName); QFETCH(QString, fileName);
SodepMessage message("/", "loadEmbeddedJolieService"); Message message("/", "loadEmbeddedJolieService");
SodepValue value; Value value;
value.children("resourcePrefix") << SodepValue(resourcePrefix); value.children("resourcePrefix") << Value(resourcePrefix);
value.children("filepath") << SodepValue(QString(DATA_DIR"/")+fileName); value.children("filepath") << Value(QString(DATA_DIR"/")+fileName);
message.setData(value); message.setData(value);
SodepMessage reply = m_client->call(message); Message reply = m_client->call(message);
SodepMessage expected("/", "loadEmbeddedJolieService"); Message expected("/", "loadEmbeddedJolieService");
expected.setData(SodepValue(resourcePrefix)); expected.setData(Value(resourcePrefix));
sodepCompare(reply, expected); sodepCompare(reply, expected);
} }
void shouldListServices() void shouldListServices()
{ {
SodepMessage message("/", "getServices"); Message message("/", "getServices");
SodepMessage reply = m_client->call(message); Message reply = m_client->call(message);
SodepMessage expected("/", "getServices"); Message expected("/", "getServices");
SodepValue value; Value value;
SodepValue s1; Value s1;
s1.children("isEmbedded") << SodepValue(1); s1.children("isEmbedded") << Value(1);
s1.children("resourceName") << SodepValue("Math"); s1.children("resourceName") << Value("Math");
SodepValue s2; Value s2;
s2.children("isEmbedded") << SodepValue(1); s2.children("isEmbedded") << Value(1);
s2.children("resourceName") << SodepValue("Printer"); s2.children("resourceName") << Value("Printer");
value.children("service") << s1 << s2; value.children("service") << s1 << s2;
expected.setData(value); expected.setData(value);
@ -147,26 +148,26 @@ private slots:
{ {
QTest::addColumn<QString>("path"); QTest::addColumn<QString>("path");
QTest::addColumn<QString>("method"); QTest::addColumn<QString>("method");
QTest::addColumn<SodepValue>("data"); QTest::addColumn<Value>("data");
QTest::addColumn<SodepValue>("replyData"); QTest::addColumn<Value>("replyData");
QTest::newRow("printer service") << "/Printer" << "printInput" << SodepValue("Patapatapon!") << SodepValue("success"); QTest::newRow("printer service") << "/Printer" << "printInput" << Value("Patapatapon!") << Value("success");
QTest::newRow("math service") << "/Math" << "twice" << SodepValue(10.5) << SodepValue(21.0); QTest::newRow("math service") << "/Math" << "twice" << Value(10.5) << Value(21.0);
} }
void shouldPlaceServiceCalls() void shouldPlaceServiceCalls()
{ {
QFETCH(QString, path); QFETCH(QString, path);
QFETCH(QString, method); QFETCH(QString, method);
QFETCH(SodepValue, data); QFETCH(Value, data);
QFETCH(SodepValue, replyData); QFETCH(Value, replyData);
SodepMessage message(path, method); Message message(path, method);
message.setData(data); message.setData(data);
SodepMessage reply = m_client->call(message); Message reply = m_client->call(message);
SodepMessage expected("/", method); Message expected("/", method);
expected.setData(replyData); expected.setData(replyData);
sodepCompare(reply, expected); sodepCompare(reply, expected);
@ -184,18 +185,18 @@ private slots:
{ {
QFETCH(QString, serviceName); QFETCH(QString, serviceName);
SodepMessage message("/", "unloadEmbeddedService"); Message message("/", "unloadEmbeddedService");
SodepValue value(serviceName); Value value(serviceName);
message.setData(value); message.setData(value);
SodepMessage reply = m_client->call(message); Message reply = m_client->call(message);
SodepMessage expected("/", "unloadEmbeddedService"); Message expected("/", "unloadEmbeddedService");
sodepCompare(reply, expected); sodepCompare(reply, expected);
} }
}; };
QTEST_MAIN(SodepMetaServiceTest) QTEST_MAIN(TestMetaService)
#include "sodepmetaservicetest.moc" #include "testmetaservice.moc"

View File

@ -25,10 +25,12 @@
#include <QtGui/QPushButton> #include <QtGui/QPushButton>
#include <QtNetwork/QTcpSocket> #include <QtNetwork/QTcpSocket>
#include <qtjolie/sodepmessage.h> #include <qtjolie/message.h>
#include <qtjolie/sodepvalue.h> #include <qtjolie/value.h>
#include <qtjolie/sodephelpers_p.h> #include <qtjolie/sodephelpers_p.h>
using namespace Jolie;
class MainWindow : public QWidget class MainWindow : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -56,8 +58,8 @@ public:
private slots: private slots:
void sendMessage() void sendMessage()
{ {
SodepMessage message("/", "printInput"); Message message("/", "printInput");
message.setData(SodepValue(m_lineEdit->text())); message.setData(Value(m_lineEdit->text()));
sodepWrite(m_socket, message); sodepWrite(m_socket, message);
qDebug("Message sent:"); qDebug("Message sent:");
@ -90,4 +92,4 @@ int main(int argc, char **argv)
return app.exec(); return app.exec();
} }
#include "sodepprintertest.moc" #include "testprinter.moc"

View File

@ -21,18 +21,20 @@
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtTest/QtTest> #include <QtTest/QtTest>
#include <qtjolie/sodepvalue.h> #include <qtjolie/value.h>
#include "sodeptesthelpers.h" #include "testhelpers.h"
class SodepValueTest : public QObject using namespace Jolie;
class TestValue : public QObject
{ {
Q_OBJECT Q_OBJECT
private slots: private slots:
void shouldHandleInvalids() void shouldHandleInvalids()
{ {
SodepValue v; Value v;
QCOMPARE(v.toInt(), 0); QCOMPARE(v.toInt(), 0);
QCOMPARE(v.toDouble(), 0.0); QCOMPARE(v.toDouble(), 0.0);
@ -47,7 +49,7 @@ private slots:
void shouldRespectIntValues() void shouldRespectIntValues()
{ {
SodepValue v1(42), v2; Value v1(42), v2;
QCOMPARE(v1.toInt(), 42); QCOMPARE(v1.toInt(), 42);
QCOMPARE(v2.toInt(), 0); QCOMPARE(v2.toInt(), 0);
@ -66,7 +68,7 @@ private slots:
void shouldRespectDoubleValues() void shouldRespectDoubleValues()
{ {
SodepValue v1(0.42), v2; Value v1(0.42), v2;
QCOMPARE(v1.toDouble(), 0.42); QCOMPARE(v1.toDouble(), 0.42);
QCOMPARE(v2.toDouble(), 0.0); QCOMPARE(v2.toDouble(), 0.0);
@ -85,7 +87,7 @@ private slots:
void shouldRespectStringValues() void shouldRespectStringValues()
{ {
SodepValue v1("42"), v2; Value v1("42"), v2;
QCOMPARE(v1.toString(), QString("42")); QCOMPARE(v1.toString(), QString("42"));
QCOMPARE(v2.toString(), QString()); QCOMPARE(v2.toString(), QString());
@ -104,10 +106,10 @@ private slots:
void shouldHandleChildren() void shouldHandleChildren()
{ {
SodepValue v; Value v;
v.children("first") << SodepValue(7) << SodepValue(8); v.children("first") << Value(7) << Value(8);
v.children("second") << SodepValue(42); v.children("second") << Value(42);
QCOMPARE(v.children("second").size(), 1); QCOMPARE(v.children("second").size(), 1);
QCOMPARE(v.children("second")[0].toInt(), 42); QCOMPARE(v.children("second")[0].toInt(), 42);
@ -121,22 +123,22 @@ private slots:
void shouldBeSerializable_data() void shouldBeSerializable_data()
{ {
QTest::addColumn<SodepValue>("original"); QTest::addColumn<Value>("original");
QTest::addColumn<QByteArray>("serialized"); QTest::addColumn<QByteArray>("serialized");
QTest::newRow("empty value") << SodepValue() QTest::newRow("empty value") << Value()
<< QByteArray::fromHex("0000000000"); << QByteArray::fromHex("0000000000");
QTest::newRow("double value") << SodepValue(0.42) QTest::newRow("double value") << Value(0.42)
<< QByteArray::fromHex("033FDAE147AE147AE100000000"); << QByteArray::fromHex("033FDAE147AE147AE100000000");
QTest::newRow("int value") << SodepValue(42) QTest::newRow("int value") << Value(42)
<< QByteArray::fromHex("020000002A00000000"); << QByteArray::fromHex("020000002A00000000");
QTest::newRow("string value") << SodepValue("foo") QTest::newRow("string value") << Value("foo")
<< QByteArray::fromHex("0100000003")+QByteArray("foo") << QByteArray::fromHex("0100000003")+QByteArray("foo")
+ QByteArray::fromHex("00000000"); + QByteArray::fromHex("00000000");
SodepValue complex("complex"); Value complex("complex");
complex.children("foo") << SodepValue(42); complex.children("foo") << Value(42);
complex.children("bar") << SodepValue(0.42); complex.children("bar") << Value(0.42);
QTest::newRow("complex value") << complex QTest::newRow("complex value") << complex
<< QByteArray::fromHex("0100000007")+QByteArray("complex") << QByteArray::fromHex("0100000007")+QByteArray("complex")
+ QByteArray::fromHex("00000002") // two children + QByteArray::fromHex("00000002") // two children
@ -152,9 +154,9 @@ private slots:
{ {
QBuffer buffer; QBuffer buffer;
QFETCH(SodepValue, original); QFETCH(Value, original);
QFETCH(QByteArray, serialized); QFETCH(QByteArray, serialized);
SodepValue result; Value result;
buffer.open(QIODevice::WriteOnly); buffer.open(QIODevice::WriteOnly);
sodepWrite(buffer, original); sodepWrite(buffer, original);
@ -169,6 +171,6 @@ private slots:
} }
}; };
QTEST_MAIN(SodepValueTest) QTEST_MAIN(TestValue)
#include "sodepvaluetest.moc" #include "testvalue.moc"