From db3ea6638daab220954f4f1a65c8c721374dc4fc Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 1 Nov 2011 03:11:43 +0100 Subject: [PATCH] use boost::random to ensure distinct test frame contents --- src/tool/try.cpp | 52 +++++++--------------- tests/46engine.tests | 2 +- tests/components/proc/engine/testframe.cpp | 39 ++++++++-------- tests/components/proc/engine/testframe.hpp | 31 ++++--------- 4 files changed, 44 insertions(+), 80 deletions(-) diff --git a/src/tool/try.cpp b/src/tool/try.cpp index 9e68a90a5..7b73f4c1f 100644 --- a/src/tool/try.cpp +++ b/src/tool/try.cpp @@ -20,53 +20,31 @@ // 1/11 - integer floor and wrap operation(s) // 1/11 - how to fetch the path of the own executable -- at least under Linux? // 10/11 - simple demo using a pointer and a struct +// 11/11 - using the boost random number generator(s) #include +#include +#include + +using boost::lexical_cast; using std::cout; - - - -/** - * custom datastructure - * holding a constant char array with "hey" - */ -struct MyStruct - { - char data_[3]; - const int length_; - - MyStruct() - : length_(3) - { - const char *tmp = "hey"; - for (int i=0; ilength_; ++i) - cout << myPointer->data_[i]; - - cout << "\n"; - } +using std::endl; int -main (int, char**) //(int argc, char* argv[]) +main (int cnt, char* argv[]) { - printMyStruct (&theStruct); + + int32_t seed = (2 == cnt)? lexical_cast (argv[1]) : 42; + + boost::rand48 ranGen(seed); + + cout << "seed = "<< seed << endl; + for (uint i=0; i< 100; ++i) + cout << ranGen() % CHAR_MAX <<"__"; cout << "\n.gulp.\n"; diff --git a/tests/46engine.tests b/tests/46engine.tests index aca5be526..293dc00c7 100644 --- a/tests/46engine.tests +++ b/tests/46engine.tests @@ -2,7 +2,7 @@ TESTING "Component Test Suite: Render Engine parts" ./test-components --group=en -PLANNED "Test support: dummy frames" TestFrame_test < #include #include #include #include -using std::memcpy; -using std::vector; + namespace engine { namespace test { + using std::vector; + using std::memcpy; + + typedef boost::rand48 PseudoRandom; + namespace error = lumiera::error; namespace { // hidden local support facilities.... /** @internal helper for generating unique test frames. - * The "discriminator" is used as a stepping size when + * This "discriminator" is used as a random seed when * filling the test frame data buffers. It is generated * to be different on adjacent frames of the same series, * as well as to differ to all near by neighbouring channels. @@ -50,10 +55,10 @@ namespace test { * @param family the channel this frame belongs to */ uint64_t - generateDiscriminator(uint seq, uint family) + generateDistinction(uint seq, uint family) { // random offset, but fixed per executable run - static uint base(10 + rand() % 90); + static uint base(10 + rand() % 990); // use the family as stepping return (seq+1) * (base+family); @@ -128,6 +133,7 @@ namespace test { boost::scoped_ptr testFrames; + TestFrame& accessTestFrame (uint seqNr, uint chanNr) { @@ -162,6 +168,7 @@ namespace test { + /* ===== TestFrame class ===== */ TestFrame::~TestFrame() { @@ -170,16 +177,16 @@ namespace test { TestFrame::TestFrame(uint seq, uint family) - : discriminator_(generateDiscriminator(seq,family)) + : distinction_(generateDistinction (seq,family)) , stage_(CREATED) { - ASSERT (0 < discriminator_); + ASSERT (0 < distinction_); buildData(); } TestFrame::TestFrame (TestFrame const& o) - : discriminator_(o.discriminator_) + : distinction_(o.distinction_) , stage_(CREATED) { memcpy (data_, o.data_, BUFFSIZ); @@ -192,7 +199,7 @@ namespace test { throw new error::Logic ("target TestFrame is already dead"); if (this != &o) { - discriminator_ = o.discriminator_; + distinction_ = o.distinction_; stage_ = CREATED; memcpy (data_, o.data_, BUFFSIZ); } @@ -242,9 +249,9 @@ namespace test { bool TestFrame::verifyData() const { - char c(0); + PseudoRandom gen(distinction_); for (uint i=0; i #include #include -//using std::tr1::shared_ptr; -//using std::string; - - namespace engine { namespace test { -//class TestPlacement; - /** * Mock data frame for simulated rendering. * A test frame can be created and placed instead of a real data frame. @@ -52,12 +43,13 @@ namespace test { * * Each TestFrame is automatically filled with pseudo random data; * multiple frames are arranged in sequences and channels, causing the random data - * to be reproducible yet different in each frame. The lifecycle of each TestFrame - * is tracked and marked in an embedded state field. Moreover, the contents of - * the data block can be verified, because the sequence of bytes is reproducible, + * to be reproducible yet different within each frame. TestFrame's lifecycle is + * tracked and marked in an embedded state field. Moreover, the contents of the + * data block can be verified, because the sequence of bytes is reproducible, * based on the channel and sequence number of the test frame. * - * @todo WIP-WIP-WIP 9/11 + * @see TestFrame_test + * @see OutputSlotProtocol_test * */ class TestFrame @@ -68,7 +60,7 @@ namespace test { static const size_t BUFFSIZ = 1024; - uint64_t discriminator_; + uint64_t distinction_; StageOfLife stage_; char data_[BUFFSIZ]; @@ -79,7 +71,7 @@ namespace test { TestFrame (TestFrame const&); TestFrame& operator= (TestFrame const&); - /** Helper to verify a given memory location holds + /** Helper to verify that a given memory location holds * an active TestFrame instance (created, not yet destroyed) * @return true if the TestFrame datastructure is intact and * marked as still alive. @@ -101,9 +93,7 @@ namespace test { private: bool contentEquals (TestFrame const& o) const; - bool verifyData() const; - char generate (char) const; - + bool verifyData() const; void buildData (); }; @@ -126,10 +116,5 @@ namespace test { - - /* == some test data to check == */ - // extern const lib::time::Duration LENGTH_TestClip; - - }} // namespace engine::test #endif