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)
5  2011, 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"
20 
25 
26 
27 
28 namespace steam {
29 namespace play {
30 namespace test {
31 
35 
36 
37 
38 
39  /***************************************************************/
46  class OutputSlotProtocol_test : public Test
47  {
48  virtual void
49  run (Arg)
50  {
51  verifyStandardCase();
52  }
53 
54 
55  void
56  verifyStandardCase()
57  {
58  // Create Test fixture.
59  // In real usage, the OutputSlot will be preconfigured
60  // (Media format, number of channels, physical connections)
61  // and then registered with / retrieved from an OutputManager
63 
64  // Client claims the OutputSlot
65  // and opens it for exclusive use.
66  OutputSlot::Allocation& alloc = oSlot.allocate();
67 
68  // Now the client is able to prepare
69  // "calculation streams" for the individual
70  // Channels to be output through this slot.
71  OutputSlot::OpenedSinks sinks = alloc.getOpenedSinks();
72  DataSink sink1 = *sinks;
73  DataSink sink2 = *++sinks;
74 
75  // within the frame-calculation "loop"
76  // we perform a data exchange cycle
77  FrameCnt frameNr = 123;
78  BuffHandle buff00 = sink1.lockBufferFor (frameNr);
79  BuffHandle buff10 = sink2.lockBufferFor (frameNr);
80 
81  // rendering process calculates content....
82  buff00.accessAs<TestFrame>() = testData(0,0);
83 
84  // while further frames might be processed in parallel
85  BuffHandle buff11 = sink2.lockBufferFor (++frameNr);
86  buff11.accessAs<TestFrame>() = testData(1,1);
87  buff10.accessAs<TestFrame>() = testData(1,0);
88 
89  // Now it's time to emit the output
90  sink2.emit (frameNr-1, buff10);
91  sink2.emit (frameNr , buff11);
92  sink1.emit (frameNr-1, buff00);
93  // that's all for the client
94 
95  // Verify sane operation....
96  DiagnosticOutputSlot& checker = DiagnosticOutputSlot::access(oSlot);
97  CHECK ( checker.frame_was_allocated (0,123));
98  CHECK (!checker.frame_was_allocated (0,124));
99  CHECK ( checker.frame_was_allocated (1,123));
100  CHECK ( checker.frame_was_allocated (1,124));
101 
102  CHECK (checker.output_was_closed (0,0));
103  CHECK (checker.output_was_closed (1,0));
104  CHECK (checker.output_was_closed (1,1));
105 
106  CHECK ( checker.output_was_emitted (0,0));
107  CHECK (!checker.output_was_emitted (0,1));
108  CHECK ( checker.output_was_emitted (1,0));
109  CHECK ( checker.output_was_emitted (1,1));
110 
111  DiagnosticOutputSlot::OutFrames stream0 = checker.getChannel(0);
112  DiagnosticOutputSlot::OutFrames stream1 = checker.getChannel(1);
113 
114  CHECK ( stream0);
115  CHECK (*stream0 == testData(0,0)); ++stream0;
116  CHECK (!stream0);
117 
118  CHECK ( stream1);
119  CHECK (*stream1 == testData(1,0)); ++stream1;
120  CHECK (*stream1 == testData(1,1)); ++stream1;
121  CHECK (!stream1);
122  }
123  };
124 
125 
127  LAUNCHER (OutputSlotProtocol_test, "unit play");
128 
129 
130 
131 }}} // namespace steam::play::test
Mock data frame for simulated rendering.
Definition: testframe.hpp:68
Definition: run.hpp:40
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.
Simplistic 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:73
Handle for a buffer for processing data, abstracting away the actual implementation.
Definition: buffhandle.hpp:111
static OutputSlot & build()
build a new Diagnostic Output Slot instance, discard the existing one.
Unit test helper to generate fake test data frames.
TestFrame & testData(uint seqNr, uint chanNr)
Helper to access a specific frame of test data at a fixed memory location.
Definition: testframe.cpp:186