summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/mock-resource-library.cpp20
-rw-r--r--tests/mock-resource-library.h19
-rw-r--r--tests/test-resource.cpp44
-rw-r--r--tests/test-resource.h25
-rw-r--r--tests/test-resource.pro21
5 files changed, 129 insertions, 0 deletions
diff --git a/tests/mock-resource-library.cpp b/tests/mock-resource-library.cpp
new file mode 100644
index 0000000..4a4fdb4
--- /dev/null
+++ b/tests/mock-resource-library.cpp
@@ -0,0 +1,20 @@
+#include "mock-resource-library.h"
+
+MockResourceLibrary::MockResourceLibrary(QObject *parent, bool makeInitFail)
+ : QObject(parent), initializeFails(makeInitFail)
+{
+}
+
+MockResourceLibrary::~MockResourceLibrary()
+{
+}
+
+void MockResourceLibrary::makeInitializeFail()
+{
+ initializeFails=true;
+}
+
+bool MockResourceLibrary::initialize()
+{
+ return !initializeFails;
+}
diff --git a/tests/mock-resource-library.h b/tests/mock-resource-library.h
new file mode 100644
index 0000000..df6fd97
--- /dev/null
+++ b/tests/mock-resource-library.h
@@ -0,0 +1,19 @@
+#ifndef MOCK_RESOURCE_LIBRARY_H
+#define MOCK_RESOURCE_LIBRARY_H
+
+#include <QObject>
+#include "resource-library.h"
+
+class MockResourceLibrary: public QObject, public ResourceLibrary
+{
+ Q_OBJECT
+private:
+ bool initializeFails;
+public:
+ MockResourceLibrary(QObject *parent=0,bool makeInitFail=false);
+ virtual ~MockResourceLibrary();
+ void makeInitializeFail();
+ bool initialize();
+};
+
+#endif
diff --git a/tests/test-resource.cpp b/tests/test-resource.cpp
new file mode 100644
index 0000000..aae4dd5
--- /dev/null
+++ b/tests/test-resource.cpp
@@ -0,0 +1,44 @@
+#include "test-resource.h"
+TestResource::TestResource()
+{
+}
+
+TestResource::~TestResource()
+{
+}
+
+void TestResource::initTestCase()
+{
+ resource = new Resource(MediaClass, RP_FLAGS_AUDIO|RP_FLAGS_VIDEO, this);
+ resourceLibrary = new MockResourceLibrary(resource, false);
+}
+
+void TestResource::testConstructor()
+{
+ QVERIFY(resource != NULL);
+ QVERIFY(resource->resourceClass == MediaClass);
+ QVERIFY(resource->flags == (RP_FLAGS_AUDIO|RP_FLAGS_VIDEO));
+}
+
+void TestResource::testInitializeSucceeds()
+{
+ bool initializeSucceeded = resource->initialize(resourceLibrary);
+
+ QVERIFY(resource->resourceLibrary == resourceLibrary);
+ QVERIFY(initializeSucceeded);
+}
+
+void TestResource::testInitializeFails()
+{
+ MockResourceLibrary *mockResourceLibrary =
+ static_cast<MockResourceLibrary *>(resourceLibrary);
+ mockResourceLibrary->makeInitializeFail();
+
+ bool initializeSucceeded = resource->initialize(resourceLibrary);
+
+ QEXPECT_FAIL("", "Expecting resourceLibrary->initialize() to fail", Continue);
+ QVERIFY(initializeSucceeded);
+ delete resource;
+}
+
+QTEST_MAIN(TestResource)
diff --git a/tests/test-resource.h b/tests/test-resource.h
new file mode 100644
index 0000000..7d0bd7f
--- /dev/null
+++ b/tests/test-resource.h
@@ -0,0 +1,25 @@
+#ifndef TEST_RESOURCE_H
+#define TEST_RESOURCE_H
+
+#include <QtTest/QTest>
+#include "resource.h"
+#include "mock-resource-library.h"
+
+class TestResource: public QObject
+{
+ Q_OBJECT
+private:
+ ResourceLibrary *resourceLibrary;
+ Resource *resource;
+public:
+ TestResource();
+ ~TestResource();
+private slots:
+ void initTestCase();
+
+ void testConstructor();
+ void testInitializeSucceeds();
+ void testInitializeFails();
+};
+
+#endif
diff --git a/tests/test-resource.pro b/tests/test-resource.pro
new file mode 100644
index 0000000..3271864
--- /dev/null
+++ b/tests/test-resource.pro
@@ -0,0 +1,21 @@
+BASE = ..
+TEMPLATE = app
+TARGET = test-resource
+DESTDIR = build
+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
+
+OBJECTS_DIR = build
+MOC_DIR = build
+
+CONFIG += qt qtestlib debug warn_on
+QT -= gui
+
+# Install directives
+INSTALLBASE = /usr
+target.path = $$INSTALLBASE/share/libresourceqt/tests
+INSTALLS = target