Skip to content

Commit

Permalink
[cue] Fix test build
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Jun 24, 2024
1 parent 9165c37 commit c8b9fcb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
4 changes: 4 additions & 0 deletions examples/Qt/DeviceBuilder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ if(NOT TARGET ${QT_PREFIX}::Widgets)
return()
endif()

if(NOT OSSIA_PROTOCOL_OSCQUERY)
return()
endif()

set(CMAKE_AUTOMOC ON)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ${QT_PREFIX}::Widgets ossia)
4 changes: 2 additions & 2 deletions src/ossia/preset/cue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ int cues::get_cue(std::string_view name)
m_cues.begin(), m_cues.end(), [=](const cue& c) { return c.name == name; });
if(BOOST_UNLIKELY(it == m_cues.end()))
{
m_cues.push_back(cue{.name = std::string(name)});
m_cues.push_back(cue{.name = std::string(name), .preset = {}});
return m_cues.size() - 1;
}
else
Expand Down Expand Up @@ -336,7 +336,7 @@ void cues::remove(int idx)

if(m_cues.empty())
{
m_cues.push_back({.name{"Init"}});
m_cues.push_back({.name{"Init"}, .preset = {}});
m_current = 0;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ossia/preset/cue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ class OSSIA_EXPORT namespace_selection : Nano::Observer
ossia::hash_set<ossia::net::node_base*> m_selection;
};

class OSSIA_EXPORT cues// : public namespace_selection
class OSSIA_EXPORT cues
{
public:
std::vector<cue> m_cues{{.name{"Init"}}};
std::vector<cue> m_cues{{.name{"Init"}, .preset = {}}};

int size() const noexcept { return this->m_cues.size(); }

Expand Down
65 changes: 35 additions & 30 deletions tests/Preset/CueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ TEST_CASE("test_cue", "test_cue")

default_cue_device device;
ossia::cues c;
c.set_device(&device.dev);
ossia::namespace_selection sel;
sel.set_device(&device.dev);

WHEN("initial state")
{
THEN("one cue")
{
REQUIRE(c.size() == 1);
REQUIRE(c.current_cue().name == "Init");
REQUIRE(c.current_cue()->name == "Init");
}
}

Expand All @@ -72,23 +73,25 @@ TEST_CASE("test_cue", "test_cue")
THEN("two cue")
{
REQUIRE(c.size() == 2);
REQUIRE(c.current_cue().name == "Cue");
// REQUIRE(c.current_cue().selection == std::vector<std::string>{"/"});
REQUIRE(c.current_cue().preset.empty());
REQUIRE(c.current_cue()->name == "Cue");
// REQUIRE(c.current_cue()->selection == std::vector<std::string>{"/"});
REQUIRE(c.current_cue()->preset.empty());
}
}

WHEN("updating the cue")
{
c.create("Cue");
REQUIRE(c.size() == 2);
REQUIRE(c.current_cue().name == "Cue");
c.update("Cue");
REQUIRE(c.current_cue()->name == "Cue");
c.update(device.dev.get_root_node(), sel, "Cue");
THEN("entire tree is copied")
{
REQUIRE(c.current_cue().name == "Cue");
REQUIRE(c.current_cue()->name == "Cue");

auto& cue = c.current_cue();
auto cue_ptr = c.current_cue();
REQUIRE(cue_ptr);
auto& cue = *cue_ptr;

REQUIRE(cue.preset.size() == 4);

Expand All @@ -108,7 +111,7 @@ TEST_CASE("test_cue", "test_cue")
REQUIRE(device.a4.value() == "bar");

c.create("Cue 1");
c.update();
c.update(device.dev.get_root_node(), sel, "Cue 1");
REQUIRE(c.m_cues[1].name == "Cue 1");
REQUIRE(c.m_cues[1].preset.size() == 4);

Expand All @@ -118,17 +121,17 @@ TEST_CASE("test_cue", "test_cue")
device.a4.set_value("a4");

c.create("Cue 2");
c.update();
c.update(device.dev.get_root_node(), sel, "Cue 2");

THEN("recalling sets the correct values")
{
c.recall("Cue 1");
c.recall(device.dev.get_root_node(), sel, "Cue 1");
REQUIRE(device.a1.value() == 13579);
REQUIRE(device.a2.value() == 3.1415);
REQUIRE(device.a3.value() == "foo");
REQUIRE(device.a4.value() == "bar");

c.recall("Cue 2");
c.recall(device.dev.get_root_node(), sel, "Cue 2");
REQUIRE(device.a1.value() == 10);
REQUIRE(device.a2.value() == 1.2);
REQUIRE(device.a3.value() == "a3");
Expand All @@ -145,14 +148,15 @@ TEST_CASE("test_cue_ns", "test_cue_ns")
default_cue_device device;

ossia::cues c;
c.set_device(&device.dev);
c.namespace_deselect("/");
ossia::namespace_selection sel;
sel.set_device(&device.dev);
sel.namespace_deselect("/");

THEN("updating does nothing")
{
REQUIRE(c.current_cue().preset.empty());
c.update();
REQUIRE(c.current_cue().preset.empty());
REQUIRE(c.current_cue()->preset.empty());
c.update(device.dev.get_root_node(), sel);
REQUIRE(c.current_cue()->preset.empty());
}
}

Expand All @@ -161,19 +165,20 @@ TEST_CASE("test_cue_ns", "test_cue_ns")
default_cue_device device;

ossia::cues c;
c.set_device(&device.dev);
c.namespace_deselect("/");
REQUIRE(c.m_selection.empty());
ossia::namespace_selection sel;
sel.set_device(&device.dev);
sel.namespace_deselect("/");
REQUIRE(sel.m_selection.empty());

c.namespace_select("/bim");
REQUIRE(c.m_selection.size() == 4);
sel.namespace_select("/bim");
REQUIRE(sel.m_selection.size() == 4);

c.update();
c.update(device.dev.get_root_node(), sel);

THEN("node now contains cues from /bim/bam and /bim/boum*")
{
//REQUIRE(c.se)
auto& cue = c.current_cue();
auto* cue_ptr = c.current_cue();
auto& cue = *cue_ptr;
REQUIRE(cue.preset.size() == 3);
REQUIRE(at(cue.preset, "/bim/bam") == 3.1415);
REQUIRE(at(cue.preset, "/bim/boum") == "foo"s);
Expand All @@ -182,17 +187,17 @@ TEST_CASE("test_cue_ns", "test_cue_ns")

WHEN("deselecting a sub node")
{
c.namespace_deselect("/bim/boum");
sel.namespace_deselect("/bim/boum");

c.clear();
c.create("Cue");

c.update();
c.update(device.dev.get_root_node(), sel);

THEN("node now contains cues from /bim/bam and /bim/boum.1 only")
{
auto& cue = c.current_cue();
//INFO(cue.selection);
auto* cue_ptr = c.current_cue();
auto& cue = *cue_ptr;
REQUIRE(cue.preset.size() == 2);
REQUIRE(at(cue.preset, "/bim/bam") == 3.1415);
REQUIRE(at(cue.preset, "/bim/boum.1") == "bar"s);
Expand Down

0 comments on commit c8b9fcb

Please sign in to comment.