summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-13 13:14:25 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-13 13:31:06 +0200
commitf482f4e2ebdff76d1818822fd98f7941787745d8 (patch)
tree901fe4211c2473bae735324abd50431497086bfa /tests
parentf15c9a9aaacfde28fe1275ec337f0ad96abe8851 (diff)
downloadlibresourceqt-f482f4e2ebdff76d1818822fd98f7941787745d8.tar.gz
Added tests for Resource::reserve()
Diffstat (limited to 'tests')
-rw-r--r--tests/mock-resource-library.cpp26
-rw-r--r--tests/mock-resource-library.h10
-rw-r--r--tests/test-resource.cpp50
-rw-r--r--tests/test-resource.h5
4 files changed, 83 insertions, 8 deletions
diff --git a/tests/mock-resource-library.cpp b/tests/mock-resource-library.cpp
index 49c29e4..565e745 100644
--- a/tests/mock-resource-library.cpp
+++ b/tests/mock-resource-library.cpp
@@ -1,11 +1,14 @@
#include "mock-resource-library.h"
-MockResourceLibrary::MockResourceLibrary(QObject *parent,
+MockResourceLibrary::MockResourceLibrary(Resource *resource,
bool makeInitializationFail,
- bool makeConnectingToServerFail)
- : QObject(parent), initializeFails(makeInitializationFail),
- connectToServerFails(makeConnectingToServerFail)
+ bool makeConnectingToServerFail,
+ bool makeReserveFail)
+ : QObject(resource), initializeFails(makeInitializationFail),
+ connectToServerFails(makeConnectingToServerFail),
+ reserveFails(makeReserveFail)
{
+ this->resource = resource;
}
MockResourceLibrary::~MockResourceLibrary()
@@ -37,3 +40,18 @@ bool MockResourceLibrary::connectToServer()
else
return false;
}
+
+bool MockResourceLibrary::reserve()
+{
+ if(!reserveFails) {
+ resource->handleStateChange(OwnedState);
+ }
+ else {
+ resource->handleStateChange(NotOwnedState);
+ }
+}
+
+void MockResourceLibrary::makeReserveFail()
+{
+ reserveFails = true;
+}
diff --git a/tests/mock-resource-library.h b/tests/mock-resource-library.h
index 6c743fe..1d3d17d 100644
--- a/tests/mock-resource-library.h
+++ b/tests/mock-resource-library.h
@@ -3,6 +3,7 @@
#include <QObject>
#include "resource-library.h"
+#include "resource.h"
class MockResourceLibrary: public QObject, public ResourceLibrary
{
@@ -10,14 +11,19 @@ class MockResourceLibrary: public QObject, public ResourceLibrary
private:
bool initializeFails;
bool connectToServerFails;
+ Resource *resource;
+ bool reserveFails;
public:
- MockResourceLibrary(QObject *parent=0,bool makeInitializationFail=false,
- bool makeConnectingToServerFail=false);
+ MockResourceLibrary(Resource *resource=0,bool makeInitializationFail=false,
+ bool makeConnectingToServerFail=false, bool makeReserveFail=false);
virtual ~MockResourceLibrary();
void makeInitializeFail();
void makeServerConnectFail();
bool initialize();
bool connectToServer();
+
+ bool reserve();
+ void makeReserveFail();
};
#endif
diff --git a/tests/test-resource.cpp b/tests/test-resource.cpp
index 49c43b0..5064df9 100644
--- a/tests/test-resource.cpp
+++ b/tests/test-resource.cpp
@@ -3,7 +3,7 @@
using namespace ResourceTypes;
TestResource::TestResource()
- : isReservable(false)
+ : isReservable(false), isReserved(false)
{
}
@@ -14,13 +14,15 @@ TestResource::~TestResource()
void TestResource::init()
{
resource = new Resource(MediaClass, AudioResource|VideoResource, this);
- resourceLibrary = new MockResourceLibrary(resource, false, false);
+ 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;
}
void TestResource::testApplicationClass()
@@ -110,4 +112,48 @@ void TestResource::handleReservable()
isReservable = true;
}
+void TestResource::testReserve()
+{
+ resource->initialize(resourceLibrary);
+ QObject::connect(resource, SIGNAL(stateChanged(enum ResourceState)),
+ this, SLOT(handleStateChanged(enum ResourceState)));
+ resource->connectToServer();
+
+ bool reserveSucceeds = resource->reserve();
+
+ QVERIFY(resource->isReserved());
+ QVERIFY(reserveSucceeds);
+ QVERIFY(isReserved);
+}
+
+void TestResource::testReserveExpectFail()
+{
+ MockResourceLibrary *mockResourceLibrary =
+ static_cast<MockResourceLibrary *>(resourceLibrary);
+
+ resource->initialize(resourceLibrary);
+ QObject::connect(resource, SIGNAL(stateChanged(enum ResourceState)),
+ this, SLOT(handleStateChanged(enum ResourceState)));
+ resource->connectToServer();
+
+ mockResourceLibrary->makeReserveFail();
+ bool reserveSucceeds = resource->reserve();
+
+ QVERIFY(reserveSucceeds);
+ QEXPECT_FAIL("", "Expecting resourceLibrary->reserve() to fail", Continue);
+ QVERIFY(isReserved);
+}
+
+void TestResource::handleStateChanged(enum ResourceState newState)
+{
+ switch(newState) {
+ case OwnedState:
+ isReserved = true;
+ break;
+ default:
+ isReserved = false;
+ break;
+ }
+}
+
QTEST_MAIN(TestResource)
diff --git a/tests/test-resource.h b/tests/test-resource.h
index 3d5a062..a762a8a 100644
--- a/tests/test-resource.h
+++ b/tests/test-resource.h
@@ -13,12 +13,14 @@ private:
Resource *resource;
bool isReservable;
+ bool isReserved;
public:
TestResource();
~TestResource();
public slots:
void handleReservable();
+ void handleStateChanged(enum ResourceState newState);
private slots:
void init();
@@ -33,6 +35,9 @@ private slots:
void testResources();
void testReservable();
+
+ void testReserve();
+ void testReserveExpectFail();
};
#endif