Skip to content

Commit

Permalink
Improving Test Coverage (#551)
Browse files Browse the repository at this point in the history
* Adding JSON test

* Adding test for ParametersView

* Add WaveformView test

* Add test for Level Detector Visualizer

* Add gain computer plot test

* Trying to fix vizualizer tests

* Running viz test comparisons not just on Mac

* Apply clang-format

* Fixing typos

* Apply clang-format

* Updating ForwardingParameter for ignoring code coverage

* Add tests for CLAP preset discovery

* Apply clang-format

* Fixing warnings, etc

* More designated initializer fixes

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jatinchowdhury18 and github-actions[bot] authored Sep 5, 2024
1 parent ee4722f commit ef7a646
Show file tree
Hide file tree
Showing 28 changed files with 611 additions and 20 deletions.
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ignore:
- "modules/common/chowdsp_core/JUCEHelpers/**"
- "modules/plugin/chowdsp_presets/**/*.h"
- "modules/plugin/chowdsp_presets/**/*.cpp"
- "modules/gui/chowdsp_foleys"
Expand Down
2 changes: 2 additions & 0 deletions modules/common/chowdsp_json/JSONUtils/chowdsp_JSONUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ namespace JSONUtils
}
else
{
// LCOV_EXCL_START
// unable to create an output stream for this file
jassertfalse;
// LCOV_EXCL_END
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <chowdsp_dsp_utils/chowdsp_dsp_utils.h>
#include "chowdsp_OversamplingMenu.h"

// LCOV_EXCL_START

namespace chowdsp
{
template <typename OSType, typename ComboBoxType>
Expand Down Expand Up @@ -186,3 +188,5 @@ void OversamplingMenu<OSType, ComboBoxType>::generateComboBoxMenu()
template class OversamplingMenu<VariableOversampling<float>>;
template class OversamplingMenu<VariableOversampling<double>>;
} // namespace chowdsp

// LCOV_EXCL_END
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <chowdsp_listeners/chowdsp_listeners.h>

// LCOV_EXCL_START

namespace chowdsp
{
/** Menu that can be used as an interface for chowdsp::VariableOversampling */
Expand Down Expand Up @@ -57,3 +59,5 @@ class OversamplingMenu : public ComboBoxType
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OversamplingMenu)
};
} // namespace chowdsp

// LCOV_EXCL_END
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

// LCOV_EXCL_START

namespace chowdsp::ParamUtils
{
/** Mixin for parameters that recognize some form of modulation. */
Expand All @@ -18,3 +20,5 @@ struct ModParameterMixin : public clap_juce_extensions::clap_juce_parameter_capa
}
};
} // namespace chowdsp::ParamUtils

// LCOV_EXCL_END
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

// LCOV_EXCL_START

namespace chowdsp::CLAPExtensions
{
/** Interface for clap_juce_extensions::clap_properties */
Expand All @@ -18,3 +20,5 @@ struct CLAPInfoExtensions : public clap_juce_extensions::clap_properties
}
};
} // namespace chowdsp::CLAPExtensions

// LCOV_EXCL_END
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ EmbeddedPresetsProvider::EmbeddedPresetsProvider (const clap_universal_plugin_id
jassert (discoveryLocation.location == nullptr);
}

std::vector<Preset> EmbeddedPresetsProvider::getPresets() { return {}; }
std::vector<Preset> EmbeddedPresetsProvider::getPresets() { return {}; } // LCOV_EXCL_LINE

