Hello,
I have the following problem: I am using catch2 as a unit testing framework and I am trying to test my class, that derives from juce::Value::Listener. I’ve used the testing framework with juce a lot and it works fine in general. I have learned to call ScopedJuceInitialiser_GUI() to get the MessageManager to run, but somehow the code - as outline/simplified below - still does not work. With some investigation I found listeners are called asynchronously, but even if I throw-in a sleep/wait after changing the value, the listener still doesn’t get called. Any help much appreciated.
#include <catch2/catch_all.hpp>
class MyListener : public juce::Value::Listener
{
public:
void valueChanged (Value& value)
{
changed = true;
}bool valueHasChanged() { return changed; }private:
bool changed {false};
};TEST_CASE (“Test”, “[Test]”)
{
const auto x = juce::ScopedJuceInitialiser_GUI();auto value = juce::Value (var (0)); auto listener = MyListener(); value.addListener (&listener); value.setValue (1); REQUIRE (listener.valueHasChanged());}
