-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathmic_source_test.cpp
More file actions
122 lines (103 loc) · 3.66 KB
/
Copy pathmic_source_test.cpp
File metadata and controls
122 lines (103 loc) · 3.66 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
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
/* Copyright (C) 2023 Michal Kosciesza <michal@mkiol.net>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#define private public
#include <catch2/catch_test_macros.hpp>
#include <QCoreApplication>
#include <QTimer>
#include <memory>
#include "../src/mic_source.h"
TEST_CASE("mic_source", "[stop]") {
int argc = 0;
char* argv[] = {nullptr};
QCoreApplication app(argc, argv);
SECTION("immediate stop after creation") {
bool has_audio = false;
try {
auto mic = std::make_unique<mic_source>("");
has_audio = mic->ok();
if (has_audio) {
// Stop immediately
mic->stop();
// Verify internal state
REQUIRE(mic->m_stopped == true);
REQUIRE(mic->m_eof == true);
REQUIRE(mic->m_audio_device == nullptr);
}
} catch (const std::exception& e) {
// No audio device available in test environment
WARN("No audio device available: " << e.what());
}
}
SECTION("stop prevents double-stop") {
bool has_audio = false;
try {
auto mic = std::make_unique<mic_source>("");
has_audio = mic->ok();
if (has_audio) {
// Call stop twice
mic->stop();
mic->stop(); // Should return early
// Verify state is still correct
REQUIRE(mic->m_stopped == true);
REQUIRE(mic->m_eof == true);
REQUIRE(mic->m_audio_device == nullptr);
}
} catch (const std::exception& e) {
// No audio device available in test environment
WARN("No audio device available: " << e.what());
}
}
SECTION("read_audio after stop returns EOF") {
bool has_audio = false;
try {
auto mic = std::make_unique<mic_source>("");
has_audio = mic->ok();
if (has_audio) {
mic->stop();
// Try to read audio
char buf[1024];
auto data = mic->read_audio(buf, sizeof(buf));
// Should return EOF
REQUIRE(data.eof == true);
REQUIRE(mic->m_ended == true);
}
} catch (const std::exception& e) {
// No audio device available in test environment
WARN("No audio device available: " << e.what());
}
}
SECTION("clear after stop doesn't crash") {
bool has_audio = false;
try {
auto mic = std::make_unique<mic_source>("");
has_audio = mic->ok();
if (has_audio) {
mic->stop();
// Should not crash
REQUIRE_NOTHROW(mic->clear());
}
} catch (const std::exception& e) {
// No audio device available in test environment
WARN("No audio device available: " << e.what());
}
}
SECTION("destructor after stop doesn't crash") {
bool has_audio = false;
try {
auto mic = std::make_unique<mic_source>("");
has_audio = mic->ok();
if (has_audio) {
mic->stop();
// Destructor will be called when mic goes out of scope
REQUIRE_NOTHROW(mic.reset());
}
} catch (const std::exception& e) {
// No audio device available in test environment
WARN("No audio device available: " << e.what());
}
}
}