2009-02-08 16:35:56 +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 <QtTest/QtTest>
|
|
|
|
|
2009-04-25 16:06:25 +02:00
|
|
|
#include <QtJolie/Fault>
|
2009-04-25 15:50:35 +02:00
|
|
|
#include "testhelpers.h"
|
2009-02-08 16:35:56 +01:00
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
using namespace Jolie;
|
|
|
|
|
|
|
|
class TestFault : public QObject
|
2009-02-08 16:35:56 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void shouldHandleInvalids()
|
|
|
|
{
|
2009-04-25 15:50:35 +02:00
|
|
|
Fault f;
|
2009-02-08 16:35:56 +01:00
|
|
|
|
2009-05-30 10:44:34 +02:00
|
|
|
QCOMPARE(f.name(), QByteArray());
|
2009-02-08 16:35:56 +01:00
|
|
|
QVERIFY(!f.data().isValid());
|
|
|
|
|
|
|
|
QVERIFY(!f.isValid());
|
|
|
|
}
|
|
|
|
void shouldVerifyInitialState()
|
|
|
|
{
|
2009-04-25 15:50:35 +02:00
|
|
|
Fault f1("blup"), f2("blop", Value(42));
|
2009-02-08 16:35:56 +01:00
|
|
|
|
2009-05-30 10:44:34 +02:00
|
|
|
QCOMPARE(f1.name(), QByteArray("blup"));
|
2009-02-08 16:35:56 +01:00
|
|
|
QVERIFY(!f1.data().isValid());
|
|
|
|
|
2009-05-30 10:44:34 +02:00
|
|
|
QCOMPARE(f2.name(), QByteArray("blop"));
|
2009-02-08 16:35:56 +01:00
|
|
|
QVERIFY(f2.data().isValid());
|
|
|
|
QCOMPARE(f2.data().toInt(), 42);
|
|
|
|
|
|
|
|
f1 = f2;
|
|
|
|
|
2009-05-30 10:44:34 +02:00
|
|
|
QCOMPARE(f1.name(), QByteArray("blop"));
|
2009-02-08 16:35:56 +01:00
|
|
|
QVERIFY(f1.data().isValid());
|
|
|
|
QCOMPARE(f1.data().toInt(), 42);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shouldBeSerializable_data()
|
|
|
|
{
|
2009-04-25 15:50:35 +02:00
|
|
|
Value v(42);
|
2009-02-08 16:35:56 +01:00
|
|
|
QByteArray vSerial = QByteArray::fromHex("020000002A00000000");
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
QTest::addColumn<Fault>("original");
|
2009-02-08 16:35:56 +01:00
|
|
|
QTest::addColumn<QByteArray>("serialized");
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
QTest::newRow("empty fault") << Fault()
|
2009-02-08 16:35:56 +01:00
|
|
|
<< QByteArray::fromHex("00");
|
2009-04-25 15:50:35 +02:00
|
|
|
QTest::newRow("no value fault") << Fault("foo")
|
2009-02-08 16:35:56 +01:00
|
|
|
<< QByteArray::fromHex("0100000003")+QByteArray("foo")
|
|
|
|
+ QByteArray::fromHex("0000000000");
|
2009-04-25 15:50:35 +02:00
|
|
|
QTest::newRow("value fault") << Fault("bar", v)
|
2009-02-08 16:35:56 +01:00
|
|
|
<< QByteArray::fromHex("0100000003")+QByteArray("bar")
|
|
|
|
+ vSerial;
|
|
|
|
}
|
|
|
|
|
|
|
|
void shouldBeSerializable()
|
|
|
|
{
|
|
|
|
QBuffer buffer;
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
QFETCH(Fault, original);
|
2009-02-08 16:35:56 +01:00
|
|
|
QFETCH(QByteArray, serialized);
|
2009-04-25 15:50:35 +02:00
|
|
|
Fault result;
|
2009-02-08 16:35:56 +01:00
|
|
|
|
|
|
|
buffer.open(QIODevice::WriteOnly);
|
|
|
|
sodepWrite(buffer, original);
|
|
|
|
buffer.close();
|
|
|
|
|
|
|
|
buffer.open(QIODevice::ReadOnly);
|
|
|
|
result = sodepReadFault(buffer);
|
|
|
|
buffer.close();
|
|
|
|
|
|
|
|
sodepCompare(result, original);
|
|
|
|
QCOMPARE(buffer.data(), serialized);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
QTEST_MAIN(TestFault)
|
2009-02-08 16:35:56 +01:00
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
#include "testfault.moc"
|