bool EmbeddedPresetsProvider::init() noexcept
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct ForwardingParameter::ForwardingAttachment
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ForwardingAttachment)
};
#else
// LCOV_EXCL_START
ForwardingParameter::ForwardingAttachment::ForwardingAttachment (juce::RangedAudioParameter& internal, juce::RangedAudioParameter& forwarding, juce::UndoManager* um)
: internalParam (internal), forwardingParam (forwarding), undoManager (um)
{
Expand Down Expand Up @@ -135,6 +136,7 @@ void ForwardingParameter::ForwardingAttachment::parameterGestureChanged (int, bo
else
endGesture();
}
// LCOV_EXCL_END
#endif

//=================================================================================
Expand All @@ -144,10 +146,12 @@ ForwardingParameter::ForwardingParameter (const ParameterID& id, PluginState& st
{
}
#else
// LCOV_EXCL_START
ForwardingParameter::ForwardingParameter (const ParameterID& id, juce::UndoManager* um, const juce::String& thisDefaultName)
: juce::RangedAudioParameter (id, thisDefaultName), undoManager (um), defaultName (thisDefaultName)
{
}
// LCOV_EXCL_END
#endif

ForwardingParameter::~ForwardingParameter()
Expand All @@ -170,7 +174,7 @@ void ForwardingParameter::reportParameterInfoChange (juce::AudioProcessor* proce
void ForwardingParameter::setParam (juce::RangedAudioParameter* paramToUse, const juce::String& newName, bool deferHostNotification)
{
#if ! JUCE_MODULE_AVAILABLE_chowdsp_plugin_state
juce::SpinLock::ScopedLockType sl (paramLock);
juce::SpinLock::ScopedLockType sl (paramLock); // LCOV_EXCL_LINE
#endif

if (internalParam != nullptr)
Expand All @@ -191,7 +195,7 @@ void ForwardingParameter::setParam (juce::RangedAudioParameter* paramToUse, cons
#if JUCE_MODULE_AVAILABLE_chowdsp_plugin_state
attachment = std::make_unique<ForwardingAttachment> (*internalParam, *this, pluginState);
#else
attachment = std::make_unique<ForwardingAttachment> (*internalParam, *this, undoManager);
attachment = std::make_unique<ForwardingAttachment> (*internalParam, *this, undoManager); // LCOV_EXCL_LINE
#endif
}
}
Expand All @@ -207,9 +211,11 @@ float ForwardingParameter::getValue() const
void ForwardingParameter::setValue (float newValue)
{
#if ! JUCE_MODULE_AVAILABLE_chowdsp_plugin_state
// LCOV_EXCL_START
juce::SpinLock::ScopedTryLockType stl (paramLock);
if (! stl.isLocked())
return;
// LCOV_EXCL_END
#endif

if (internalParam != nullptr && ! juce::approximatelyEqual (internalParam->getValue(), newValue))
Expand Down
21 changes: 21 additions & 0 deletions tests/common_tests/chowdsp_json_test/JSONTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ TEST_CASE ("JSON Test", "[common][json]")
testFile.deleteFile();
}

SECTION ("JSON Bad File Test")
{
chowdsp::json jTest = {
{ "pi", 3.141 },
{ "happy", true },
{ "name", "Niels" },
{ "nothing", nullptr },
{ "answer", { { "everything", 42 } } },
{ "list", { 1, 0, 2 } },
{ "object", { { "currency", "USD" }, { "value", 42.99 } } }
};

const auto testFolder = juce::File::getSpecialLocation (juce::File::userHomeDirectory).getChildFile ("test");
testFolder.createDirectory();
testFolder.getChildFile ("test.txt").create();

chowdsp::JSONUtils::toFile (jTest, testFolder, 4); // 4 space indent
REQUIRE (testFolder.isDirectory());
testFolder.deleteRecursively();
}

SECTION ("JSON Memory Block Test")
{
chowdsp::json jTest = {
Expand Down
4 changes: 1 addition & 3 deletions tests/gui_tests/chowdsp_gui_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ target_sources(chowdsp_gui_test PRIVATE
WindowInPluginTest.cpp
HostContextProviderTest.cpp
ComponentArenaTest.cpp

# OversamplingMenuTest.cpp
# PresetsCompTest.cpp
ParametersViewTest.cpp
)
66 changes: 66 additions & 0 deletions tests/gui_tests/chowdsp_gui_test/ParametersViewTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <CatchUtils.h>
#include <chowdsp_gui/chowdsp_gui.h>
#include <chowdsp_plugin_base/chowdsp_plugin_base.h>

namespace params_view_test
{
struct LevelParams : chowdsp::ParamHolder
{
explicit LevelParams (const juce::String& paramPrefix = "", int version = 100)
: prefix (paramPrefix),
versionHint (version)
{
add (percent, gain);
}

const juce::String prefix;
const int versionHint;

chowdsp::PercentParameter::Ptr percent { juce::ParameterID { prefix + "percent", versionHint }, "Percent" };
chowdsp::GainDBParameter::Ptr gain { juce::ParameterID { prefix + "gain", versionHint }, "Gain", juce::NormalisableRange { -30.0f, 0.0f }, 0.0f };
};

struct PluginParameterState : chowdsp::ParamHolder
{
PluginParameterState()
{
add (levelParams, mode, onOff);
}

LevelParams levelParams;
chowdsp::ChoiceParameter::Ptr mode { "mode", "Mode", juce::StringArray { "Percent", "Gain", "Percent / Gain", "Gain / Percent" }, 2 };
chowdsp::BoolParameter::Ptr onOff { "on_off", "On/Off", true };
};

using State = chowdsp::PluginStateImpl<PluginParameterState>;

struct Plugin : chowdsp::PluginBase<State>
{
const juce::String getName() const override { return "Plugin"; }
void releaseResources() override {}
void processAudioBlock (juce::AudioBuffer<float>& buffer) override { buffer.clear(); }
juce::AudioProcessorEditor* createEditor() override { return new chowdsp::ParametersViewEditor { *this }; }
};
} // namespace params_view_test

TEST_CASE ("Parameters View Test", "[gui][state]")
{
params_view_test::Plugin plugin;

auto* editor = dynamic_cast<chowdsp::ParametersViewEditor*> (plugin.createEditor());
REQUIRE (editor != nullptr);
auto _ = chowdsp::runAtEndOfScope (
[&plugin, editor]
{
plugin.editorBeingDeleted (editor);
delete editor;
});

editor->setSize (600, 600);

auto& params = plugin.getState().params;
REQUIRE (editor->view.getComponentForParameter (params.onOff) != nullptr);
REQUIRE (editor->view.getComponentForParameter (params.mode) != nullptr);
REQUIRE (editor->view.getComponentForParameter (params.levelParams.gain) != nullptr);
REQUIRE (editor->view.getComponentForParameter (params.levelParams.percent) != nullptr);
}
3 changes: 3 additions & 0 deletions tests/gui_tests/chowdsp_visualizers_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ target_sources(chowdsp_visualizers_test PRIVATE
EqualizerPlotTest.cpp
GenericFilterPlotTest.cpp
WaveshaperPlotTest.cpp
WaveformViewTest.cpp
LevelDetectorTest.cpp
GainComputerPlotTest.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,10 @@ TEST_CASE ("Equalizer Plot Test", "[visualizers][EQ]")
chowdsp::ParameterTypeHelpers::setValue (false, *state.params.testEQParams.eqParams[3].onOffParam);
juce::MessageManager::getInstance()->runDispatchLoopUntil (100);

#if JUCE_MAC
const auto testScreenshot = plotComp.createComponentSnapshot ({ 500, 300 });
// VizTestUtils::saveImage (testScreenshot, "eq_response_plot.png");

const auto refScreenshot = VizTestUtils::loadImage ("eq_response_plot.png");
VizTestUtils::compareImages (testScreenshot, refScreenshot);
#endif
}
}
42 changes: 42 additions & 0 deletions tests/gui_tests/chowdsp_visualizers_test/GainComputerPlotTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "VizTestUtils.h"

#include <chowdsp_compressor/chowdsp_compressor.h>
#include <chowdsp_visualizers/chowdsp_visualizers.h>

TEST_CASE ("Gain Computer Plot Test", "[visualizers][compressor]")
{
static constexpr int width = 500;
static constexpr int height = 500;
static constexpr int plotNumSamples = 128;

chowdsp::compressor::GainComputerPlot plot;
plot.setSize (width, height);
plot.setThreshold (-12.0f);

chowdsp::compressor::GainComputer<float, chowdsp::compressor::FeedForwardCompGainComputer<float>> gainComputer;

gainComputer.prepare (48000.0, plotNumSamples);
gainComputer.setThreshold (-12.0f);
gainComputer.setRatio (4.0f);
gainComputer.setKnee (18.0f);
gainComputer.reset();

chowdsp::StaticBuffer<float, 1, plotNumSamples> inputBuffer { 1, plotNumSamples };
chowdsp::StaticBuffer<float, 1, plotNumSamples> outputBuffer { 1, plotNumSamples };

for (auto [n, sample] : chowdsp::enumerate (inputBuffer.getWriteSpan (0)))
sample = juce::Decibels::decibelsToGain (juce::jmap ((float) n,
0.0f,
(float) inputBuffer.getNumSamples(),
plot.params.xMin,
plot.params.xMax));

gainComputer.processBlock (inputBuffer, outputBuffer);
plot.updatePlotPath (inputBuffer.getReadSpan (0), outputBuffer.getReadSpan (0));

const auto testScreenshot = plot.createComponentSnapshot ({ width, height });
// VizTestUtils::saveImage (testScreenshot, "gain_computer_plot.png");

const auto refScreenshot = VizTestUtils::loadImage ("gain_computer_plot.png");
VizTestUtils::compareImages (testScreenshot, refScreenshot);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ TEST_CASE ("Generic Filter Plot Test", "[visualizers]")
chowdsp::SVFNotch<float> filter;
};

#if JUCE_MAC
TestComponent comp {};
const auto testScreenshot = comp.createComponentSnapshot ({ 500, 300 });
// VizTestUtils::saveImage (testScreenshot, "generic_filter_plot.png");

const auto refScreenshot = VizTestUtils::loadImage ("generic_filter_plot.png");
VizTestUtils::compareImages (testScreenshot, refScreenshot);
#endif
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/gui_tests/chowdsp_visualizers_test/Images/waveshaper_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions tests/gui_tests/chowdsp_visualizers_test/LevelDetectorTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "VizTestUtils.h"
#include <chowdsp_visualizers/chowdsp_visualizers.h>

TEST_CASE ("Level Detector Test", "[visualizers][compressor]")
{
static constexpr int width = 500;
static constexpr int height = 300;
static constexpr int block_size = 512;

chowdsp::compressor::LevelDetectorVisualizer visualizer;
visualizer.setBufferSize (100);
visualizer.setSamplesPerBlock (block_size);

float phase = 0.0f;
for (int i = 0; i < 100; ++i)
{
std::array<float, block_size> buffer {};
for (auto& x : buffer)
{
x = 0.5f * std::sin (phase);
phase += 0.08f;
}
visualizer.pushChannel (0, nonstd::span<const float> { buffer });

buffer.fill (0.5f);
visualizer.pushChannel (1, nonstd::span<const float> { buffer });
}

visualizer.setSize (width, height);
const auto testScreenshot = visualizer.createComponentSnapshot ({ width, height });
// VizTestUtils::saveImage (testScreenshot, "level_detector.png");

const auto refScreenshot = VizTestUtils::loadImage ("level_detector.png");
VizTestUtils::compareImages (testScreenshot, refScreenshot);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ TEST_CASE ("Spectrum Plot Base Test", "[visualizers]")
}
};

#if JUCE_MAC
TestComp comp {};
const auto testScreenshot = comp.createComponentSnapshot ({ 500, 300 });
// VizTestUtils::saveImage (testScreenshot, "freq_grid_plot.png");

const auto refScreenshot = VizTestUtils::loadImage ("freq_grid_plot.png");
VizTestUtils::compareImages (testScreenshot, refScreenshot);
#endif
}
}
Loading

0 comments on commit ef7a646

Please sign in to comment.