Skip to content

Commit

Permalink
Merge pull request #79 from Laguna1989/FEATURE_ApprovalTestsForEffects
Browse files Browse the repository at this point in the history
Approval tests for effects
  • Loading branch information
Laguna1989 authored May 17, 2022
2 parents 28e9a2f + 4684a25 commit 9b457ab
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitattributes
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
23 changes: 18 additions & 5 deletions .github/workflows/test_verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ jobs:
platform: x64

- uses: actions/checkout@v2
with:
lfs: 'true'

- name: gitlfs
run: git lfs pull

- name: ccache
uses: hendrikmuhs/ccache-action@v1
Expand All @@ -40,11 +45,19 @@ 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

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

- name: CopyAssets
run: cp -r ${{github.workspace}}/assets ${{github.workspace}}/build/test/approval_tests

# - name: Test
# run: ./OpenALpp_UnitTests --order rand
# working-directory: ${{github.workspace}}/build/bin/
- name: ApprovalTest
run: ./OpenALpp_ApprovalTests --order rand
working-directory: ${{github.workspace}}/build/test/approval_tests

Linux_clang:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -146,7 +159,7 @@ jobs:
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
.
- name: Copy assets
run: cp -r assets ${{github.workspace}}/build/test/integration/
run: cp -r assets ${{github.workspace}}/build/test/integration_tests/
- name: Build
working-directory: ${{github.workspace}}/build
run: emmake make OpenALpp_UnitTests OpenALpp_Integration
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.19)
project(OpenALpp VERSION 0.1.0)

option(OALPP_ENABLE_UNIT_TESTS "Enable unit tests" ON)
option(OALPP_ENABLE_APPROVAL_TESTS "Enable approval tests" ON)
option(OALPP_ENABLE_INTEGRATION_TESTS "Enable integration tests" ON)
option(OALPP_STATIC_LIBRARY "Build openal as static library" ON)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ CMake Options
-------------

* `OALPP_ENABLE_UNIT_TESTS` - Enable unit tests - default `ON`
* `OALPP_ENABLE_APPROVAL_TESTS` - Enable approval tests - default `ON`
* `OALPP_ENABLE_INTEGRATION_TESTS` - Enable integration test - default `ON`
* `OALPP_STATIC_LIBRARY` - Build OpenALpp and dependencies as static library - default `ON`

Expand Down
5 changes: 5 additions & 0 deletions ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ add_subdirectory(libnyquist)
if (OALPP_ENABLE_UNIT_TESTS)
add_subdirectory(catch2)
endif ()


if (OALPP_ENABLE_APPROVAL_TESTS)
add_subdirectory(approvaltestscpp)
endif ()
9 changes: 9 additions & 0 deletions ext/approvaltestscpp/CMakeLists.txt
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)
6 changes: 5 additions & 1 deletion test/CMakeLists.txt
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 ()
20 changes: 20 additions & 0 deletions test/approval_tests/CMakeLists.txt
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)
6 changes: 6 additions & 0 deletions test/approval_tests/approval_test_helpers.cpp
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);
}
9 changes: 9 additions & 0 deletions test/approval_tests/approval_test_helpers.hpp
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
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
21 changes: 21 additions & 0 deletions test/approval_tests/effect_convolution_test.cpp
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);
}
41 changes: 41 additions & 0 deletions test/approval_tests/effect_gain_test.cpp
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);
}
}
6 changes: 6 additions & 0 deletions test/approval_tests/main.cpp
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.

0 comments on commit 9b457ab

Please sign in to comment.