Commit c3b1de22 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Fixed AbstractProcessorTest.

parent c488b267
......@@ -58,6 +58,25 @@ namespace campvis {
*/
class CAMPVIS_CORE_API AbstractProcessor : public HasPropertyCollection {
public:
/**
* Scoped lock of an AbstractProcessor that automatically unlocks the processor on destruction.
* Useful for exception safety.
*/
struct CAMPVIS_CORE_API ScopedLock {
/**
* Constructs a new Scoped lock, locking \a p and unlocking \a p on destruction.
* \param p Processor to lock
* \param unlockInExtraThread Unlock \a p in extra thread (since this might be an expensive operation)
*/
ScopedLock(AbstractProcessor* p, bool unlockInExtraThread);
/// Destructor, unlocks the processor
~ScopedLock();
AbstractProcessor* _p; ///< The processor to lock
bool _unlockInExtraThread; ///< Unlock _p in extra thread (since this might be an expensive operation)
};
/**
* Available invalidation levels
*/
......@@ -275,26 +294,6 @@ namespace campvis {
sigslot::signal1<AbstractProcessor*> s_validated;
protected:
/**
* Scoped lock of an AbstractProcessor that automatically unlocks the processor on destruction.
* Useful for exception safety.
*/
struct CAMPVIS_CORE_API ScopedLock {
/**
* Constructs a new Scoped lock, locking \a p and unlocking \a p on destruction.
* \param p Processor to lock
* \param unlockInExtraThread Unlock \a p in extra thread (since this might be an expensive operation)
*/
ScopedLock(AbstractProcessor* p, bool unlockInExtraThread);
/// Destructor, unlocks the processor
~ScopedLock();
AbstractProcessor* _p; ///< The processor to lock
bool _unlockInExtraThread; ///< Unlock _p in extra thread (since this might be an expensive operation)
};
/**
* Gets called from default process() method when having an invalidation level of INVALID_SHADER.
*
......
......@@ -30,20 +30,22 @@
#include "gtest/gtest.h"
#include "core/pipeline/abstractprocessor.h"
#include "core/properties/genericproperty.h"
#include "core/datastructures/datacontainer.h"
#include "core/datastructures/imagedata.h"
using namespace campvis;
// FIXME: This is not what I was supposed to be. fix me please.
class DummyTestProcessor : public AbstractProcessor {
public:
DummyTestProcessor () {
_invalidateExternally = false;
this->invalidate(AbstractProcessor::VALID);
DummyTestProcessor ()
: _boolProperty("BoolProperty", "Bool Property", false)
, _togglePropertyDuringProcess(false)
{
addProperty(_boolProperty);
}
~DummyTestProcessor () {}
virtual const std::string getName() const { return "DummyTestProcessor"; };
......@@ -52,19 +54,14 @@ public:
virtual ProcessorState getProcessorState() const { return AbstractProcessor::TESTING; };
virtual void updateResult(DataContainer& dataContainer) {
dataContainer.removeData("ImageData");
dataContainer.addData("ImageData", new ImageData(2, tgt::svec3(1,2,1), 4));
}
void setExternalInvalidation(bool status, AbstractProcessor::InvalidationLevel level) {
_invalidateExternally = status;
this->invalidate(level);
this->invalidate(this->getInvalidationLevel());
if (_togglePropertyDuringProcess) {
bool currentValue = _boolProperty.getValue();
_boolProperty.setValue(! currentValue);
}
}
private:
bool _invalidateExternally;
BoolProperty _boolProperty;
bool _togglePropertyDuringProcess;
};
......@@ -98,10 +95,26 @@ protected:
* Tests invalidation of data
*/
TEST_F(AbstractProcessorTest, invalidationTest) {
this->_processor1.invalidate(AbstractProcessor::INVALID_RESULT);
this->_processor1._togglePropertyDuringProcess = false;
this->_processor1.process(this->_dataContainer);
EXPECT_EQ(AbstractProcessor::VALID, this->_processor1.getInvalidationLevel());
this->_processor1.setExternalInvalidation(true, AbstractProcessor::INVALID_RESULT);
}
/**
* Tests processor's locking mechanism
*/
TEST_F(AbstractProcessorTest, lockingTest) {
this->_processor1.invalidate(AbstractProcessor::INVALID_RESULT);
this->_processor1._togglePropertyDuringProcess = true;
this->_processor1.process(this->_dataContainer);
EXPECT_NE(AbstractProcessor::VALID, this->_processor1.getInvalidationLevel());
}
{
AbstractProcessor::ScopedLock lock(&this->_processor1, false);
bool currentValue = this->_processor1._boolProperty.getValue();
this->_processor1._boolProperty.setValue(! currentValue);
EXPECT_EQ(currentValue, this->_processor1._boolProperty.getValue());
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment