* Lumiera source code always was copyrighted by individual contributors * there is no entity "Lumiera.org" which holds any copyrights * Lumiera source code is provided under the GPL Version 2+ == Explanations == Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above. For this to become legally effective, the ''File COPYING in the root directory is sufficient.'' The licensing header in each file is not strictly necessary, yet considered good practice; attaching a licence notice increases the likeliness that this information is retained in case someone extracts individual code files. However, it is not by the presence of some text, that legally binding licensing terms become effective; rather the fact matters that a given piece of code was provably copyrighted and published under a license. Even reformatting the code, renaming some variables or deleting parts of the code will not alter this legal situation, but rather creates a derivative work, which is likewise covered by the GPL! The most relevant information in the file header is the notice regarding the time of the first individual copyright claim. By virtue of this initial copyright, the first author is entitled to choose the terms of licensing. All further modifications are permitted and covered by the License. The specific wording or format of the copyright header is not legally relevant, as long as the intention to publish under the GPL remains clear. The extended wording was based on a recommendation by the FSF. It can be shortened, because the full terms of the license are provided alongside the distribution, in the file COPYING.
231 lines
7.9 KiB
C++
231 lines
7.9 KiB
C++
/*
|
||
BufferProviderProtocol(Test) - demonstration of buffer provider usage cycle
|
||
|
||
Copyright (C)
|
||
2011, Hermann Vosseler <Ichthyostega@web.de>
|
||
|
||
**Lumiera** 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. See the file COPYING for further details.
|
||
|
||
* *****************************************************************/
|
||
|
||
/** @file buffer-provider-protocol-test.cpp
|
||
** unit test \ref BufferProviderProtocol_test
|
||
*/
|
||
|
||
|
||
#include "lib/error.hpp"
|
||
#include "lib/test/run.hpp"
|
||
#include "lib/test/test-helper.hpp"
|
||
#include "lib/test/tracking-dummy.hpp"
|
||
#include "lib/util-foreach.hpp"
|
||
#include "steam/engine/testframe.hpp"
|
||
#include "steam/engine/diagnostic-buffer-provider.hpp"
|
||
#include "steam/engine/buffhandle-attach.hpp"
|
||
#include "steam/engine/bufftable.hpp"
|
||
|
||
using util::isSameObject;
|
||
using util::for_each;
|
||
|
||
|
||
namespace steam {
|
||
namespace engine{
|
||
namespace test {
|
||
|
||
using lib::test::Dummy;
|
||
|
||
using steam::engine::BuffHandle;
|
||
using LERR_(LIFECYCLE);
|
||
using LERR_(LOGIC);
|
||
|
||
|
||
namespace { // Test fixture
|
||
|
||
const uint TEST_SIZE = 1024*1024;
|
||
const uint TEST_ELMS = 20;
|
||
|
||
|
||
void
|
||
do_some_calculations (BuffHandle const& buffer)
|
||
{
|
||
UNIMPLEMENTED ("some verifiable test/dummy buffer accessing operations");
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/**************************************************************************//**
|
||
* @test verify and demonstrate the usage cycle of data buffers for the engine
|
||
* based on the BufferProvider interface. This is kind of a "dry run"
|
||
* for documentation purposes, because the BufferProvider implementation
|
||
* used here is just a diagnostics facility, allowing to investigate
|
||
* the state of individual buffers even after "releasing" them.
|
||
*
|
||
* This test should help understanding the sequence of buffer management
|
||
* operations performed at various stages while passing an calculation job
|
||
* through the render engine.
|
||
*/
|
||
class BufferProviderProtocol_test : public Test
|
||
{
|
||
virtual void
|
||
run (Arg)
|
||
{
|
||
verifySimpleUsage();
|
||
verifyStandardCase();
|
||
verifyObjectAttachment();
|
||
verifyObjectAttachmentFailure();
|
||
}
|
||
|
||
|
||
void
|
||
verifySimpleUsage()
|
||
{
|
||
// Create Test fixture.
|
||
// In real usage, a suitable memory/frame/buffer provider
|
||
// will be preconfigured, depending on the usage context
|
||
BufferProvider& provider = DiagnosticBufferProvider::build();
|
||
|
||
BuffHandle buff = provider.lockBufferFor<TestFrame>();
|
||
CHECK (buff.isValid());
|
||
CHECK (sizeof(TestFrame) <= buff.size());
|
||
buff.accessAs<TestFrame>() = testData(0);
|
||
|
||
TestFrame& content = buff.accessAs<TestFrame>();
|
||
CHECK (testData(0) == content);
|
||
|
||
buff.emit();
|
||
buff.release();
|
||
CHECK (!buff.isValid());
|
||
VERIFY_ERROR (LIFECYCLE, buff.accessAs<TestFrame>() );
|
||
|
||
DiagnosticBufferProvider& checker = DiagnosticBufferProvider::access(provider);
|
||
CHECK (checker.buffer_was_used (0));
|
||
CHECK (checker.buffer_was_closed (0));
|
||
|
||
CHECK (testData(0) == checker.accessMemory (0));
|
||
}
|
||
|
||
|
||
void
|
||
verifyStandardCase()
|
||
{
|
||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #829
|
||
// Create Test fixture.
|
||
// In real usage, a suitable memory/frame/buffer provider
|
||
// will be preconfigured, depending on the usage context
|
||
BufferProvider& provider = DiagnosticBufferProvider::build();
|
||
|
||
BuffDescr desc1 = provider.getDescriptor<TestFrame>(); // note: implies also sizeof(TestFrame)
|
||
BuffDescr desc2 = provider.getDescriptorFor(TEST_SIZE);
|
||
CHECK (desc1.verifyValidity());
|
||
CHECK (desc2.verifyValidity());
|
||
|
||
uint num1 = provider.announce(TEST_ELMS, desc1);
|
||
uint 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_SIZE, storage)
|
||
.announce(num1, desc1)
|
||
.announce(num2, desc2)
|
||
.build();
|
||
|
||
tab.lockBuffers();
|
||
for_each (tab.buffers(), do_some_calculations);
|
||
tab.releaseBuffers();
|
||
|
||
DiagnosticBufferProvider& checker = DiagnosticBufferProvider::access(provider);
|
||
CHECK (checker.all_buffers_released());
|
||
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #829
|
||
}
|
||
|
||
|
||
void
|
||
verifyObjectAttachment()
|
||
{
|
||
BufferProvider& provider = DiagnosticBufferProvider::build();
|
||
BuffDescr type_A = provider.getDescriptorFor(sizeof(TestFrame));
|
||
BuffDescr type_B = provider.getDescriptorFor(sizeof(int));
|
||
BuffDescr type_C = provider.getDescriptor<int>();
|
||
|
||
BuffHandle handle_A = provider.lockBuffer(type_A);
|
||
BuffHandle handle_B = provider.lockBuffer(type_B);
|
||
BuffHandle handle_C = provider.lockBuffer(type_C);
|
||
|
||
CHECK (handle_A);
|
||
CHECK (handle_B);
|
||
CHECK (handle_C);
|
||
|
||
CHECK (sizeof(TestFrame) == handle_A.size());
|
||
CHECK (sizeof( int ) == handle_B.size());
|
||
CHECK (sizeof( int ) == handle_C.size());
|
||
|
||
TestFrame& embeddedFrame = handle_A.create<TestFrame>();
|
||
CHECK (isSameObject (*handle_A, embeddedFrame));
|
||
CHECK (embeddedFrame.isAlive());
|
||
CHECK (embeddedFrame.isSane());
|
||
|
||
VERIFY_ERROR (LOGIC, handle_B.create<TestFrame>()); // too small to hold a TestFrame
|
||
VERIFY_ERROR (LIFECYCLE, handle_C.create<int>()); // has already an attached TypeHandler (creating an int)
|
||
|
||
handle_A.release();
|
||
handle_B.release();
|
||
handle_C.release();
|
||
|
||
CHECK (embeddedFrame.isDead());
|
||
CHECK (embeddedFrame.isSane());
|
||
}
|
||
|
||
|
||
void
|
||
verifyObjectAttachmentFailure()
|
||
{
|
||
BufferProvider& provider = DiagnosticBufferProvider::build();
|
||
BuffDescr type_D = provider.getDescriptorFor(sizeof(Dummy));
|
||
|
||
Dummy::checksum() = 0;
|
||
BuffHandle handle_D = provider.lockBuffer(type_D);
|
||
CHECK (0 == Dummy::checksum()); // nothing created thus far
|
||
|
||
handle_D.create<Dummy>();
|
||
CHECK (0 < Dummy::checksum());
|
||
|
||
handle_D.release();
|
||
CHECK (0 == Dummy::checksum());
|
||
|
||
BuffHandle handle_DD = provider.lockBuffer(type_D);
|
||
|
||
CHECK (0 == Dummy::checksum());
|
||
Dummy::activateCtorFailure();
|
||
|
||
CHECK (handle_DD.isValid());
|
||
try
|
||
{
|
||
handle_DD.create<Dummy>();
|
||
NOTREACHED ("Dummy ctor should fail");
|
||
}
|
||
catch (int val)
|
||
{
|
||
CHECK (!handle_DD.isValid());
|
||
|
||
CHECK (0 < Dummy::checksum());
|
||
CHECK (val == Dummy::checksum());
|
||
}
|
||
|
||
VERIFY_ERROR (LIFECYCLE, handle_DD.accessAs<Dummy>() );
|
||
VERIFY_ERROR (LIFECYCLE, handle_DD.create<Dummy>() );
|
||
}
|
||
};
|
||
|
||
|
||
/** Register this test class... */
|
||
LAUNCHER (BufferProviderProtocol_test, "unit player");
|
||
|
||
|
||
|
||
}}} // namespace steam::engine::test
|