stubs and changes to make the test compile

This commit is contained in:
Fischlurch 2011-11-11 23:33:59 +01:00
parent fe1ae51b49
commit fd94367b9e
3 changed files with 51 additions and 21 deletions

View file

@ -46,6 +46,7 @@
#include "lib/error.hpp"
#include "proc/engine/buffer-provider.hpp"
#include "lib/scoped-ptrvect.hpp"
#include "lib/access-casted.hpp"
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_array.hpp>
@ -115,6 +116,10 @@ namespace engine {
, public lib::ScopedPtrVect<diagn::Block>
{
public:
/* === BufferProvider interface === */
using BufferProvider::lockBufferFor;
virtual uint announce (uint count, BufferDescriptor const& type);
virtual BuffHandle lockBufferFor (BufferDescriptor const& descriptor);
virtual void mark_emitted (BuffHandle const& handle);
@ -126,12 +131,40 @@ namespace engine {
diagn::Block& access_or_create (uint bufferID);
template<typename TY>
TY& accessAs (uint bufferID);
private:
bool withinStorageSize (uint bufferID) const;
};
/** convenience shortcut: access the buffer with the given number,
* then try to convert the raw memory to the templated type.
* @throw error::Invalid if the required fame number is beyond
* the number of buffers marked as "emitted"
* @throw error::Fatal if conversion is not possible or the
* conversion path chosen doesn't work (which might
* be due to RTTI indicating an incompatible type).
*/
template<typename TY>
TY&
TrackingHeapBlockProvider::accessAs (uint bufferID)
{
if (!withinStorageSize (bufferID))
throw error::Invalid ("Buffer with the given ID not yet emitted");
diagn::Block& memoryBlock = access_or_create (bufferID);
TY* converted = util::AccessCasted<TY*>::access (memoryBlock.accessMemory());
if (!converted)
throw error::Fatal ("unable to access the target location with the required conversion");
else
return *converted;
}
} // namespace engine

View file

@ -73,7 +73,8 @@ namespace test {
bool
verifyUsedBlock (uint nr, diagn::Block& memoryBlock)
{
return memoryBlock.was_closed()
return memoryBlock.was_used()
&& memoryBlock.was_closed()
&& has_expectedContent (nr, memoryBlock);
}
}
@ -91,7 +92,6 @@ namespace test {
virtual void
run (Arg)
{
UNIMPLEMENTED ("verify test helper");
simpleExample();
verifyStandardCase();
verifyTestProtocol();
@ -114,9 +114,6 @@ namespace test {
provider.releaseBuffer(testBuff);
diagn::Block& block0 = provider.access_or_create(0);
CHECK (block0.was_used());
CHECK (block0.was_closed());
CHECK (testData(dataID) == block0.accessMemory());
}
@ -161,11 +158,11 @@ namespace test {
CHECK (5 == provider.size());
provider.access<uint>(0) = 20;
provider.access<uint>(1) = 21;
provider.access<uint>(2) = 22;
provider.access<uint>(3) = 23;
provider.access<uint>(4) = 24;
provider.accessAs<uint>(0) = 20;
provider.accessAs<uint>(1) = 21;
provider.accessAs<uint>(2) = 22;
provider.accessAs<uint>(3) = 23;
provider.accessAs<uint>(4) = 24;
bu1.accessAs<uint>() = 1;
bu2.accessAs<uint>() = 2;
@ -173,11 +170,11 @@ namespace test {
bu4.accessAs<uint>() = 4;
bu5.accessAs<uint>() = 5;
CHECK (20 == provider.access<uint>(0));
CHECK (21 == provider.access<uint>(1));
CHECK (22 == provider.access<uint>(2));
CHECK (23 == provider.access<uint>(3));
CHECK (24 == provider.access<uint>(4));
CHECK (20 == provider.accessAs<uint>(0));
CHECK (21 == provider.accessAs<uint>(1));
CHECK (22 == provider.accessAs<uint>(2));
CHECK (23 == provider.accessAs<uint>(3));
CHECK (24 == provider.accessAs<uint>(4));
provider.mark_emitted (bu3);
provider.mark_emitted (bu1);
@ -185,11 +182,11 @@ namespace test {
provider.mark_emitted (bu4);
provider.mark_emitted (bu2);
CHECK (3 == provider.access<uint>(0));
CHECK (1 == provider.access<uint>(1));
CHECK (5 == provider.access<uint>(2));
CHECK (4 == provider.access<uint>(3));
CHECK (2 == provider.access<uint>(4));
CHECK (3 == provider.accessAs<uint>(0));
CHECK (1 == provider.accessAs<uint>(1));
CHECK (5 == provider.accessAs<uint>(2));
CHECK (4 == provider.accessAs<uint>(3));
CHECK (2 == provider.accessAs<uint>(4));
}
};

View file

@ -66,7 +66,7 @@ namespace play {
: public OutputSlot::Connection
{
shared_ptr<BufferProvider> buffProvider_;
shared_ptr<TrackingHeapBlockProvider> buffProvider_;
BufferDescriptor bufferType_;