Newer
Older
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "coreinfo.h"
#include "emulator.h"
#include <sstream>
#include <fstream>
using namespace std;
using namespace ::testing;
struct EmulatorTestParam {
string system;
string rom;
};
class EmulatorTest : public TestWithParam<EmulatorTestParam> {
public:
virtual void SetUp() override;
};
struct EmulatorTestParamName {
string operator()(const TestParamInfo<EmulatorTestParam>& info) const {
return info.param.system;
}
};
void EmulatorTest::SetUp() {
ifstream in("../retro/cores.json");
ostringstream out;
Retro::corePath("../retro/cores");
while (!in.eof()) {
string line;
in >> line;
out << line;
}
Retro::loadCoreInfo(out.str().c_str());
}
namespace Retro {
TEST_F(EmulatorTest, Create) {
{
Emulator e;
EXPECT_FALSE(e.loadRom(""));
}
{
Emulator f;
EXPECT_FALSE(f.loadRom(""));
}
}
TEST_P(EmulatorTest, Load) {
const auto& param = GetParam();
Emulator e;
ASSERT_TRUE(e.loadRom("roms/" + param.rom));
EXPECT_EQ(e.core(), param.system);
e.run();
}
TEST_P(EmulatorTest, AutoUnload) {
const auto& param = GetParam();
{
Emulator e;
ASSERT_TRUE(e.loadRom("roms/" + param.rom));
e.run();
}
{
Emulator e;
ASSERT_TRUE(e.loadRom("roms/" + param.rom));
}
}
TEST_P(EmulatorTest, Unload) {
const auto& param = GetParam();
Emulator e;
ASSERT_TRUE(e.loadRom("roms/" + param.rom));
e.run();
e.unloadRom();
e.unloadCore();
}
TEST_P(EmulatorTest, UnloadOrder) {
const auto& param = GetParam();
Emulator e;
ASSERT_TRUE(e.loadRom("roms/" + param.rom));
e.run();
e.unloadCore();
e.unloadRom();
}
TEST_P(EmulatorTest, Output) {
const auto& param = GetParam();
Emulator e;
ASSERT_TRUE(e.loadRom("roms/" + param.rom));
e.run();
EXPECT_GT(e.getImageHeight(), 0);
EXPECT_GT(e.getImageWidth(), 0);
EXPECT_GT(e.getImagePitch(), 0);
EXPECT_GT(e.getImageDepth(), 0);
EXPECT_THAT(e.getImageData(), NotNull());
e.run();
e.run();
EXPECT_GT(e.getAudioSamples(), 0);
EXPECT_THAT(e.getAudioData(), NotNull());
}
TEST_P(EmulatorTest, States) {
const auto& param = GetParam();
Emulator e;
ASSERT_TRUE(e.loadRom("roms/" + param.rom));
EXPECT_GT(e.serializeSize(), 0);
ASSERT_NO_THROW(e.unserialize(static_cast<const void*>(""), 0));
ASSERT_NO_THROW(e.unserialize(NULL, 0));
EXPECT_FALSE(e.unserialize(static_cast<const void*>(""), 0));
vector<uint8_t> v;
e.run();
v.resize(e.serializeSize());
EXPECT_TRUE(e.serialize(v.data(), v.size()));
EXPECT_TRUE(e.unserialize(v.data(), v.size()));
e.run();
}
vector<EmulatorTestParam> s_systems{
{ "Genesis", "Dekadence-Dekadrive.md" },
{ "Atari2600", "automaton.a26" },
};
INSTANTIATE_TEST_CASE_P(EmulatorCore, EmulatorTest, ValuesIn(s_systems), EmulatorTestParamName());
TEST_F(EmulatorTest, HotSwap) {
Emulator e;
for (const auto& system : s_systems) {
ASSERT_TRUE(e.loadRom("roms/" + system.rom));
ASSERT_EQ(e.core(), system.system);
e.run();
e.unloadCore();
}
}
}