Skip to content

Commit df2775b

Browse files
committed
init cpp test
1 parent 63d256f commit df2775b

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed

.github/workflows/tests.yml

+20-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
branches: [main]
99

1010
jobs:
11-
tests:
11+
py_test:
1212
name: Tests on ${{ matrix.os }} with python ${{ matrix.python-version }}
1313
runs-on: ${{ matrix.os }}
1414
strategy:
@@ -42,3 +42,22 @@ jobs:
4242

4343
- name: Codecov
4444
uses: codecov/[email protected]
45+
46+
cpp_test:
47+
runs-on: ${{ matrix.os }}
48+
strategy:
49+
matrix:
50+
os: [ ubuntu-latest, windows-latest, macOS-latest ]
51+
52+
steps:
53+
- uses: actions/checkout@v4
54+
- name: Configure CMake
55+
run: cmake -S . -Bbuild -DBUILD_SYMUSIC_TEST:BOOL=ON -DCMAKE_BUILD_TYPE=Debug
56+
57+
- name: Build
58+
run: cmake --build build --config Debug
59+
60+
- name: Run CPP Tests
61+
run: |
62+
cd build
63+
ctest -C Debug --output-on-failure --verbose

CMakeLists.txt

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15)
77

88
option(BUILD_SYMUSIC_PY "Build the python binding of symusic" OFF)
99
option(BUILD_SYMUSIC_EXAMPLE "Build the test target" OFF)
10+
option(BUILD_SYMUSIC_TEST "Build the test target" OFF)
1011
option(ENABLE_LTO "Enables link-time optimization, requires compiler support." ON)
1112
option(VTUNE "Compile Options for Intel VTune" Off)
1213

@@ -79,6 +80,24 @@ if(BUILD_SYMUSIC_EXAMPLE)
7980
target_link_libraries(adjust_time PUBLIC symusic)
8081
endif()
8182

83+
if(BUILD_SYMUSIC_TEST)
84+
Include(FetchContent)
85+
FetchContent_Declare(
86+
Catch2
87+
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
88+
GIT_TAG v3.4.0 # or a later release
89+
)
90+
FetchContent_MakeAvailable(Catch2)
91+
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
92+
add_executable(symusic_test tests/cpp/test_main.cpp)
93+
target_include_directories(symusic_test PRIVATE tests/cpp)
94+
target_link_libraries(symusic_test PRIVATE Catch2::Catch2WithMain symusic)
95+
include(CTest)
96+
include(Catch)
97+
catch_discover_tests(symusic_test)
98+
endif()
99+
100+
82101
if (ENABLE_LTO)
83102
include(CheckIPOSupported)
84103
check_ipo_supported(RESULT has_lto OUTPUT lto_check_output)

include/symusic/event.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ template<TType T>
6161
struct TimeStamp {
6262
typedef T ttype;
6363
typedef typename T::unit unit;
64-
unit time;
64+
unit time = 0;
6565

6666
COMPILER_DEFAULT_METHODS(TimeStamp)
6767

tests/cpp/test_main.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//
2+
// Created by lyk on 24-5-23.
3+
// The main entry of the test program using Catch2
4+
// Include unit test in different files into one file
5+
//
6+
7+
#include "test_time_events.hpp"

tests/cpp/test_time_events.hpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#pragma once
2+
#ifndef SYMUSIC_TEST_TIME_EVENTS_HPP
3+
#define SYMUSIC_TEST_TIME_EVENTS_HPP
4+
5+
#include "symusic.h"
6+
#include "catch2/catch_test_macros.hpp"
7+
using namespace symusic;
8+
9+
TEST_CASE("Test Time Event", "[symusic]") {
10+
SECTION("Note") {
11+
// default constructor
12+
REQUIRE(Note<Tick>{} == Note<Tick>{0, 0 ,0, 0});
13+
REQUIRE(Note<Quarter>{} == Note<Quarter>{0, 0 ,0, 0});
14+
REQUIRE(Note<Second>{} == Note<Second>{0, 0 ,0, 0});
15+
}
16+
}
17+
18+
#endif // SYMUSIC_TEST_TIME_EVENTS_HPP

0 commit comments

Comments
 (0)