31 #include <boost/random/linear_congruential.hpp> 46 typedef boost::rand48 PseudoRandom;
65 static uint base(10 + rand() % 990);
68 return (seq+1) * (base+family);
73 accessAsTestFrame (
void* memoryLocation)
75 REQUIRE (memoryLocation);
76 return *
reinterpret_cast<TestFrame*
> (memoryLocation);
94 template<u
int CHA, u
int FRA>
96 : vector<vector<TestFrame>>
98 typedef vector<vector<TestFrame>> VECT;
103 for (uint i=0; i<CHA; ++i)
108 getFrame (uint seqNr, uint chanNr=0)
110 if (chanNr >= this->size())
112 WARN (
test,
"Growing table of test frames to %d channels, " 113 "which is > the default (%d)", chanNr, CHA);
116 ENSURE (chanNr < this->size());
117 vector<TestFrame>& channel = at(chanNr);
119 if (seqNr >= channel.size())
121 WARN_IF (seqNr >= FRA,
test,
122 "Growing channel #%d of test frames to %d elements, " 123 "which is > the default (%d)", chanNr, seqNr, FRA);
124 for (uint i=channel.size(); i<=seqNr; ++i)
125 channel.push_back (
TestFrame (i,chanNr));
127 ENSURE (seqNr < channel.size());
129 return channel[seqNr];
133 const uint INITIAL_CHAN = 20;
134 const uint INITIAL_FRAMES = 100;
138 std::unique_ptr<TestFrames> testFrames;
142 accessTestFrame (uint seqNr, uint chanNr)
144 if (!testFrames) testFrames.reset (
new TestFrames);
146 return testFrames->getFrame(seqNr,chanNr);
157 return accessTestFrame (seqNr, 0);
163 return accessTestFrame (seqNr,chanNr);
177 TestFrame::~TestFrame()
183 TestFrame::TestFrame(uint seq, uint family)
187 ASSERT (0 < distinction_);
192 TestFrame::TestFrame (
TestFrame const& o)
193 : distinction_(o.distinction_)
196 memcpy (data_, o.data_, BUFFSIZ);
200 TestFrame::operator= (
TestFrame const& o)
202 if (DISCARDED == stage_)
203 throw new error::Logic (
"target TestFrame is already dead");
206 distinction_ = o.distinction_;
208 memcpy (data_, o.data_, BUFFSIZ);
221 TestFrame::isAlive (
void* memLocation)
223 TestFrame& candidate (accessAsTestFrame (memLocation));
224 return candidate.isSane()
229 TestFrame::isDead (
void* memLocation)
231 TestFrame& candidate (accessAsTestFrame (memLocation));
232 return candidate.isSane()
237 TestFrame::operator== (
void* memLocation)
const 239 TestFrame& candidate (accessAsTestFrame (memLocation));
240 return candidate.isSane()
241 && candidate == *
this;
245 TestFrame::contentEquals (
TestFrame const& o)
const 247 for (uint i=0; i<BUFFSIZ; ++i)
248 if (data_[i] != o.data_[i])
254 TestFrame::verifyData()
const 256 PseudoRandom gen(distinction_);
257 for (uint i=0; i<BUFFSIZ; ++i)
258 if (data_[i] !=
char(gen() % CHAR_MAX))
264 TestFrame::buildData()
266 PseudoRandom gen(distinction_);
267 for (uint i=0; i<BUFFSIZ; ++i)
268 data_[i] =
char(gen() % CHAR_MAX);
273 TestFrame::isAlive()
const 275 return (CREATED == stage_)
280 TestFrame::isDead()
const 282 return (DISCARDED == stage_);
286 TestFrame::isSane()
const 288 return ( (CREATED == stage_)
290 ||(DISCARDED == stage_))
static bool isAlive(void *memLocation)
Helper to verify that a given memory location holds an active TestFrame instance (created, not yet destroyed)
Mock data frame for simulated rendering.
allocated buffer, returned from client
TestFrame & testData(uint seqNr)
Helper to access a specific frame of test data at a fixed memory location.
Steam-Layer implementation namespace root.
Derived specific exceptions within Lumiera's exception hierarchy.
void resetTestFrames()
discards all the TestFrame instances and initialises an empty table of test frames ...
uint64_t generateDistinction(uint seq, uint family)
Lumiera error handling (C++ interface).
Unit test helper to generate fake test data frames.
static bool isDead(void *memLocation)
Helper to verify a given memory location holds an already destroyed TestFrame instance.