Skip to content

Commit 17321dc

Browse files
authored
Merge pull request #75 from Laguna1989/FEATURE_CodeCoverage
Improve code coverage
2 parents f44ecd0 + e7d4117 commit 17321dc

6 files changed

Lines changed: 57 additions & 8 deletions

File tree

.github/workflows/test_verification.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
# working-directory: ${{github.workspace}}/build/bin/
8787

8888
Windows:
89-
runs-on: windows-latest
89+
runs-on: windows-2019
9090
steps:
9191
- name: Set up cmake
9292
uses: jwlawson/actions-setup-cmake@v1.11

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
CoverageReport-*/
22
# Created by https://www.gitignore.io/api/c++,cmake,visualstudio
33
# Edit at https://www.gitignore.io/?templates=c++,cmake,visualstudio
44

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ How to build
1515
3. `cmake ..`
1616
4. `cmake --build . --target OpenALpp_Lib`
1717

18+
How to measure Code Coverage with [OpenCppCoverage](https://github.com/OpenCppCoverage/OpenCppCoverage)
19+
-----------
20+
21+
```
22+
OpenCppCoverage.exe
23+
--sources <absolute path>\OpenALpp\impl\
24+
--excluded_sources <absolute path>\OpenALpp\test\
25+
--excluded_sources <absolute path>\OpenALpp\ext*
26+
--excluded_sources <absolute path>\OpenALpp\cmake-build-debug*
27+
.\path\to\unit_tests\OpenALpp_UnitTests.exe
28+
```
29+
1830
Code Example
1931
----------
2032

test/unit_tests/sound_data_channel_conversion_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ TEST_CASE("SoundDataRightToMono", "[SoundConversion]")
9999

100100
SECTION("Raises exception on mono data")
101101
{
102-
SoundDataMonoFake fakeStereo {};
103-
REQUIRE_THROWS(SoundDataLeftToMono { fakeStereo });
102+
SoundDataMonoFake fakeMono {};
103+
REQUIRE_THROWS(SoundDataRightToMono { fakeMono });
104104
}
105105
}
106106

@@ -131,8 +131,8 @@ TEST_CASE("SoundDataMidToMono", "[SoundConversion]")
131131

132132
SECTION("Raises exception on mono data")
133133
{
134-
SoundDataMonoFake fakeStereo {};
135-
REQUIRE_THROWS(SoundDataLeftToMono { fakeStereo });
134+
SoundDataMonoFake fakeMono {};
135+
REQUIRE_THROWS(SoundDataMidToMono { fakeMono });
136136
}
137137
}
138138

@@ -163,7 +163,7 @@ TEST_CASE("SoundDataSideToMono", "[SoundConversion]")
163163

164164
SECTION("Raises exception on mono data")
165165
{
166-
SoundDataMonoFake fakeStereo {};
167-
REQUIRE_THROWS(SoundDataLeftToMono { fakeStereo });
166+
SoundDataMonoFake fakeMono {};
167+
REQUIRE_THROWS(SoundDataSideToMono { fakeMono });
168168
}
169169
}

test/unit_tests/sound_effects_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ TEST_CASE("SoundEffect returns zero on zero input", "[SoundEffect]")
9595
inputVector.resize(numberOfSamples);
9696
REQUIRE(chain.process(inputVector) == inputVector);
9797
}
98+
99+
SECTION("convolution")
100+
{
101+
auto const numberOfSamples = 10000u;
102+
std::vector<float> samples;
103+
samples.resize(numberOfSamples);
104+
oalpp::effects::utility::Convolution convolution { samples };
105+
106+
std::vector<float> inputVector;
107+
inputVector.resize(numberOfSamples);
108+
109+
auto const result = convolution.process(inputVector);
110+
REQUIRE(std::all_of(result.cbegin(), result.cend(), [](float f) { return f == 0.0f; })
111+
== true);
112+
}
98113
}
99114
}
100115

test/unit_tests/sound_test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,28 @@ TEST_CASE("Sound getCurrentPosition", "[Sound]")
399399
}
400400
}
401401
}
402+
403+
SECTION("update with looping sound does not raise exception")
404+
{
405+
fake.m_samples.resize(262144 + 200);
406+
Sound snd { fake };
407+
snd.setIsLooping(true);
408+
snd.play();
409+
auto const start = std::chrono::system_clock::now();
410+
while (snd.isPlaying()) {
411+
snd.update();
412+
auto const newValue = snd.getCurrentOffsetInSeconds();
413+
auto const now = std::chrono::system_clock::now();
414+
float const elapsedSeconds
415+
= std::chrono::duration_cast<std::chrono::microseconds>(now - start).count()
416+
/ 1000.0f / 1000.0f;
417+
418+
if (elapsedSeconds >= 6.0f) {
419+
snd.pause();
420+
break;
421+
}
422+
}
423+
}
402424
}
403425

404426
TEST_CASE("Sound Constructor without SoundContext raises exception", "[Sound]")

0 commit comments

Comments
 (0)