Lumiera  0.pre.03
»edit your freedom«
dispatcher-interface-test.cpp
Go to the documentation of this file.
1 /*
2  DispatcherInterface(Test) - document and verify dispatcher for frame job creation
3 
4  Copyright (C)
5  2012, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
21 #include "steam/play/timings.hpp"
22 #include "lib/time/timevalue.hpp"
23 #include "lib/util.hpp"
24 
25 #include <utility>
26 
27 using test::Test;
28 
29 
30 namespace steam {
31 namespace engine{
32 namespace test {
33 
35  using lib::time::Offset;
36  using lib::time::Time;
37  using play::Timings;
38 
39  using asset::Pipe;
40  using PID = asset::ID<Pipe>;
41  using mobject::ModelPort;
42  using lumiera::error::LUMIERA_ERROR_LOGIC;
43 
44 
45 
46 
47 
48 
49  /***************************************************************/
59  {
60 
61  virtual void
62  run (Arg)
63  {
64  seedRand();
68  }
69 
70 
75  void
77  {
78  MockDispatcher dispatcher;
79  auto [port,sink] = dispatcher.getDummyConnection(1);
80  CHECK (1 == dispatcher.resolveModelPort (port));
81 
82  // but when using some arbitrary unrelated ModelPort...
83  PID dazedPipe = Pipe::query ("id(dazed)");
84  ModelPort evil = reinterpret_cast<ModelPort&> (dazedPipe);
85  VERIFY_ERROR (LOGIC, dispatcher.resolveModelPort(evil));
86  }
87 
88 
89 
95  void
97  {
98  MockDispatcher dispatcher{MakeRec() // a first active segment
99  .attrib("start", Time{0,10}) // covering the time [10s ... 20s[
100  .attrib("after", Time{0,20})
101  .attrib("mark", 23) // pipeline-Hash used as marker to verify proper access
102  .genNode()
103  ,MakeRec() // add a second Segment
104  .attrib("start", Time{0,20}) // covering the rest of the timeline from 20s on
105  .attrib("mark", 45)
106  .genNode()};
107  size_t portIDX = 1;
108  // Dispatcher-Interface: access JobTicket
109  JobTicket& ticket0 = dispatcher.getJobTicketFor (portIDX, -Time{0,5});
110  JobTicket& ticket1 = dispatcher.getJobTicketFor (portIDX, Time{0,15});
111  JobTicket& ticket2 = dispatcher.getJobTicketFor (portIDX, Time{0,25});
112 
113  CHECK ( ticket0.empty()); // this ticket was drawn from an undefined part of the timeline
114  CHECK (not ticket1.empty()); // while this ticket belongs to the first segment
115  CHECK (not ticket2.empty()); // and this to the second segment
116 
117  Job job0 = ticket0.createJobFor(-Time{0,5});
118  Job job1 = ticket1.createJobFor(Time{0,15});
119  Job job2 = ticket2.createJobFor(Time{0,25});
120 
121  CHECK (MockJob::isNopJob(job0));
122 
123  CHECK (Time(0,15) == job1.parameter.nominalTime);
124  CHECK (23 == job1.parameter.invoKey.part.a); // proof that this job is connected to segment #1
125 
126  CHECK (Time(0,25) == job2.parameter.nominalTime);
127  CHECK (45 == job2.parameter.invoKey.part.a); // and this one to segment #2
128  }
129 
130 
131 
137  void
139  {
140  MockDispatcher dispatcher{MakeRec() // a single segment covering the complete time-axis
141  .attrib("mark", 555) // marker to demonstrate proper connectivity
142  .genNode()};
143 
144  play::Timings timings (FrameRate::PAL);
145  auto [port,sink] = dispatcher.getDummyConnection(1);
146 
147  // Dispatcher-Interface: pipeline builder...
148  auto pipeline = dispatcher.forCalcStream (timings)
149  .timeRange(Time{200,0}, Time{300,0})
150  .pullFrom (port)
151  .feedTo (sink);
152 
153  CHECK (not isnil (pipeline));
154  CHECK (5 == pipeline.currFrameNr()); // 5 * 1/25sec = 200ms
155 
156  Job job = pipeline.buildJob(); // invoke the JobPlanning to build a Job for the first frame
157  CHECK (Time(200,0) == job.parameter.nominalTime);
158  CHECK (555 == job.parameter.invoKey.part.a); // the marker shows that this job is connected properly
159 
160  ++pipeline; // iterate to advance to the next frame
161  CHECK (not isnil (pipeline));
162  CHECK (6 == pipeline.currFrameNr());
163  job = pipeline.buildJob(); // build job for the next frame
164  CHECK (Time(240,0) == job.parameter.nominalTime);
165  CHECK (555 == job.parameter.invoKey.part.a);
166 
167  ++pipeline;
168  CHECK (7 == pipeline.currFrameNr());
169  job = pipeline.buildJob();
170  CHECK (Time(280,0) == job.parameter.nominalTime);
171 
172  ++pipeline; // iterate beyond end point
173  CHECK (isnil (pipeline)); // pipeline exhausted
174  }
175  };
176 
177 
179  LAUNCHER (DispatcherInterface_test, "unit engine");
180 
181 
182 
183 }}} // namespace steam::engine::test
size_t resolveModelPort(ModelPort modelPort) override
translate a generic ModelPort spec into the specific index number applicable at the Timeline referred...
Mock data structures to support implementation testing of render job planning and frame dispatch...
Definition: run.hpp:40
Framerate specified as frames per second.
Definition: timevalue.hpp:655
Generic frame timing specification.
Definition: timings.hpp:86
A mocked frame Dispatcher setup without any backing model.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
play::test::DummyOutputLink getDummyConnection(uint index)
The faked builder/playback setup provides some preconfigured ModelPort and corresponding DataSink han...
Steam-Layer implementation namespace root.
structural asset corresponding to the part of the model forming a processing pipe for generating medi...
Definition: pipe.hpp:70
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
Abstract Base Class for all testcases.
Definition: run.hpp:53
Simplistic test class runner.
void seedRand()
draw a new random seed from a common nucleus, and re-seed the default-Gen.
Definition: suite.cpp:211
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
static PPipe query(string const &properties)
convenience shortcut for retrieving default configured pipes
Definition: pipe.cpp:57
Handle designating a point within the model, where actually output data can be pulled.
Definition: model-port.hpp:95
static bool isNopJob(Job const &)
Offset measures a distance in time.
Definition: timevalue.hpp:358
How to define a timing specification or constraint.
Individual frame rendering task, forwarding to a closure.
Definition: job.h:268
a family of time value like entities and their relationships.
static const FrameRate PAL
predefined constant for PAL framerate
Definition: timevalue.hpp:671
execution plan for pulling a specific exit node.
Definition: job-ticket.hpp:78
Job createJobFor(Time nominalTime)
Core operation: build a concrete render job based on this blueprint.
Definition: job-ticket.cpp:71