diff --git a/blocks/basic/include/gnuradio-4.0/basic/common_blocks.hpp b/blocks/basic/include/gnuradio-4.0/basic/common_blocks.hpp index cb1a0f49f..c031a6f49 100644 --- a/blocks/basic/include/gnuradio-4.0/basic/common_blocks.hpp +++ b/blocks/basic/include/gnuradio-4.0/basic/common_blocks.hpp @@ -10,6 +10,22 @@ #include #include +// A convenience class to make writing unit tests easier. +// This sink allows to inspect the input port values as a class member. +template +class InspectSink : public gr::Block> { +public: + T value{}; + gr::PortIn in; + + constexpr void + processOne(T val) { + value = val; + } +}; + +ENABLE_REFLECTION_FOR_TEMPLATE_FULL((typename T), (InspectSink), value, in); + template class builtin_multiply : public gr::Block> { public: diff --git a/core/test/qa_DynamicBlock.cpp b/core/test/qa_DynamicBlock.cpp index 5a6748137..291580ba7 100644 --- a/core/test/qa_DynamicBlock.cpp +++ b/core/test/qa_DynamicBlock.cpp @@ -56,7 +56,7 @@ const boost::ut::suite DynamicBlocktests = [] { // sources_count / 2 inputs on construction, and change the number // via settings auto &adder = testGraph.addBlock(std::make_unique>(sources_count / 2)); - auto &sink = testGraph.emplaceBlock>({}); + auto &sink = testGraph.emplaceBlock>({}); // Function that adds a new source node to the graph, and connects // it to one of adder's ports @@ -80,7 +80,7 @@ const boost::ut::suite DynamicBlocktests = [] { const auto work = sink.work(1UZ); expect(eq(work.performed_work, 1UZ)); - expect(eq(sink.lastValue, static_cast((i + 1) * sources.size()))); + expect(eq(sink.value, static_cast((i + 1) * sources.size()))); } // add yet another sources_count number of ports @@ -104,7 +104,7 @@ const boost::ut::suite DynamicBlocktests = [] { const auto sink_work = sink.work(1UZ); expect(eq(sink_work.performed_work, 1UZ)); - expect(eq(sink.lastValue, static_cast((i + 1) * sources_count + (i - events_count + 1) * sources_count))); + expect(eq(sink.value, static_cast((i + 1) * sources_count + (i - events_count + 1) * sources_count))); } }; };