-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from Laguna1989/FEATURE_ApprovalTestsForEffects
Approval tests for effects
- Loading branch information
Showing
18 changed files
with
152 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test/approval_tests/approval_tests/* filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
message(STATUS "Fetching approvaltests") | ||
include(FetchContent) | ||
|
||
FetchContent_Declare( | ||
approvaltests | ||
GIT_REPOSITORY https://github.com/approvals/ApprovalTests.cpp | ||
GIT_TAG v.10.12.2 | ||
) | ||
FetchContent_MakeAvailable(approvaltests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
if (OALPP_ENABLE_INTEGRATION_TESTS) | ||
add_subdirectory(integration) | ||
add_subdirectory(integration_tests) | ||
endif () | ||
|
||
if (OALPP_ENABLE_UNIT_TESTS) | ||
add_subdirectory(unit_tests) | ||
endif () | ||
|
||
if (OALPP_ENABLE_APPROVAL_TESTS) | ||
add_subdirectory(approval_tests) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
file(GLOB TESTFILES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
add_executable(OpenALpp_ApprovalTests ${TESTFILES}) | ||
|
||
target_link_libraries(OpenALpp_ApprovalTests PRIVATE | ||
OpenALpp_Lib | ||
ApprovalTests::ApprovalTests | ||
Catch2::Catch2) | ||
|
||
FetchContent_GetProperties(catch2) | ||
FetchContent_GetProperties(approvaltests) | ||
|
||
target_include_directories(OpenALpp_ApprovalTests PUBLIC | ||
${catch2_SOURCE_DIR}/include | ||
${approvaltests_SOURCE_DIR}) | ||
|
||
if (NOT OALPP_STATIC_LIBRARY) | ||
message(WARNING "Building OpenALpp unit tests with dynamic library: dll/so will not be copied by default.") | ||
endif () | ||
|
||
add_test(NAME OpenALpp_ApprovalTests COMMAND OpenALpp_ApprovalTests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "approval_test_helpers.hpp" | ||
|
||
int ApprovalTestHelpers::asInt(float number, unsigned int digits) | ||
{ | ||
return static_cast<int>(number * digits); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
#ifndef OPENALPP_APPROVAL_TEST_HELPERS_HPP | ||
#define OPENALPP_APPROVAL_TEST_HELPERS_HPP | ||
|
||
struct ApprovalTestHelpers { | ||
static int asInt(float number, unsigned int digits); | ||
}; | ||
|
||
#endif // OPENALPP_APPROVAL_TEST_HELPERS_HPP |
3 changes: 3 additions & 0 deletions
3
test/approval_tests/approval_tests/effect_convolution_test.convolution.approved.txt
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
test/approval_tests/approval_tests/effect_gain_test.gain.1.0.approved.txt
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
test/approval_tests/approval_tests/effect_gain_test.gain.2.0.approved.txt
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "ApprovalTests/ApprovalTests.hpp" | ||
#include "approval_test_helpers.hpp" | ||
#include "catch2/catch.hpp" | ||
#include "oalpp/effects/utility/convolution.hpp" | ||
#include "oalpp/sound_data.hpp" | ||
|
||
TEST_CASE("convolution") | ||
{ | ||
std::string const fileName { "assets/test1.ogg" }; | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "ApprovalTests/ApprovalTests.hpp" | ||
#include "approval_test_helpers.hpp" | ||
#include "catch2/catch.hpp" | ||
#include "oalpp/effects/utility/gain.hpp" | ||
#include "oalpp/sound_data.hpp" | ||
|
||
TEST_CASE("gain") | ||
{ | ||
SECTION("1.0") | ||
{ | ||
std::string const fileName { "assets/test1.ogg" }; | ||
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); | ||
} | ||
SECTION("2.0") | ||
{ | ||
std::string const fileName { "assets/test1.ogg" }; | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#define APPROVALS_CATCH | ||
#include "ApprovalTests/ApprovalTests.hpp" | ||
|
||
// This puts "received" and "approved" files in approval_tests/ sub-directory, | ||
// keeping the test source directory tidy: | ||
auto directoryDisposer = ApprovalTests::Approvals::useApprovalsSubdirectory("approval_tests"); |
File renamed without changes.
File renamed without changes.