From fe1ae51b494caf81c4673fb7c32940185037e32d Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 11 Nov 2011 01:44:01 +0100 Subject: [PATCH] WIP draft test for internal test buffer provider a test to cover a helper for writing tests ;-) --- src/proc/engine/buffer-provider.hpp | 2 +- tests/46engine.tests | 5 + .../tracking-heap-block-provider-test.cpp | 202 ++++++++++++++++++ 3 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 tests/components/proc/engine/tracking-heap-block-provider-test.cpp diff --git a/src/proc/engine/buffer-provider.hpp b/src/proc/engine/buffer-provider.hpp index ba4a4dd7f..368d54a4c 100644 --- a/src/proc/engine/buffer-provider.hpp +++ b/src/proc/engine/buffer-provider.hpp @@ -95,7 +95,7 @@ namespace engine { template BufferDescriptor getDescriptor(); - + /* === API for BuffHandle internal access === */ diff --git a/tests/46engine.tests b/tests/46engine.tests index 46c1806db..07fac0119 100644 --- a/tests/46engine.tests +++ b/tests/46engine.tests @@ -7,6 +7,11 @@ return: 0 END +TEST "Test support: dummy buffer provider" TrackingHeapBlockProvider_test < + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + + +#include "lib/error.hpp" +#include "lib/test/run.hpp" +//#include "lib/test/test-helper.hpp" +//#include "lib/util-foreach.hpp" +//#include "proc/play/diagnostic-output-slot.hpp" +#include "proc/engine/tracking-heap-block-provider.hpp" +#include "proc/engine/testframe.hpp" +//#include "proc/engine/diagnostic-buffer-provider.hpp" +#include "proc/engine/buffhandle.hpp" +//#include "proc/engine/bufftable.hpp" + +//#include +//#include +#include +#include + +//using boost::format; +//using std::string; +//using std::cout; +using std::rand; +//using util::for_each; + + +namespace engine{ +namespace test { + +// using lib::AllocationCluster; +// using mobject::session::PEffect; +// using ::engine::BuffHandle; +// using lumiera::error::LUMIERA_ERROR_LIFECYCLE; + + + namespace { // Test fixture + + const size_t TEST_ELM_SIZE = sizeof(uint); + const uint MAX_ELMS = 50; + + std::vector testNumbers(MAX_ELMS); + + + bool + has_expectedContent (uint nr, diagn::Block& memoryBlock) + { + void* mem = memoryBlock.accessMemory(); + uint data = *static_cast (mem); + + return data == testNumbers[nr]; + } + + bool + verifyUsedBlock (uint nr, diagn::Block& memoryBlock) + { + return memoryBlock.was_closed() + && has_expectedContent (nr, memoryBlock); + } + } + + + /********************************************************************** + * @test verify a test support facility, used to write mock components + * to test the lumiera engine. The TrackingHeapBlockProvider is a + * braindead implementation of the BufferProvider interface: it just + * claims new heap blocks and never de-allocates them, allowing other + * test and mock objects to verify allocated buffers after the fact. + */ + class TrackingHeapBlockProvider_test : public Test + { + virtual void + run (Arg) + { + UNIMPLEMENTED ("verify test helper"); + simpleExample(); + verifyStandardCase(); + verifyTestProtocol(); + } + + + void + simpleExample() + { + TrackingHeapBlockProvider provider; + + BuffHandle testBuff = provider.lockBufferFor(); + CHECK (testBuff); + CHECK (testBuff.accessAs().isSane()); + + uint dataID = 1 + rand() % 29; + testBuff.accessAs() = testData(dataID); + + provider.mark_emitted (testBuff); + provider.releaseBuffer(testBuff); + + diagn::Block& block0 = provider.access_or_create(0); + CHECK (block0.was_used()); + CHECK (block0.was_closed()); + + CHECK (testData(dataID) == block0.accessMemory()); + } + + + void + verifyStandardCase() + { + TrackingHeapBlockProvider provider; + + BufferDescriptor buffType = provider.getDescriptorFor(TEST_ELM_SIZE); + uint numElms = provider.announce(MAX_ELMS, buffType); + CHECK (0 < numElms); + CHECK (numElms <= MAX_ELMS); + + for (uint i=0; i() = testNumbers[i] = rand() % 100000; + provider.mark_emitted (buff); + provider.releaseBuffer(buff); + } + + for (uint nr=0; nr(0) = 20; + provider.access(1) = 21; + provider.access(2) = 22; + provider.access(3) = 23; + provider.access(4) = 24; + + bu1.accessAs() = 1; + bu2.accessAs() = 2; + bu3.accessAs() = 3; + bu4.accessAs() = 4; + bu5.accessAs() = 5; + + CHECK (20 == provider.access(0)); + CHECK (21 == provider.access(1)); + CHECK (22 == provider.access(2)); + CHECK (23 == provider.access(3)); + CHECK (24 == provider.access(4)); + + provider.mark_emitted (bu3); + provider.mark_emitted (bu1); + provider.mark_emitted (bu5); + provider.mark_emitted (bu4); + provider.mark_emitted (bu2); + + CHECK (3 == provider.access(0)); + CHECK (1 == provider.access(1)); + CHECK (5 == provider.access(2)); + CHECK (4 == provider.access(3)); + CHECK (2 == provider.access(4)); + } + }; + + + /** Register this test class... */ + LAUNCHER (TrackingHeapBlockProvider_test, "unit player"); + + + +}} // namespace engine::test