40 using std::unique_ptr;
52 using LERR_(LIFECYCLE);
57 const size_t TEST_MAX_SIZE = 1024 * 1024;
59 const size_t SIZE_A = 1 + rand() % TEST_MAX_SIZE;
60 const size_t SIZE_B = 1 + rand() % TEST_MAX_SIZE;
63 void*
const SOME_POINTER = &JUST_SOMETHING;
70 TY* ptr =
reinterpret_cast<TY*
> (entry.access());
89 unique_ptr<BufferMetadata>
meta_;
94 CHECK (ensure_proper_fixture());
95 verifyBasicProperties();
102 ensure_proper_fixture()
107 return (SIZE_A != SIZE_B)
108 && (JUST_SOMETHING != meta_->key(SIZE_A))
109 && (JUST_SOMETHING != meta_->key(SIZE_B))
115 verifyBasicProperties()
131 CHECK ( & meta_->get(key));
132 CHECK ( & meta_->get(key1));
133 CHECK ( & meta_->get(key2));
135 CHECK ( isSameObject (meta_->get(key), meta_->get(key)));
136 CHECK ( isSameObject (meta_->get(key), meta_->get(key1)));
137 CHECK (!isSameObject (meta_->get(key), meta_->get(key2)));
141 CHECK (
NIL == m1.state());
142 CHECK (!meta_->isLocked(key));
149 CHECK (!isSameObject (m1,m2));
150 CHECK (
NIL == m1.state());
151 CHECK (
LOCKED == m2.state());
152 CHECK (SOME_POINTER == m2.access());
155 HashVal keyX = meta_->key(key1, SOME_POINTER);
156 CHECK (meta_->isLocked(keyX));
157 CHECK (keyX != key1);
160 CHECK ( isSameObject (m1, meta_->get(key)));
161 CHECK ( isSameObject (m1, meta_->get(key1)));
162 CHECK ( isSameObject (m2, meta_->get(keyX)));
163 CHECK ( key1 == m2.parentKey());
166 CHECK (
LOCKED == m2.state());
169 CHECK (SOME_POINTER == m2.access());
170 CHECK ( meta_->isLocked(keyX));
171 CHECK ( meta_->isKnown(keyX));
175 CHECK (!meta_->isLocked(keyX));
176 CHECK ( meta_->isKnown(keyX));
177 CHECK ( meta_->isKnown(key1));
180 CHECK ( isSameObject (m2, meta_->get(keyX)));
183 meta_->release(keyX);
184 CHECK (!meta_->isLocked(keyX));
185 CHECK (!meta_->isKnown(keyX));
186 CHECK ( meta_->isKnown(key1));
202 TypeHandler attachTestFrame = TypeHandler::create<TestFrame>();
211 bufferType1 = meta_->key(bufferType1, transaction1);
212 rawBuffType = meta_->key(rawBuffType, transaction2);
217 typedef char RawBuffer[SIZE_B];
218 void* storage = malloc (2*SIZE_B);
221 RawBuffer* rawbuf = (RawBuffer*)storage;
232 CHECK (
LOCKED == f0.state());
233 CHECK (
LOCKED == f1.state());
234 CHECK (
LOCKED == f2.state());
235 CHECK (
LOCKED == r0.state());
236 CHECK (
LOCKED == r1.state());
238 CHECK (transaction1 == f0.localKey());
239 CHECK (transaction1 == f1.localKey());
240 CHECK (transaction1 == f2.localKey());
241 CHECK (transaction2 == r0.localKey());
242 CHECK (transaction2 == r1.localKey());
245 CHECK (f0.access() == frames+0);
246 CHECK (f1.access() == frames+1);
247 CHECK (f2.access() == frames+2);
248 CHECK (r0.access() == rawbuf+0);
249 CHECK (r1.access() == rawbuf+1);
252 CHECK (defaultFrame == f0.access());
253 CHECK (defaultFrame == f1.access());
254 CHECK (defaultFrame == f2.access());
264 accessAs<TestFrame> (f0) =
testData(1);
265 accessAs<TestFrame> (f1) =
testData(2);
266 accessAs<TestFrame> (f2) =
testData(3);
272 CHECK (TestFrame::isAlive (f0.access()));
273 CHECK (TestFrame::isAlive (f1.access()));
274 CHECK (TestFrame::isAlive (f2.access()));
276 strncpy (& accessAs<char> (r0), randStr(SIZE_B - 1).c_str(), SIZE_B);
277 strncpy (& accessAs<char> (r1), randStr(SIZE_B - 1).c_str(), SIZE_B);
293 meta_->release(handle_f0);
294 meta_->release(handle_f1);
295 meta_->release(handle_f2);
296 meta_->release(handle_r0);
297 meta_->release(handle_r1);
299 CHECK (TestFrame::isDead (&frames[0]));
300 CHECK (TestFrame::isDead (&frames[1]));
301 CHECK (TestFrame::isDead (&frames[2]));
307 CHECK (!meta_->isLocked(handle_f0));
308 CHECK (!meta_->isLocked(handle_f1));
309 CHECK (!meta_->isLocked(handle_f2));
310 CHECK (!meta_->isLocked(handle_r0));
311 CHECK (!meta_->isLocked(handle_r1));
320 CHECK (
NIL == meta_->get(key).state());
321 CHECK (meta_->get(key).isTypeKey());
322 CHECK (!meta_->isLocked(key));
332 CHECK (
LOCKED == entry.state());
333 CHECK (!entry.isTypeKey());
335 CHECK (SOME_POINTER == entry.access());
341 CHECK (
EMITTED == entry.state());
342 CHECK (entry.isLocked());
347 CHECK (
EMITTED == entry.state());
350 CHECK (
FREE == entry.state());
351 CHECK (!entry.isLocked());
352 CHECK (!entry.isTypeKey());
362 void* OTHER_LOCATION =
this;
363 entry.lock (OTHER_LOCATION);
364 CHECK (
LOCKED == entry.state());
365 CHECK (entry.isLocked());
370 CHECK (
BLOCKED == entry.state());
376 CHECK (OTHER_LOCATION == entry.access());
379 CHECK (!entry.isLocked());
382 meta_->lock(key, SOME_POINTER);
383 CHECK (entry.isLocked());
387 CHECK (
BLOCKED == entry.state());
388 CHECK (SOME_POINTER == entry.access());
392 CHECK (meta_->isKnown(entry));
393 CHECK (entry.isLocked());
396 meta_->release(entry);
397 CHECK (!meta_->isKnown(entry));
398 CHECK ( meta_->isKnown(key));
allocated buffer, no longer in use
Mock data frame for simulated rendering.
AnyPair entry(Query< TY > const &query, typename WrapReturn< TY >::Wrapper &obj)
helper to simplify creating mock table entries, wrapped correctly
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
allocated buffer blocked by protocol failure
TestFrame & testData(uint seqNr)
Helper to access a specific frame of test data at a fixed memory location.
allocated buffer, returned from client
allocated buffer actively in use
Entry & mark(BufferState newState)
Buffer state machine.
Steam-Layer implementation namespace root.
string randStr(size_t len)
create garbage string of given length
an opaque ID to be used by the BufferProvider implementation.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
Lumiera error handling (C++ interface).
size_t HashVal
a STL compatible hash value
A pair of functors to maintain a datastructure within a buffer.
abstract entry, not yet allocated
Unit test helper to generate fake test data frames.
A complete metadata Entry, based on a Key.
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.