Add simple tests

This commit is contained in:
WarmUpTill 2023-03-12 20:57:49 +01:00 committed by WarmUpTill
parent 8b105ad22b
commit ebbf64ddae
7 changed files with 21180 additions and 0 deletions

36
.github/actions/run-tests/action.yml vendored Normal file
View File

@ -0,0 +1,36 @@
name: 'Package plugin'
description: 'Packages the plugin for specified architecture and build config.'
inputs:
target:
description: 'Build target'
required: true
workingDirectory:
description: 'Working directory'
required: false
default: ${{ github.workspace }}
runs:
using: 'composite'
steps:
- name: Run macOS tests
if: ${{ runner.os == 'macOS' }}
shell: zsh {0}
run: |
if [[ '${{ inputs.target }}' != 'x86_64' ]]; then
exit 0
fi
${{ inputs.workingDirectory }}/build_x86_64/tests/advanced-scene-switcher-tests
- name: Run Linux packaging
if: ${{ runner.os == 'Linux' }}
shell: bash
run: |
if [[ '${{ inputs.target }}' != 'x86_64' ]]; then
exit 0
fi
${{ inputs.workingDirectory }}/build_x86_64/tests/advanced-scene-switcher-tests
- name: Run Windows packaging
if: ${{ runner.os == 'Windows' }}
shell: pwsh
run: |
${{ inputs.workingDirectory }}/build_x64/tests/RelWithDebInfo/advanced-scene-switcher-tests.exe

View File

@ -155,6 +155,12 @@ jobs:
codesign: 'true'
codesignIdent: ${{ env.CODESIGN_IDENT }}
- name: Run tests
uses: ./plugin/.github/actions/run-tests
with:
workingDirectory: ${{ github.workspace }}/plugin
target: ${{ matrix.arch }}
- name: Package Plugin
uses: ./plugin/.github/actions/package-plugin
with:
@ -250,6 +256,12 @@ jobs:
config: RelWithDebInfo
portable: ${{ matrix.portable }}
- name: Run tests
uses: ./plugin/.github/actions/run-tests
with:
workingDirectory: ${{ github.workspace }}/plugin
target: ${{ matrix.arch }}
- name: Package Plugin
uses: ./plugin/.github/actions/package-plugin
with:
@ -353,6 +365,12 @@ jobs:
config: RelWithDebInfo
visualStudio: 'Visual Studio 17 2022'
- name: Run tests
uses: ./plugin/.github/actions/run-tests
with:
workingDirectory: ${{ github.workspace }}/plugin
target: ${{ matrix.arch }}
- name: Package Plugin
uses: ./plugin/.github/actions/package-plugin
with:

View File

@ -471,3 +471,4 @@ endif()
# --- End of section ---
add_subdirectory(src/macro-external)
add_subdirectory(tests)

View File

@ -6,7 +6,14 @@
#include <stack>
#include <cmath>
#ifdef UNIT_TEST
const char *obs_module_text(const char *text)
{
return text;
}
#else
#include <obs-module.h>
#endif
static std::vector<std::string_view> nonOperatorSeparators = {
" ",

18
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.14)
project(advanced-scene-switcher-tests)
get_target_property(ADVSS_SOURCE_DIR advanced-scene-switcher-lib SOURCE_DIR)
add_executable(${PROJECT_NAME})
target_compile_definitions(${PROJECT_NAME} PRIVATE UNIT_TEST)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_sources(${PROJECT_NAME}
PRIVATE tests.cpp ${ADVSS_SOURCE_DIR}/src/utils/math-helpers.cpp)
target_include_directories(
${PROJECT_NAME}
PRIVATE "${ADVSS_SOURCE_DIR}/src" "${ADVSS_SOURCE_DIR}/src/legacy"
"${ADVSS_SOURCE_DIR}/src/macro-core" "${ADVSS_SOURCE_DIR}/src/utils"
"${ADVSS_SOURCE_DIR}/forms")
install(TARGETS advanced-scene-switcher-lib
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
enable_testing()

21029
tests/catch.hpp Normal file

File diff suppressed because it is too large Load Diff

71
tests/tests.cpp Normal file
View File

@ -0,0 +1,71 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <math-helpers.hpp>
TEST_CASE("Expressions are evaluated successfully", "[math-helpers]")
{
auto expressionResult = EvalMathExpression("1");
auto *doubleValuePtr = std::get_if<double>(&expressionResult);
REQUIRE(doubleValuePtr != nullptr);
REQUIRE(*doubleValuePtr == 1.0);
expressionResult = EvalMathExpression("1 + 2");
doubleValuePtr = std::get_if<double>(&expressionResult);
REQUIRE(doubleValuePtr != nullptr);
REQUIRE(*doubleValuePtr == 3.0);
expressionResult = EvalMathExpression("1 + 2 * 3");
doubleValuePtr = std::get_if<double>(&expressionResult);
REQUIRE(doubleValuePtr != nullptr);
REQUIRE(*doubleValuePtr == 7.0);
expressionResult = EvalMathExpression("(1 + 2) * 3");
doubleValuePtr = std::get_if<double>(&expressionResult);
REQUIRE(doubleValuePtr != nullptr);
REQUIRE(*doubleValuePtr == 9.0);
expressionResult =
EvalMathExpression("cos(abs(1 - sqrt(10 - 2 * 3)) -1)");
doubleValuePtr = std::get_if<double>(&expressionResult);
REQUIRE(doubleValuePtr != nullptr);
REQUIRE(*doubleValuePtr == 1.0);
}
TEST_CASE("Invalid expressions are not evaluated", "[math-helpers]")
{
auto expressionResult = EvalMathExpression("");
auto *doubleValuePtr = std::get_if<double>(&expressionResult);
REQUIRE(doubleValuePtr == nullptr);
expressionResult = EvalMathExpression(")");
doubleValuePtr = std::get_if<double>(&expressionResult);
REQUIRE(doubleValuePtr == nullptr);
expressionResult = EvalMathExpression("(");
doubleValuePtr = std::get_if<double>(&expressionResult);
REQUIRE(doubleValuePtr == nullptr);
expressionResult = EvalMathExpression("()");
doubleValuePtr = std::get_if<double>(&expressionResult);
REQUIRE(doubleValuePtr == nullptr);
expressionResult = EvalMathExpression("1 + 2)");
doubleValuePtr = std::get_if<double>(&expressionResult);
REQUIRE(doubleValuePtr == nullptr);
expressionResult = EvalMathExpression("1 + 2 * asdf");
doubleValuePtr = std::get_if<double>(&expressionResult);
REQUIRE(doubleValuePtr == nullptr);
}