Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code coverage #75

Merged
merged 6 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test_verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
# working-directory: ${{github.workspace}}/build/bin/

Windows:
runs-on: windows-latest
runs-on: windows-2019
steps:
- name: Set up cmake
uses: jwlawson/actions-setup-cmake@v1.11
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

CoverageReport-*/
# Created by https://www.gitignore.io/api/c++,cmake,visualstudio
# Edit at https://www.gitignore.io/?templates=c++,cmake,visualstudio

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ How to build
3. `cmake ..`
4. `cmake --build . --target OpenALpp_Lib`

How to measure Code Coverage with [OpenCppCoverage](https://github.com/OpenCppCoverage/OpenCppCoverage)
-----------

```
OpenCppCoverage.exe
--sources <absolute path>\OpenALpp\impl\
--excluded_sources <absolute path>\OpenALpp\test\
--excluded_sources <absolute path>\OpenALpp\ext*
--excluded_sources <absolute path>\OpenALpp\cmake-build-debug*
.\path\to\unit_tests\OpenALpp_UnitTests.exe
```

Code Example
----------

Expand Down
12 changes: 6 additions & 6 deletions test/unit_tests/sound_data_channel_conversion_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ TEST_CASE("SoundDataRightToMono", "[SoundConversion]")

SECTION("Raises exception on mono data")
{
SoundDataMonoFake fakeStereo {};
REQUIRE_THROWS(SoundDataLeftToMono { fakeStereo });
SoundDataMonoFake fakeMono {};
REQUIRE_THROWS(SoundDataRightToMono { fakeMono });
}
}

Expand Down Expand Up @@ -131,8 +131,8 @@ TEST_CASE("SoundDataMidToMono", "[SoundConversion]")

SECTION("Raises exception on mono data")
{
SoundDataMonoFake fakeStereo {};
REQUIRE_THROWS(SoundDataLeftToMono { fakeStereo });
SoundDataMonoFake fakeMono {};
REQUIRE_THROWS(SoundDataMidToMono { fakeMono });
}
}

Expand Down Expand Up @@ -163,7 +163,7 @@ TEST_CASE("SoundDataSideToMono", "[SoundConversion]")

SECTION("Raises exception on mono data")
{
SoundDataMonoFake fakeStereo {};
REQUIRE_THROWS(SoundDataLeftToMono { fakeStereo });
SoundDataMonoFake fakeMono {};
REQUIRE_THROWS(SoundDataSideToMono { fakeMono });
}
}
15 changes: 15 additions & 0 deletions test/unit_tests/sound_effects_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ TEST_CASE("SoundEffect returns zero on zero input", "[SoundEffect]")
inputVector.resize(numberOfSamples);
REQUIRE(chain.process(inputVector) == inputVector);
}

SECTION("convolution")
{
auto const numberOfSamples = 10000u;
std::vector<float> samples;
samples.resize(numberOfSamples);
oalpp::effects::utility::Convolution convolution { samples };

std::vector<float> inputVector;
inputVector.resize(numberOfSamples);

auto const result = convolution.process(inputVector);
REQUIRE(std::all_of(result.cbegin(), result.cend(), [](float f) { return f == 0.0f; })
== true);
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions test/unit_tests/sound_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,28 @@ TEST_CASE("Sound getCurrentPosition", "[Sound]")
}
}
}

SECTION("update with looping sound does not raise exception")
{
fake.m_samples.resize(262144 + 200);
Sound snd { fake };
snd.setIsLooping(true);
snd.play();
auto const start = std::chrono::system_clock::now();
while (snd.isPlaying()) {
snd.update();
auto const newValue = snd.getCurrentOffsetInSeconds();
auto const now = std::chrono::system_clock::now();
float const elapsedSeconds
= std::chrono::duration_cast<std::chrono::microseconds>(now - start).count()
/ 1000.0f / 1000.0f;

if (elapsedSeconds >= 6.0f) {
snd.pause();
break;
}
}
}
}

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