/* DISPATCHER-MOCK.hpp - test scaffolding to verify render job planning and dispatch Copyright (C) Lumiera.org 2023, Hermann Vosseler This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /** @file testframe.hpp ** Unit test helper to generate fake test data frames */ #ifndef STEAM_ENGINE_TEST_DISPATCHER_MOCK_H #define STEAM_ENGINE_TEST_DISPATCHER_MOCK_H ////#include "steam/engine/procnode.hpp" //#include "steam/play/dummy-play-connection.hpp" #include "steam/fixture/segmentation.hpp" #include "steam/mobject/model-port.hpp" #include "steam/engine/dispatcher.hpp" #include "steam/engine/job-ticket.hpp" //#include "steam/play/timings.hpp" #include "lib/time/timevalue.hpp" ////#include "lib/time/timequant.hpp" ////#include "lib/format-cout.hpp" #include "lib/diff/gen-node.hpp" #include "lib/depend.hpp" #include "lib/itertools.hpp" //#include "lib/iter-tree-explorer.hpp" //#include "lib/util-coll.hpp" #include "vault/real-clock.hpp" #include "lib/test/test-helper.hpp" #include "vault/engine/job.h" #include "vault/engine/dummy-job.hpp" #include "lib/util.hpp" //#include //#include #include #include //using test::Test; //using util::isnil; //using util::last; //using std::vector; //using std::function; //using std::rand; //#include //#include namespace steam { namespace engine { namespace test { using lib::diff::GenNode; using lib::diff::MakeRec; // using lib::time::FrameRate; // using lib::time::Duration; // using lib::time::Offset; // using lib::time::TimeVar; using lib::time::TimeValue; using lib::time::Time; // using mobject::ModelPort; // using play::Timings; using lib::HashVal; using std::make_tuple; using std::deque; ///////////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1294 : organisation of namespaces / includes?? using fixture::Segmentation; namespace { // used internally // using play::PlayTestFrames_Strategy; // using play::ModelPorts; using vault::engine::JobClosure; using vault::engine::JobParameter; using vault::engine::DummyJob; // typedef play::DummyPlayConnection DummyPlaybackSetup; class MockDispatcherTable : public Dispatcher { // DummyPlaybackSetup dummySetup_; /* == mock Dispatcher implementation == */ FrameCoord locateRelative (FrameCoord const&, FrameCnt frameOffset) { UNIMPLEMENTED ("dummy implementation of the core dispatch operation"); } bool isEndOfChunk (FrameCnt, ModelPort port) { UNIMPLEMENTED ("determine when to finish a planning chunk"); } JobTicket& accessJobTicket (ModelPort, TimeValue nominalTime) { UNIMPLEMENTED ("dummy implementation of the model backbone / segmentation"); } public: ModelPort provideMockModelPort() { // ModelPorts mockModelPorts = dummySetup_.provide_testModelPorts(); // return *mockModelPorts; // using just the first dummy port } }; /// @deprecated this setup is confusing and dangerous (instance identity is ambiguous) lib::Depend mockDispatcher; template inline auto defineSpec (HashVal seed, IT&& prereq) { using SpecTuple = std::tuple; return lib::singleValIterator( /////////////////////////////////////////////TICKET #1297 : multiplicity per channel will be removed here SpecTuple(DummyJob::getFunctor() , seed , std::forward (prereq))); } inline auto defineSimpleSpec (HashVal seed =0) { return defineSpec (seed, lib::nilIterator()); } }//(End)internal test helpers.... #if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1221 #endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1221 /** * Mock for... * * @see JobPlanningSetup_test * @see DispatcherInterface_test * */ class MockJobTicket : public JobTicket { public: MockJobTicket() : JobTicket{defineSimpleSpec()} { } MockJobTicket (HashVal seed) : JobTicket{defineSimpleSpec (seed)} { } template MockJobTicket (HashVal seed, IT&& prereq) : JobTicket{defineSpec (seed, std::forward (prereq))} { } bool verify_associated (Job const&) const; static bool isAssociated (Job const&, JobTicket const&); private: }; class MockSegmentation : public Segmentation { std::deque tickets_; public: MockSegmentation() : Segmentation{} , tickets_{} { } MockSegmentation (std::initializer_list specs) : MockSegmentation{} { for (auto& spec : specs) { JobTicket& newTicket = buildTicketFromSpec (spec); auto start = spec.retrieveAttribute