From b8394e641f48542d8ce335902fceade0bc7ed2e3 Mon Sep 17 00:00:00 2001 From: rkcf Date: Mon, 27 Feb 2023 14:08:02 -0600 Subject: [PATCH 1/7] Build: move to using cmake --- CMakeLists.txt | 13 +++++++++++++ Makefile | 15 ++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..402c8f7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.14) +project(wtpp) + +set(CMAKE_CXX_STANDARD 17) + +add_library (wave src/wave.cpp) +add_library (wavetable src/wavetable.cpp) +add_library (common src/common.cpp) +add_library (generators src/generators.cpp) + +add_executable(wtpp src/wtpp.cpp) + +target_link_libraries(wtpp wave wavetable common generators) diff --git a/Makefile b/Makefile index 5b73fda..4741b0d 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,18 @@ PROJ = wtpp CC = /usr/bin/clang++ +CMAKE = /usr/bin/cmake GDB = /usr/bin/gdb -OLEVEL = -O2 - -CFLAGS = -Wall -std=c++17 $(OLEVEL) -o $(PROJ) - -OBJECTS = src/wtpp.cpp src/wave.cpp src/wavetable.cpp src/generators.cpp src/common.cpp build: - $(CC) $(CFLAGS) $(OBJECTS) + $(CMAKE) --build build clean: rm wtpp -debug: build +debug: + $(CC) -g $(CFLAGS) $(OBJECTS) $(GDB) $(PROJ) + +web-debug: + $(CC) -g $(CFLAGS) $(OBJECTS) + gdbgui $(PROJ) From 36dc4a1e3d9eef20d9b3c04742f47a03e110868c Mon Sep 17 00:00:00 2001 From: rkcf Date: Mon, 27 Feb 2023 14:33:54 -0600 Subject: [PATCH 2/7] Build: add google test framework Refs: #17 --- CMakeLists.txt | 17 +++++++++++++++++ Makefile | 10 ++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 402c8f7..f320013 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,3 +11,20 @@ add_library (generators src/generators.cpp) add_executable(wtpp src/wtpp.cpp) target_link_libraries(wtpp wave wavetable common generators) + +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/95d8c7ac4389b38b197bc7521dffb62508653eb5.zip +) + +FetchContent_MakeAvailable(googletest) + +enable_testing() + +add_executable(wtpp_test tests/wtpp_test.cpp) + +target_link_libraries(wtpp_test GTest::gtest_main) + +include(GoogleTest) +gtest_discover_tests(wtpp_test) diff --git a/Makefile b/Makefile index 4741b0d..05457f7 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,15 @@ PROJ = wtpp CC = /usr/bin/clang++ -CMAKE = /usr/bin/cmake GDB = /usr/bin/gdb -build: - $(CMAKE) --build build +build-release: + cmake --build build clean: - rm wtpp + rm build/wtpp + +test: build + cd build && ctest debug: $(CC) -g $(CFLAGS) $(OBJECTS) From a349cbed67999abed2871189be58e8198c02edce Mon Sep 17 00:00:00 2001 From: rkcf Date: Mon, 27 Feb 2023 15:07:56 -0600 Subject: [PATCH 3/7] Refactor: Move application out of main and into temp testing file Closes: #17 Refs: #17 --- src/wtpp.cpp | 56 +--------------------------------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/src/wtpp.cpp b/src/wtpp.cpp index a7bcd05..e32c011 100644 --- a/src/wtpp.cpp +++ b/src/wtpp.cpp @@ -1,60 +1,6 @@ -#include -#include -#include - -#include - -#include "ini.h" - -#include "common.h" -#include "wave.h" -#include "generators.h" -#include "wavetable.h" +#include int main() { - clog("Generating wave cycle lookup tables"); - Wave sin_wave, squ_wave, saw_wave, tri_wave, isaw_wave; - - // Calculate fundamental wave values - sample_table_t sin_vals = gen_sin(); - sample_table_t squ_vals = gen_squ(); - sample_table_t saw_vals = gen_saw(); - sample_table_t tri_vals = gen_tri(); - sample_table_t isaw_vals = gen_isaw(); - - // Set wave lookup table values - sin_wave.setTable(sin_vals); - squ_wave.setTable(squ_vals); - saw_wave.setTable(saw_vals); - tri_wave.setTable(tri_vals); - isaw_wave.setTable(isaw_vals); - - clog("Printing head of sine table"); - sin_wave.print_head(); - clog("Printing head of square table"); - squ_wave.print_head(); - clog("Printing head of saw table"); - saw_wave.print_head(); - clog("Printing head of triangle table"); - tri_wave.print_head(); - clog("Printing head of inverse saw table"); - isaw_wave.print_head(); - - Wavetable wt_01{"Fundamental Waves"}; - clog(wt_01.name()); - - // Add fundamental waves to wt_01 - std::array fundies = {sin_wave, squ_wave, saw_wave, tri_wave, isaw_wave}; - for (uint8_t i = 0; i < 5; i++){ - wt_01.setWave(i, fundies[i]); - } - - // Write sine wave table to file - sin_wave.export_csv("data/sine.csv"); - - // Write full Wavetable data to file - wt_01.export_csv("data"); - return 0; } From a3dacdd1a7cd2cb4c7069f792c049011ea9c2f0d Mon Sep 17 00:00:00 2001 From: rkcf Date: Tue, 28 Feb 2023 09:24:23 -0600 Subject: [PATCH 4/7] Test: add coverage for Wave construction Refs: #18, #16 --- CMakeLists.txt | 3 +++ Makefile | 2 +- tests/wave_test.cpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/wave_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f320013..d3d92b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,11 @@ FetchContent_MakeAvailable(googletest) enable_testing() add_executable(wtpp_test tests/wtpp_test.cpp) +add_executable(wave_test tests/wave_test.cpp) target_link_libraries(wtpp_test GTest::gtest_main) +target_link_libraries(wave_test GTest::gtest_main) include(GoogleTest) gtest_discover_tests(wtpp_test) +gtest_discover_tests(wave_test) diff --git a/Makefile b/Makefile index 05457f7..3c86085 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ clean: rm build/wtpp test: build - cd build && ctest + cd build && ctest --output-on-failure debug: $(CC) -g $(CFLAGS) $(OBJECTS) diff --git a/tests/wave_test.cpp b/tests/wave_test.cpp new file mode 100644 index 0000000..1d612cd --- /dev/null +++ b/tests/wave_test.cpp @@ -0,0 +1,34 @@ +#include "../src/wave.h" +#include "gtest/gtest.h" + +// Initialize index at 0 for wave cycles +uint16_t Wave::m_nid = 0; + +TEST(Wave, DefaultConstructor) +{ + Wave w1, w2; + // Check that ids are correct + EXPECT_EQ(w1.getId(), 0); + EXPECT_EQ(w2.getId(), 1); + // Sample table should be 0 initialized + EXPECT_EQ(w1.getVal(0), 0); +} + +TEST(Wave, CopyConstructor) { + Wave w1; + Wave w2(w1); + // Check id is correct + EXPECT_EQ(w2.getId(), 0); + // Sample table should be 0 initialized + EXPECT_EQ(w2.getVal(0), 0); +} + +TEST(Wave, CopyAssignment) +{ + Wave w1; + Wave w2 = w1; + // Check id is correct + EXPECT_EQ(w2.getId(), 0); + // Sample table should be 0 initialized + EXPECT_EQ(w2.getVal(0), 0); +} From 30e59a7d1607e9ff270963aacf4f449263281abe Mon Sep 17 00:00:00 2001 From: rkcf Date: Tue, 28 Feb 2023 10:10:42 -0600 Subject: [PATCH 5/7] Test: add Wavetable construction test coverage Refs: #18 --- CMakeLists.txt | 4 ++++ tests/wavetable_test.cpp | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/wavetable_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d3d92b0..a1e0eeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,10 +24,14 @@ enable_testing() add_executable(wtpp_test tests/wtpp_test.cpp) add_executable(wave_test tests/wave_test.cpp) +add_executable(wavetable_test tests/wavetable_test.cpp) target_link_libraries(wtpp_test GTest::gtest_main) target_link_libraries(wave_test GTest::gtest_main) +target_link_libraries(wavetable_test GTest::gtest_main) include(GoogleTest) + gtest_discover_tests(wtpp_test) gtest_discover_tests(wave_test) +gtest_discover_tests(wavetable_test) diff --git a/tests/wavetable_test.cpp b/tests/wavetable_test.cpp new file mode 100644 index 0000000..bc20242 --- /dev/null +++ b/tests/wavetable_test.cpp @@ -0,0 +1,37 @@ +#include "../src/wavetable.h" +#include "gtest/gtest.h" + +// Initialize index at 0 for wave cycles +uint16_t Wave::m_nid = 0; +uint16_t Wavetable::m_nid = 0; + +TEST(Wavetable, DefaultConstructor) +{ + Wavetable w1("PPG"), w2("!PPG"); + // Check ids are correct + EXPECT_EQ(w1.getId(), 0); + EXPECT_EQ(w2.getId(), 1); + // Check name is correct + // std::string name = w1.name(); + // EXPECT_EQ(name, "PPG"); +} + +TEST(Wavetable, CopyConstructor) { + Wavetable w1("PPG"); + Wavetable w2(w1); + // Check id is correct + EXPECT_EQ(w2.getId(), 0); + // Sample name is correct + // std::string name = w2.name(); + // EXPECT_EQ(name, "PPG"); +} + +TEST(Wavetable, CopyAssignment) { + Wavetable w1("PPG"); + Wavetable w2 = w1; + // Check id is correct + EXPECT_EQ(w2.getId(), 0); + // Check name is correct + // std::string name = w2.name(); + // EXPECT_EQ(name, "PPG"); +} From 06e144f075b2e6ae850bd4b30ea3ec5806ac9eb6 Mon Sep 17 00:00:00 2001 From: rkcf Date: Tue, 28 Feb 2023 10:26:28 -0600 Subject: [PATCH 6/7] Test: add coverage for sample generators Refs: #18 --- CMakeLists.txt | 3 +++ tests/generators_test.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tests/generators_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a1e0eeb..6f1e02f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,13 +25,16 @@ enable_testing() add_executable(wtpp_test tests/wtpp_test.cpp) add_executable(wave_test tests/wave_test.cpp) add_executable(wavetable_test tests/wavetable_test.cpp) +add_executable(generators_test tests/generators_test.cpp) target_link_libraries(wtpp_test GTest::gtest_main) target_link_libraries(wave_test GTest::gtest_main) target_link_libraries(wavetable_test GTest::gtest_main) +target_link_libraries(generators_test generators GTest::gtest_main) include(GoogleTest) gtest_discover_tests(wtpp_test) gtest_discover_tests(wave_test) gtest_discover_tests(wavetable_test) +gtest_discover_tests(generators_test) diff --git a/tests/generators_test.cpp b/tests/generators_test.cpp new file mode 100644 index 0000000..6790a0c --- /dev/null +++ b/tests/generators_test.cpp @@ -0,0 +1,35 @@ +#include "../src/generators.h" +#include "gtest/gtest.h" + +TEST(Generator, SineWave) +{ + sample_table_t t = gen_sin(); + // Starts at 0 + EXPECT_EQ(t[0], 0); +} + +TEST(Generator, SquareWave) { + sample_table_t t = gen_squ(); + // Starts at 1 + EXPECT_EQ(t[0], 1); + // Ends at -1 + EXPECT_EQ(t[DEFAULT_N_SAMPLES - 1], -1); +} + +TEST(Generator, SawWave) { + sample_table_t t = gen_saw(); + // Starts at -1 + EXPECT_EQ(t[0], -1); +} + +TEST(Generator, TriangleWave) { + sample_table_t t = gen_tri(); + // Starts at -1 + EXPECT_EQ(t[0], -1); +} + +TEST(Generator, InverseSawWave) { + sample_table_t t = gen_isaw(); + // Starts at 1 + EXPECT_EQ(t[0], 1); +} From 010a9d229663877f387fe2db6514c43927101ce1 Mon Sep 17 00:00:00 2001 From: rkcf Date: Tue, 28 Feb 2023 10:30:08 -0600 Subject: [PATCH 7/7] Fix: correct cmake linkage issue, fixes #19 Refs: #19 --- CMakeLists.txt | 4 ++-- tests/wave_test.cpp | 3 --- tests/wavetable_test.cpp | 12 +++--------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f1e02f..9951bc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,8 +28,8 @@ add_executable(wavetable_test tests/wavetable_test.cpp) add_executable(generators_test tests/generators_test.cpp) target_link_libraries(wtpp_test GTest::gtest_main) -target_link_libraries(wave_test GTest::gtest_main) -target_link_libraries(wavetable_test GTest::gtest_main) +target_link_libraries(wave_test wave GTest::gtest_main) +target_link_libraries(wavetable_test wave wavetable GTest::gtest_main) target_link_libraries(generators_test generators GTest::gtest_main) include(GoogleTest) diff --git a/tests/wave_test.cpp b/tests/wave_test.cpp index 1d612cd..cafbeb3 100644 --- a/tests/wave_test.cpp +++ b/tests/wave_test.cpp @@ -1,9 +1,6 @@ #include "../src/wave.h" #include "gtest/gtest.h" -// Initialize index at 0 for wave cycles -uint16_t Wave::m_nid = 0; - TEST(Wave, DefaultConstructor) { Wave w1, w2; diff --git a/tests/wavetable_test.cpp b/tests/wavetable_test.cpp index bc20242..103af52 100644 --- a/tests/wavetable_test.cpp +++ b/tests/wavetable_test.cpp @@ -1,10 +1,6 @@ #include "../src/wavetable.h" #include "gtest/gtest.h" -// Initialize index at 0 for wave cycles -uint16_t Wave::m_nid = 0; -uint16_t Wavetable::m_nid = 0; - TEST(Wavetable, DefaultConstructor) { Wavetable w1("PPG"), w2("!PPG"); @@ -13,7 +9,7 @@ TEST(Wavetable, DefaultConstructor) EXPECT_EQ(w2.getId(), 1); // Check name is correct // std::string name = w1.name(); - // EXPECT_EQ(name, "PPG"); + EXPECT_EQ(w1.name(), "0: PPG"); } TEST(Wavetable, CopyConstructor) { @@ -22,8 +18,7 @@ TEST(Wavetable, CopyConstructor) { // Check id is correct EXPECT_EQ(w2.getId(), 0); // Sample name is correct - // std::string name = w2.name(); - // EXPECT_EQ(name, "PPG"); + EXPECT_EQ(w2.name(), "0: PPG"); } TEST(Wavetable, CopyAssignment) { @@ -32,6 +27,5 @@ TEST(Wavetable, CopyAssignment) { // Check id is correct EXPECT_EQ(w2.getId(), 0); // Check name is correct - // std::string name = w2.name(); - // EXPECT_EQ(name, "PPG"); + EXPECT_EQ(w2.name(), "0: PPG"); }