Lumiera  0.pre.03
»edit your freedom«
output-slot-protocol-test.cpp
Go to the documentation of this file.
1 /*
2  OutputSlotProtocol(Test) - covering the basic usage cycle of an output slot
3 
4  Copyright (C) Lumiera.org
5  2011, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 
34 
35 
36 
37 namespace steam {
38 namespace play {
39 namespace test {
40 
42  using steam::engine::test::testData;
44 
45 
46 
47 
48  /***************************************************************/
55  class OutputSlotProtocol_test : public Test
56  {
57  virtual void
58  run (Arg)
59  {
60  verifyStandardCase();
61  }
62 
63 
64  void
65  verifyStandardCase()
66  {
67  // Create Test fixture.
68  // In real usage, the OutputSlot will be preconfigured
69  // (Media format, number of channels, physical connections)
70  // and then registered with / retrieved from an OutputManager
72 
73  // Client claims the OutputSlot
74  // and opens it for exclusive use.
75  OutputSlot::Allocation& alloc = oSlot.allocate();
76 
77  // Now the client is able to prepare
78  // "calculation streams" for the individual
79  // Channels to be output through this slot.
80  OutputSlot::OpenedSinks sinks = alloc.getOpenedSinks();
81  DataSink sink1 = *sinks;
82  DataSink sink2 = *++sinks;
83 
84  // within the frame-calculation "loop"
85  // we perform a data exchange cycle
86  FrameCnt frameNr = 123;
87  BuffHandle buff00 = sink1.lockBufferFor (frameNr);
88  BuffHandle buff10 = sink2.lockBufferFor (frameNr);
89 
90  // rendering process calculates content....
91  buff00.accessAs<TestFrame>() = testData(0,0);
92 
93  // while further frames might be processed in parallel
94  BuffHandle buff11 = sink2.lockBufferFor (++frameNr);
95  buff11.accessAs<TestFrame>() = testData(1,1);
96  buff10.accessAs<TestFrame>() = testData(1,0);
97 
98  // Now it's time to emit the output
99  sink2.emit (frameNr-1, buff10);
100  sink2.emit (frameNr , buff11);
101  sink1.emit (frameNr-1, buff00);
102  // that's all for the client
103 
104  // Verify sane operation....
105  DiagnosticOutputSlot& checker = DiagnosticOutputSlot::access(oSlot);
106  CHECK ( checker.frame_was_allocated (0,123));
107  CHECK (!checker.frame_was_allocated (0,124));
108  CHECK ( checker.frame_was_allocated (1,123));
109  CHECK ( checker.frame_was_allocated (1,124));
110 
111  CHECK (checker.output_was_closed (0,0));
112  CHECK (checker.output_was_closed (1,0));
113  CHECK (checker.output_was_closed (1,1));
114 
115  CHECK ( checker.output_was_emitted (0,0));
116  CHECK (!checker.output_was_emitted (0,1));
117  CHECK ( checker.output_was_emitted (1,0));
118  CHECK ( checker.output_was_emitted (1,1));
119 
120  DiagnosticOutputSlot::OutFrames stream0 = checker.getChannel(0);
121  DiagnosticOutputSlot::OutFrames stream1 = checker.getChannel(1);
122 
123  CHECK ( stream0);
124  CHECK (*stream0 == testData(0,0)); ++stream0;
125  CHECK (!stream0);
126 
127  CHECK ( stream1);
128  CHECK (*stream1 == testData(1,0)); ++stream1;
129  CHECK (*stream1 == testData(1,1)); ++stream1;
130  CHECK (!stream1);
131  }
132  };
133 
134 
136  LAUNCHER (OutputSlotProtocol_test, "unit play");
137 
138 
139 
140 }}} // namespace steam::play::test
Mock data frame for simulated rendering.
Definition: testframe.hpp:60
Definition: run.hpp:49
An facility for writing unit-tests against the OutputSlot interface.
denotes an opened connection ready to receive media data for output.
Steam-Layer implementation namespace root.
BU & accessAs()
convenience shortcut: access the buffer contents casted to a specific type.
Helper for unit tests: Mock output sink.
Simple test class runner.
Extension to allow placing objects right into the buffers, taking ownership.
A front-end to support the buffer management within the render nodes.
Interface: Generic output sink.
Allocation & allocate()
claim this slot for exclusive use
Definition: output-slot.cpp:82
Handle for a buffer for processing data, abstracting away the actual implementation.
Definition: buffhandle.hpp:115
static OutputSlot & build()
build a new Diagnostic Output Slot instance, discard the existing one.
Unit test helper to generate fake test data frames.