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

Run Approval tests with wav files #80

Merged
merged 4 commits into from
May 19, 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
12 changes: 10 additions & 2 deletions .github/workflows/test_verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,20 @@ jobs:

- name: Build
working-directory: ${{github.workspace}}/build
run: make OpenALpp_UnitTests OpenALpp_Integration -j 4
run: make OpenALpp_UnitTests OpenALpp_Integration OpenALpp_ApprovalTests -j

# - name: Test
# Commented out because one does not simply acquire a sound context
# run: ./OpenALpp_UnitTests --order rand
# working-directory: ${{github.workspace}}/build/bin/

# Do not run approval tests on clang as there seem to be some float inconsistencies happening
# - name: CopyAssets
# run: cp -r ${{github.workspace}}/assets ${{github.workspace}}/build/test/approval_tests
#
# - name: ApprovalTest
# run: ./OpenALpp_ApprovalTests --order rand
# working-directory: ${{github.workspace}}/build/test/approval_tests

Windows:
runs-on: windows-2019
steps:
Expand Down
Binary file added assets/test1.wav
Binary file not shown.
9 changes: 7 additions & 2 deletions test/approval_tests/approval_test_helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "approval_test_helpers.hpp"
#include <algorithm>

int ApprovalTestHelpers::asInt(float number, unsigned int digits)
std::vector<int> ApprovalTestHelpers::asInt(std::vector<float> const& numbers, unsigned int digits)
{
return static_cast<int>(number * digits);
std::vector<int> numbersAsInts;
numbersAsInts.resize(numbers.size());
std::transform(numbers.cbegin(), numbers.cend(), numbersAsInts.begin(), [digits](float number)
{return static_cast<int>(number * digits);});
return numbersAsInts;
}
4 changes: 2 additions & 2 deletions test/approval_tests/approval_test_helpers.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

#ifndef OPENALPP_APPROVAL_TEST_HELPERS_HPP
#define OPENALPP_APPROVAL_TEST_HELPERS_HPP
#include <vector>

struct ApprovalTestHelpers {
static int asInt(float number, unsigned int digits);
static std::vector<int> asInt(std::vector<float> const& number, unsigned int digits);
};

#endif // OPENALPP_APPROVAL_TEST_HELPERS_HPP
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
14 changes: 5 additions & 9 deletions test/approval_tests/effect_convolution_test.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
#include "ApprovalTests/ApprovalTests.hpp"
#include "approval_test_helpers.hpp"
#include "catch2/catch.hpp"
#include "oalpp/effects/utility/convolution.hpp"
#include "oalpp/sound_data.hpp"
#include "approval_test_helpers.hpp"

TEST_CASE("convolution")
{
std::string const fileName { "assets/test1.ogg" };
std::string const fileName { "assets/test1.wav" };
oalpp::SoundData buffer { fileName };
oalpp::effects::utility::Convolution convolution { buffer.getSamples() };
oalpp::SoundDataWithEffect soundWithEffect { buffer, convolution };

std::vector<int> values;
values.resize(soundWithEffect.getSamples().size());

std::transform(soundWithEffect.getSamples().cbegin(), soundWithEffect.getSamples().cend(),
values.begin(), [](float const value) { return ApprovalTestHelpers::asInt(value, 100); });

ApprovalTests::Approvals::verifyAll(values);
// note: Due to platform dependent float behavior, the result needs to be converted to int for
// the approval tests to work.
ApprovalTests::Approvals::verifyAll(ApprovalTestHelpers::asInt(soundWithEffect.getSamples(), 100));
}
23 changes: 4 additions & 19 deletions test/approval_tests/effect_gain_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "ApprovalTests/ApprovalTests.hpp"
#include "approval_test_helpers.hpp"
#include "catch2/catch.hpp"
#include "oalpp/effects/utility/gain.hpp"
#include "oalpp/sound_data.hpp"
Expand All @@ -8,34 +7,20 @@ TEST_CASE("gain")
{
SECTION("1.0")
{
std::string const fileName { "assets/test1.ogg" };
std::string const fileName { "assets/test1.wav" };
oalpp::effects::utility::Gain gain { 1.0f };
oalpp::SoundData buffer { fileName };
oalpp::SoundDataWithEffect soundWithEffect { buffer, gain };

std::vector<int> values;
values.resize(soundWithEffect.getSamples().size());

std::transform(soundWithEffect.getSamples().cbegin(), soundWithEffect.getSamples().cend(),
values.begin(),
[](float const value) { return ApprovalTestHelpers::asInt(value, 1000); });

ApprovalTests::Approvals::verifyAll(values);
ApprovalTests::Approvals::verifyAll(soundWithEffect.getSamples());
}
SECTION("2.0")
{
std::string const fileName { "assets/test1.ogg" };
std::string const fileName { "assets/test1.wav" };
oalpp::effects::utility::Gain gain { 2.0f };
oalpp::SoundData buffer { fileName };
oalpp::SoundDataWithEffect soundWithEffect { buffer, gain };

std::vector<int> values;
values.resize(soundWithEffect.getSamples().size());

std::transform(soundWithEffect.getSamples().cbegin(), soundWithEffect.getSamples().cend(),
values.begin(),
[](float const value) { return ApprovalTestHelpers::asInt(value, 100); });

ApprovalTests::Approvals::verifyAll(values);
ApprovalTests::Approvals::verifyAll(soundWithEffect.getSamples());
}
}
14 changes: 14 additions & 0 deletions test/approval_tests/effect_phase_flip_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "ApprovalTests/ApprovalTests.hpp"
#include "catch2/catch.hpp"
#include "oalpp/effects/utility/phase_flip.hpp"
#include "oalpp/sound_data.hpp"

TEST_CASE("phase_flip")
{
std::string const fileName { "assets/test1.wav" };
oalpp::SoundData buffer { fileName };
oalpp::effects::utility::PhaseFlip phaseFlip { };
oalpp::SoundDataWithEffect soundWithEffect { buffer, phaseFlip };

ApprovalTests::Approvals::verifyAll(soundWithEffect.getSamples());
}