From 9504f0418dd0f3a9e6dff6034ffe36196c473a06 Mon Sep 17 00:00:00 2001 From: Wolf Bergenheim Date: Wed, 30 Dec 2009 16:00:09 +0200 Subject: Initial commit --- tests/mock-resource-library.cpp | 20 +++++++++++++++++++ tests/mock-resource-library.h | 19 ++++++++++++++++++ tests/test-resource.cpp | 44 +++++++++++++++++++++++++++++++++++++++++ tests/test-resource.h | 25 +++++++++++++++++++++++ tests/test-resource.pro | 21 ++++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 tests/mock-resource-library.cpp create mode 100644 tests/mock-resource-library.h create mode 100644 tests/test-resource.cpp create mode 100644 tests/test-resource.h create mode 100644 tests/test-resource.pro (limited to 'tests') 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 +#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(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 +#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 -- cgit v1.2.3