-
Notifications
You must be signed in to change notification settings - Fork 0
/
SdlHardwareLayerTest.h
69 lines (56 loc) · 1.55 KB
/
SdlHardwareLayerTest.h
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
#include <CppUTest/TestHarness.h>
#include "sdl.h"
#include "SdlLayerFactory.h"
#include "SdlHardwareLayer.h"
#include "TestDoubleSdlLayerInstanceDelegator.h"
TEST_GROUP(SdlHardwareLayerTest) {
virtual void setup() {
original = SdlLayerFactory::getInstance();
layer = new SdlHardwareLayer;
}
virtual void teardown() {
if(SdlLayerFactory::getInstance() != original)
delete SdlLayerFactory::getInstance();
SdlLayerFactory::replaceInstance(original);
delete layer;
}
SdlLayerInstanceDelegator *original;
SdlHardwareLayer *layer;
};
struct MajorMinorSdlhardwareLayer : public TestDoubleSdlLayerInstanceDelegator {
struct SDL_version v;
MajorMinorSdlhardwareLayer() {
v.major = 0;
v.minor = 0;
}
const SDL_version *SDL_Linked_Version() {
return &v;
}
};
TEST(SdlHardwareLayerTest, ItGeneratsErrorWithLowMajorMinorVersionNumber) {
SdlLayerFactory::replaceInstance(new MajorMinorSdlhardwareLayer);
try {
layer->initializeHardware();
FAIL("Should have thrown int value");
} catch (int value) {
LONGS_EQUAL(1, value);
}
}
struct InitFailingSdlHardwareLayer : public MajorMinorSdlhardwareLayer {
InitFailingSdlHardwareLayer () {
v.major = 3;
v.minor = 3;
}
int SDL_Init(int bitMask) {
return -1;
}
};
TEST(SdlHardwareLayerTest, ItGeneratesErrorWhenInitReturnsLessThan0) {
SdlLayerFactory::replaceInstance(new InitFailingSdlHardwareLayer);
try {
layer->initializeHardware();
FAIL("Should have thrown int value");
} catch (int value) {
LONGS_EQUAL(2, value);
}
}