summaryrefslogtreecommitdiff
path: root/tests/test-resource.cpp
blob: 49c43b06e17e54dcb8d7426c8222cd9069dcd8d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "test-resource.h"

using namespace ResourceTypes;

TestResource::TestResource()
    : isReservable(false)
{
}

TestResource::~TestResource()
{
}

void TestResource::init()
{
    resource = new Resource(MediaClass, AudioResource|VideoResource, this);
    resourceLibrary = new MockResourceLibrary(resource, false, false);
    QVERIFY(resource != NULL);
    QVERIFY(resource->applicationClass() == MediaClass);
    QVERIFY(resource->resources() == (AudioResource|VideoResource));
    QVERIFY(resource->isReserved() == false);
    QVERIFY(resource->hasResource(AudioResource));
    QVERIFY(resource->hasResource(VideoResource));
}

void TestResource::testApplicationClass()
{
    enum ResourceClass expected, actual;

    expected = MediaClass;
    actual = resource->applicationClass();

    QVERIFY(actual == expected);
}

void TestResource::testResources()
{
    quint16 expected, actual;

    expected = AudioResource|VideoResource;
    actual = resource->resources();

    QVERIFY(actual == expected);
}

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);
}

void TestResource::testConnectToServerSucceeds()
{
    bool initializeSucceeded = resource->initialize(resourceLibrary);

    QVERIFY(resource->resourceLibrary == resourceLibrary);
    QVERIFY(initializeSucceeded);

    bool connectToServerSucceeded = resource->connectToServer();
    QVERIFY(connectToServerSucceeded);
}

void TestResource::testConnectToServerFails()
{
    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);
}

// testStateChanged

void TestResource::testReservable()
{
    resource->initialize(resourceLibrary);
    resource->connectToServer();

    QObject::connect(resource, SIGNAL(reservable()), this, SLOT(handleReservable()));

    resource->emitReservable();

    QVERIFY(isReservable);
}

void TestResource::handleReservable()
{
    isReservable = true;
}

QTEST_MAIN(TestResource)