-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_tests.cpp
More file actions
56 lines (43 loc) · 1.08 KB
/
Copy pathaudio_tests.cpp
File metadata and controls
56 lines (43 loc) · 1.08 KB
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
#include <catch2/catch_test_macros.hpp>
#include <chrono>
int g_start_calls = 0;
int g_stop_calls = 0;
#include "stubs/miniaudio.h"
#include "stubs/dr_flac.h"
#define private public
#include "audio/engine.cpp"
#undef private
struct AudioTestAccess {
static std::vector<lizard::audio::Engine::Voice> &voices(lizard::audio::Engine &e) {
return e.m_voices;
}
};
TEST_CASE("max_concurrent_playbacks respected", "[audio]") {
lizard::audio::Engine eng;
AudioTestAccess::voices(eng).resize(16);
g_start_calls = 0;
g_stop_calls = 0;
for (int i = 0; i < 17; ++i) {
eng.play();
}
REQUIRE(g_start_calls == 17);
REQUIRE(g_stop_calls == 1);
int playing = 0;
for (auto &v : AudioTestAccess::voices(eng)) {
if (ma_sound_is_playing(&v.sound)) {
playing++;
}
}
REQUIRE(playing == 16);
}
TEST_CASE("play retriggers immediately", "[audio]") {
lizard::audio::Engine eng(1);
AudioTestAccess::voices(eng).resize(1);
g_start_calls = 0;
g_stop_calls = 0;
eng.play();
eng.play();
eng.play();
REQUIRE(g_start_calls == 3);
REQUIRE(g_stop_calls == 2);
}