From 32f71cba6d1cc268e0b4754e6f5ced1044aa9009 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 17 Sep 2011 18:25:45 +0200 Subject: [PATCH] more test-driven brainstorming --- src/proc/engine/buffer-provider.cpp | 6 +-- src/proc/engine/buffer-provider.hpp | 4 +- src/proc/engine/buffhandle.hpp | 4 +- .../engine/buffer-provider-protocol-test.cpp | 38 ++++++++++++++++++- 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/proc/engine/buffer-provider.cpp b/src/proc/engine/buffer-provider.cpp index 57660a572..c9a2311e8 100644 --- a/src/proc/engine/buffer-provider.cpp +++ b/src/proc/engine/buffer-provider.cpp @@ -40,7 +40,7 @@ namespace engine { * currently locked and usable by client code */ bool - BufferProvider::checkValidity (BufferDescriptor const&) + BufferProvider::verifyValidity (BufferDescriptor const&) { UNIMPLEMENTED ("BufferProvider basic and default implementation"); } @@ -58,9 +58,9 @@ namespace engine { /* === BufferDescriptor and BuffHandle === */ bool - BufferDescriptor::checkValidity() const + BufferDescriptor::verifyValidity() const { - return provider_->checkValidity(*this); + return provider_->verifyValidity(*this); } diff --git a/src/proc/engine/buffer-provider.hpp b/src/proc/engine/buffer-provider.hpp index 7f8f4f99b..02f6ff262 100644 --- a/src/proc/engine/buffer-provider.hpp +++ b/src/proc/engine/buffer-provider.hpp @@ -79,12 +79,12 @@ namespace engine { /** describe the kind of buffer managed by this provider */ - BufferDescriptor getDefaultDescriptor(); + BufferDescriptor getDefaultDescriptor(); //////////////TODO really? there is no sensible "default" /* === API for BuffHandle internal access === */ - bool checkValidity (BufferDescriptor const&); + bool verifyValidity (BufferDescriptor const&); }; diff --git a/src/proc/engine/buffhandle.hpp b/src/proc/engine/buffhandle.hpp index 835d0329c..f2e9646fb 100644 --- a/src/proc/engine/buffhandle.hpp +++ b/src/proc/engine/buffhandle.hpp @@ -79,7 +79,7 @@ namespace engine { public: // using standard copy operations - bool checkValidity() const; + bool verifyValidity() const; }; @@ -143,7 +143,7 @@ namespace engine { isValid() const { return bool(pBuffer_) - && descriptor_.checkValidity(); + && descriptor_.verifyValidity(); } }; diff --git a/tests/components/proc/engine/buffer-provider-protocol-test.cpp b/tests/components/proc/engine/buffer-provider-protocol-test.cpp index c3adb7f9e..19866ebfc 100644 --- a/tests/components/proc/engine/buffer-provider-protocol-test.cpp +++ b/tests/components/proc/engine/buffer-provider-protocol-test.cpp @@ -24,10 +24,11 @@ #include "lib/error.hpp" #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" -//#include "lib/util.hpp" +#include "lib/util-foreach.hpp" //#include "proc/play/diagnostic-output-slot.hpp" #include "proc/engine/diagnostic-buffer-provider.hpp" #include "proc/engine/buffhandle.hpp" +#include "proc/engine/bufftable.hpp" //#include //#include @@ -35,6 +36,7 @@ //using boost::format; //using std::string; //using std::cout; +using util::for_each; namespace engine{ @@ -48,6 +50,9 @@ namespace test { namespace { // Test fixture + const uint TEST_SIZE = 1024*1024; + const uint TEST_ELMS = 20; + } @@ -64,6 +69,7 @@ namespace test { run (Arg) { UNIMPLEMENTED ("build a diagnostic buffer provider and perform a full lifecycle"); + verifySimpleUsage(); verifyStandardCase(); } @@ -108,6 +114,36 @@ namespace test { // will be preconfigured, depending on the usage context BufferProvider& provider = DiagnosticBufferProvider::build(); #if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #829 + + BufferDescriptor desc1 = provider.getDescriptor(); + BufferDescriptor desc2 = provider.getDescriptorFor(TEST_SIZE); + CHECK (desc1.verifyValidity()); + CHECK (desc2.verifyValidity()); + + size_t num1 = provider.announce(TEST_ELMS, desc1); + size_t num2 = provider.announce(TEST_ELMS, desc2); + CHECK (num1 == TEST_ELMS); + CHECK (0 < num2 && num2 <=TEST_ELMS); + + const size_t STORAGE_SIZE = BuffTable::Storage<2*TEST_ELMS>::size; + char storage[STORAGE_SIZE]; + BuffTable& tab = BuffTable::prepare(storage, STORAGE_SIZE); + + for (uint i=0; i < num1; ++i ) + { + tab.attachBuffer (provider.lockBufferFor (desc1)); + } + for (uint i=0; i < num1; ++i ) + { + tab.attachBuffer (provider.lockBufferFor (desc2)); + } + + for_each (tab.buffers(), do_some_calculations); + + tab.releaseBuffers(); + + DiagnosticBufferProvider checker = DiagnosticBufferProvider::access(provider); + CHECK (checker.all_buffers_released()); #endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #829 } };