summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-21 09:56:07 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-21 09:56:38 +0200
commitdef881f37f26d6f3b9bf1a9c077dae4916717157 (patch)
tree6b378f9c7de325ad8d3bfb57b1e5d354d7e529fa /tests
parentf482f4e2ebdff76d1818822fd98f7941787745d8 (diff)
downloadlibresourceqt-def881f37f26d6f3b9bf1a9c077dae4916717157.tar.gz
Refactored Resource
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile1
-rw-r--r--tests/test-resource.cpp183
-rw-r--r--tests/test-resource.h30
-rw-r--r--tests/test-resource.pro4
4 files changed, 98 insertions, 120 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 8c9ab42..20ae9ef 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,5 +1,6 @@
QMAKE = qmake
MAKEFILES = $(patsubst %.pro,%.make,$(wildcard *.pro))
+MAKEOVERRIDES =
%.make: %.pro
$(QMAKE) -o $@ $<
diff --git a/tests/test-resource.cpp b/tests/test-resource.cpp
index 5064df9..bc72957 100644
--- a/tests/test-resource.cpp
+++ b/tests/test-resource.cpp
@@ -1,9 +1,6 @@
#include "test-resource.h"
-using namespace ResourceTypes;
-
TestResource::TestResource()
- : isReservable(false), isReserved(false)
{
}
@@ -13,147 +10,129 @@ TestResource::~TestResource()
void TestResource::init()
{
- resource = new Resource(MediaClass, AudioResource|VideoResource, this);
- resourceLibrary = new MockResourceLibrary(resource);
- QVERIFY(resource != NULL);
- QVERIFY(resource->applicationClass() == MediaClass);
- QVERIFY(resource->resources() == (AudioResource|VideoResource));
- QVERIFY(resource->isReserved() == false);
- QVERIFY(resource->hasResource(AudioResource));
- QVERIFY(resource->hasResource(VideoResource));
- isReservable =false;
- isReserved = false;
+ resource = new Resource();
}
-void TestResource::testApplicationClass()
+void TestResource::cleanup()
{
- enum ResourceClass expected, actual;
-
- expected = MediaClass;
- actual = resource->applicationClass();
-
- QVERIFY(actual == expected);
+ delete resource;
}
-void TestResource::testResources()
+void TestResource::testType_data()
{
- quint16 expected, actual;
-
- expected = AudioResource|VideoResource;
- actual = resource->resources();
-
- QVERIFY(actual == expected);
+ QTest::addColumn<QString>("type");
+ QTest::addColumn<QString>("expected");
+
+ QTest::newRow("AudioPlayback") << "AudioPlayback" << "AudioPlayback";
+ QTest::newRow("VideoPlayback") << "VideoPlayback" << "VideoPlayback";
+ QTest::newRow("AudioRecording") << "AudioRecording" << "AudioRecording";
+ QTest::newRow("VideoRecording") << "VideoRecording" << "VideoRecording";
+ QTest::newRow("Invalid") << "Invalid" << "Invalid";
+ QTest::newRow("Empty") << "" << "";
+ QTest::newRow("Null") << QString() << QString();
}
-
-void TestResource::testInitializeSucceeds()
+void TestResource::testType()
{
- bool initializeSucceeded = resource->initialize(resourceLibrary);
+ QFETCH(QString, type);
+ QFETCH(QString, expected);
+ resource->setType(type);
+ QString result = resource->type();
- QVERIFY(resource->resourceLibrary == resourceLibrary);
- QVERIFY(initializeSucceeded);
+ QCOMPARE(result, expected);
}
-void TestResource::testInitializeFails()
+void TestResource::testOptional_data()
{
- MockResourceLibrary *mockResourceLibrary =
- static_cast<MockResourceLibrary *>(resourceLibrary);
- mockResourceLibrary->makeInitializeFail();
-
- bool initializeSucceeded = resource->initialize(resourceLibrary);
-
- QEXPECT_FAIL("", "Expecting resourceLibrary->initialize() to fail", Continue);
- QVERIFY(initializeSucceeded);
+ QTest::addColumn<bool>("optional");
+ QTest::addColumn<bool>("expected");
+
+ QTest::newRow("Resource is optional") << true << true;
+ QTest::newRow("Resource is not optional") << false << false;
}
-void TestResource::testConnectToServerSucceeds()
+void TestResource::testOptional()
{
- bool initializeSucceeded = resource->initialize(resourceLibrary);
+ QFETCH(bool, optional);
+ QFETCH(bool, expected);
- QVERIFY(resource->resourceLibrary == resourceLibrary);
- QVERIFY(initializeSucceeded);
+ resource->setOptional(optional);
+ bool result = resource->isOptional();
- bool connectToServerSucceeded = resource->connectToServer();
- QVERIFY(connectToServerSucceeded);
+ QCOMPARE(result, expected);
}
-void TestResource::testConnectToServerFails()
+void TestResource::testShared_data()
{
- MockResourceLibrary *mockResourceLibrary =
- static_cast<MockResourceLibrary *>(resourceLibrary);
-
- bool initializeSucceeded = resource->initialize(resourceLibrary);
-
- QVERIFY(resource->resourceLibrary == resourceLibrary);
- QVERIFY(initializeSucceeded);
-
- mockResourceLibrary->makeServerConnectFail();
- bool connectToServerSucceeded = resource->connectToServer();
-
- QEXPECT_FAIL("", "Expecting resourceLibrary->connectToServer() to fail", Continue);
- QVERIFY(connectToServerSucceeded);
+ QTest::addColumn<bool>("optional");
+ QTest::addColumn<bool>("expected");
+
+ QTest::newRow("Resource is shared") << true << true;
+ QTest::newRow("Resource is not hhared") << false << false;
}
-// testStateChanged
-
-void TestResource::testReservable()
+void TestResource::testShared()
{
- resource->initialize(resourceLibrary);
- resource->connectToServer();
+ QFETCH(bool, optional);
+ QFETCH(bool, expected);
- QObject::connect(resource, SIGNAL(reservable()), this, SLOT(handleReservable()));
+ resource->setShared(optional);
+ bool result = resource->isShared();
- resource->emitReservable();
-
- QVERIFY(isReservable);
+ QCOMPARE(result, expected);
}
-void TestResource::handleReservable()
+void TestResource::testIdentifier_data()
{
- isReservable = true;
+ QTest::addColumn<quint32>("identifier");
+ QTest::addColumn<quint32>("expected");
+
+ QTest::newRow("Set identifier") << (quint32)this << (quint32)this;
+ QTest::newRow("Set to 0") << 0U << 0U;
}
-void TestResource::testReserve()
+void TestResource::testIdentifier()
{
- resource->initialize(resourceLibrary);
- QObject::connect(resource, SIGNAL(stateChanged(enum ResourceState)),
- this, SLOT(handleStateChanged(enum ResourceState)));
- resource->connectToServer();
+ QFETCH(quint32, identifier);
+ QFETCH(quint32, expected);
- bool reserveSucceeds = resource->reserve();
+ resource->setId(identifier);
+ quint32 result = resource->id();
- QVERIFY(resource->isReserved());
- QVERIFY(reserveSucceeds);
- QVERIFY(isReserved);
+ QCOMPARE(result, expected);
}
-void TestResource::testReserveExpectFail()
+void TestResource::testCopy()
{
- MockResourceLibrary *mockResourceLibrary =
- static_cast<MockResourceLibrary *>(resourceLibrary);
+ Resource copy;
+ resource->setOptional();
- resource->initialize(resourceLibrary);
- QObject::connect(resource, SIGNAL(stateChanged(enum ResourceState)),
- this, SLOT(handleStateChanged(enum ResourceState)));
- resource->connectToServer();
+ copy = *resource;
- mockResourceLibrary->makeReserveFail();
- bool reserveSucceeds = resource->reserve();
+ QCOMPARE(copy.id(), resource->id());
+ QCOMPARE(copy.isOptional(), resource->isOptional());
+ QCOMPARE(copy.isShared(), resource->isShared());
+ QCOMPARE(copy.type(), resource->type());
+}
- QVERIFY(reserveSucceeds);
- QEXPECT_FAIL("", "Expecting resourceLibrary->reserve() to fail", Continue);
- QVERIFY(isReserved);
+void TestResource::testCopyConstructor()
+{
+ resource->setOptional();
+ Resource copy(*resource);
+
+ QCOMPARE(copy.id(), resource->id());
+ QCOMPARE(copy.isOptional(), resource->isOptional());
+ QCOMPARE(copy.isShared(), resource->isShared());
+ QCOMPARE(copy.type(), resource->type());
}
-void TestResource::handleStateChanged(enum ResourceState newState)
+void TestResource::testEqualsOperator()
{
- switch(newState) {
- case OwnedState:
- isReserved = true;
- break;
- default:
- isReserved = false;
- break;
- }
+ Resource copy;
+ resource->setOptional();
+
+ copy = *resource;
+
+ QVERIFY(copy == *resource);
}
QTEST_MAIN(TestResource)
diff --git a/tests/test-resource.h b/tests/test-resource.h
index a762a8a..e55e2af 100644
--- a/tests/test-resource.h
+++ b/tests/test-resource.h
@@ -3,41 +3,39 @@
#include <QtTest/QTest>
#include "resource.h"
-#include "mock-resource-library.h"
class TestResource: public QObject
{
Q_OBJECT
private:
- ResourceLibrary *resourceLibrary;
Resource *resource;
- bool isReservable;
- bool isReserved;
public:
TestResource();
~TestResource();
-public slots:
- void handleReservable();
- void handleStateChanged(enum ResourceState newState);
private slots:
+
void init();
+ void cleanup();
- void testInitializeSucceeds();
- void testInitializeFails();
+ void testType_data();
+ void testType();
+
+ void testOptional_data();
+ void testOptional();
- void testConnectToServerSucceeds();
- void testConnectToServerFails();
+ void testShared_data();
+ void testShared();
- void testApplicationClass();
- void testResources();
+ void testIdentifier_data();
+ void testIdentifier();
- void testReservable();
+ void testCopy();
+ void testCopyConstructor();
- void testReserve();
- void testReserveExpectFail();
+ void testEqualsOperator();
};
#endif
diff --git a/tests/test-resource.pro b/tests/test-resource.pro
index 3271864..bb4da4c 100644
--- a/tests/test-resource.pro
+++ b/tests/test-resource.pro
@@ -6,8 +6,8 @@ DEPENDPATH += $${BASE}/include $${BASE}/src .
INCLUDEPATH += $${BASE}/src $${BASE}/include
# Input
-HEADERS += $${BASE}/include/resource.h test-resource.h mock-resource-library.h
-SOURCES += $${BASE}/src/resource.cpp test-resource.cpp mock-resource-library.cpp
+HEADERS += $${BASE}/include/resource.h test-resource.h
+SOURCES += $${BASE}/src/resource.cpp test-resource.cpp
OBJECTS_DIR = build
MOC_DIR = build