Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
buffer-provider-protocol-test.cpp
Go to the documentation of this file.
1/*
2 BufferProviderProtocol(Test) - demonstration of buffer provider usage cycle
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/error.hpp"
20#include "lib/test/run.hpp"
23#include "lib/util-foreach.hpp"
28
30using util::for_each;
31
32
33namespace steam {
34namespace engine{
35namespace test {
36
37 using lib::test::Dummy;
38
40 using LERR_(LIFECYCLE);
41 using LERR_(LOGIC);
42
43
44 namespace { // Test fixture
45
46 const uint TEST_SIZE = 1024*1024;
47 const uint TEST_ELMS = 20;
48
49
50 void
52 {
53 UNIMPLEMENTED ("some verifiable test/dummy buffer accessing operations");
54 }
55
56 }
57
58
59 /**************************************************************************/
70 class BufferProviderProtocol_test : public Test
71 {
72 virtual void
80
81
82 void
84 {
85 // Create Test fixture.
86 // In real usage, a suitable memory/frame/buffer provider
87 // will be preconfigured, depending on the usage context
89
90 BuffHandle buff = provider.lockBufferFor<TestFrame>();
91 CHECK (buff.isValid());
92 CHECK (sizeof(TestFrame) <= buff.size());
93 buff.accessAs<TestFrame>() = testData(0);
94
95 TestFrame& content = buff.accessAs<TestFrame>();
96 CHECK (testData(0) == content);
97
98 buff.emit();
99 buff.release();
100 CHECK (!buff.isValid());
101 VERIFY_ERROR (LIFECYCLE, buff.accessAs<TestFrame>() );
102
104 CHECK (checker.buffer_was_used (0));
105 CHECK (checker.buffer_was_closed (0));
106
107 CHECK (testData(0) == checker.accessMemory (0));
108 }
109
110
111 void
113 {
114#if false
115 // Create Test fixture.
116 // In real usage, a suitable memory/frame/buffer provider
117 // will be preconfigured, depending on the usage context
119
120 BuffDescr desc1 = provider.getDescriptor<TestFrame>(); // note: implies also sizeof(TestFrame)
121 BuffDescr desc2 = provider.getDescriptorFor(TEST_SIZE);
122 CHECK (desc1.verifyValidity());
123 CHECK (desc2.verifyValidity());
124
125 uint num1 = provider.announce(TEST_ELMS, desc1);
126 uint num2 = provider.announce(TEST_ELMS, desc2);
127 CHECK (num1 == TEST_ELMS);
128 CHECK (0 < num2 && num2 <=TEST_ELMS);
129
130 const size_t STORAGE_SIZE = BuffTable::Storage<2*TEST_ELMS>::size;
131 char storage[STORAGE_SIZE];
132 BuffTable& tab =
133 BuffTable::prepare(STORAGE_SIZE, storage)
134 .announce(num1, desc1)
135 .announce(num2, desc2)
136 .build();
137
138 tab.lockBuffers();
139 for_each (tab.buffers(), do_some_calculations);
140 tab.releaseBuffers();
141
143 CHECK (checker.all_buffers_released());
144#endif
145 }
146
147
148 void
150 {
152 BuffDescr type_A = provider.getDescriptorFor(sizeof(TestFrame));
153 BuffDescr type_B = provider.getDescriptorFor(sizeof(int));
154 BuffDescr type_C = provider.getDescriptor<int>();
155
156 BuffHandle handle_A = provider.lockBuffer(type_A);
157 BuffHandle handle_B = provider.lockBuffer(type_B);
158 BuffHandle handle_C = provider.lockBuffer(type_C);
159
160 CHECK (handle_A);
161 CHECK (handle_B);
162 CHECK (handle_C);
163
164 CHECK (sizeof(TestFrame) == handle_A.size());
165 CHECK (sizeof( int ) == handle_B.size());
166 CHECK (sizeof( int ) == handle_C.size());
167
168 TestFrame& embeddedFrame = handle_A.create<TestFrame>();
169 CHECK (isSameObject (*handle_A, embeddedFrame));
170 CHECK (embeddedFrame.isAlive());
171 CHECK (embeddedFrame.isSane());
172
173 VERIFY_ERROR (LOGIC, handle_B.create<TestFrame>()); // too small to hold a TestFrame
174 VERIFY_ERROR (LIFECYCLE, handle_C.create<int>()); // has already an attached TypeHandler (creating an int)
175
176 handle_A.release();
177 handle_B.release();
178 handle_C.release();
179
180 CHECK (embeddedFrame.isDead());
181 CHECK (embeddedFrame.isSane());
182 }
183
184
185 void
187 {
189 BuffDescr type_D = provider.getDescriptorFor(sizeof(Dummy));
190
191 Dummy::checksum() = 0;
192 BuffHandle handle_D = provider.lockBuffer(type_D);
193 CHECK (0 == Dummy::checksum()); // nothing created thus far
194
195 handle_D.create<Dummy>();
196 CHECK (0 < Dummy::checksum());
197
198 handle_D.release();
199 CHECK (0 == Dummy::checksum());
200
201 BuffHandle handle_DD = provider.lockBuffer(type_D);
202
203 CHECK (0 == Dummy::checksum());
205
206 CHECK (handle_DD.isValid());
207 try
208 {
209 handle_DD.create<Dummy>();
210 NOTREACHED ("Dummy ctor should fail");
211 }
212 catch (int val)
213 {
214 CHECK (!handle_DD.isValid());
215
216 CHECK (0 < Dummy::checksum());
217 CHECK (val == Dummy::checksum());
218 }
219
220 VERIFY_ERROR (LIFECYCLE, handle_DD.accessAs<Dummy>() );
221 VERIFY_ERROR (LIFECYCLE, handle_DD.create<Dummy>() );
222 }
223 };
224
225
228
229
230
231}}} // namespace steam::engine::test
Extension to allow placing objects right into the buffers, taking ownership.
helper for organisation of render data buffers Used during the process of _"pulling"_ a render node,...
A Dummy object for tests.
static void activateCtorFailure(bool indeed=true)
static long & checksum()
An opaque descriptor to identify the type and further properties of a data buffer.
Handle for a buffer for processing data, abstracting away the actual implementation.
BU & accessAs()
convenience shortcut: access the buffer contents casted to a specific type.
BU & create()
convenience shortcut: place and maintain an object within the buffer.
Builder & announce(uint count, BuffDescr const &type)
Interface: a facility providing and managing working buffers for media calculations.
uint announce(uint count, BuffDescr const &)
BufferProvider API: declare in advance the need for working buffers.
BuffHandle lockBufferFor(ARGS ...args)
convenience shortcut: prepare and claim ("lock") a buffer suitable to hold an object of the given typ...
BuffDescr getDescriptor(ARGS ...args)
define a "buffer type" for automatically creating an instance of the template type embedded into the ...
BuffDescr getDescriptorFor(size_t storageSize=0)
describe the kind of buffer managed by this provider
BuffHandle lockBuffer(BuffDescr const &)
BufferProvider API: retrieve a single buffer for exclusive use.
Helper for unit tests: Buffer provider reference implementation.
static DiagnosticBufferProvider & access(BufferProvider const &)
access the diagnostic API of the buffer provider
static BufferProvider & build()
build a new Diagnostic Buffer Provider instance, discard the existing one.
Mock data frame for simulated rendering.
Definition testframe.hpp:69
static bool isDead(void *memLocation)
Helper to verify a given memory location holds an already destroyed TestFrame instance.
static bool isAlive(void *memLocation)
Helper to verify that a given memory location holds an active TestFrame instance (created,...
A facility for writing unit-tests targeting the BufferProvider interface.
Lumiera error handling (C++ interface).
#define LERR_(_NAME_)
Definition error.hpp:45
unsigned int uint
Definition integral.hpp:29
TestFrame & testData(uint seqNr, uint chanNr)
Helper to access a specific frame of test data at a fixed memory location.
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities.
Definition util.hpp:421
disable_if< can_IterForEach< Container >, FUN > for_each(Container const &coll, FUN doIt)
operate on all elements of a STL container.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Tables of buffer handles and corresponding dereferenced buffer pointers.
Definition bufftable.hpp:58
static Builder & prepare(const size_t STORAGE_SIZE, void *storage)
Definition bufftable.hpp:97
A collection of frequently used helper functions to support unit testing.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Unit test helper to generate fake test data frames.
unittest helper code: test dummy objects to track instances.
Perform operations "for each element" of a collection.