PlacementIndex checks for bottom (invalid) ID

This commit is contained in:
Fischlurch 2009-12-13 05:49:08 +01:00
parent b74a505c44
commit 73fcc78cb3
5 changed files with 43 additions and 22 deletions

View file

@ -46,7 +46,8 @@ namespace mobject {
/** */
LUMIERA_ERROR_DEFINE (INVALID_PLACEMENTREF, "unresolvable placement reference, or of incompatible type");
LUMIERA_ERROR_DEFINE (INVALID_PLACEMENTREF, "unresolvable placement reference, or of incompatible type");
LUMIERA_ERROR_DEFINE (BOTTOM_PLACEMENTREF, "NIL placement-ID marker encountered.");

View file

@ -64,6 +64,8 @@ namespace mobject {
LUMIERA_ERROR_DECLARE (INVALID_PLACEMENTREF); ///< unresolvable placement reference, or of incompatible type
LUMIERA_ERROR_DECLARE (BOTTOM_PLACEMENTREF); ///< NIL placement-ID marker encountered
/**
* TODO type comment

View file

@ -176,6 +176,9 @@ namespace session {
inline void
__check_knownID(PlacementIndex const& idx, PlacementMO::ID id)
{
if (!id)
throw lumiera::error::Logic ("Encountered a NIL Placement-ID marker"
,LUMIERA_ERROR_BOTTOM_PLACEMENTREF);
if (!idx.contains (id))
throw lumiera::error::Invalid ("Accessing Placement not registered within the index"
,LUMIERA_ERROR_NOT_IN_SESSION); ///////////////////////TICKET #197

View file

@ -22,13 +22,14 @@
#include "lib/test/run.hpp"
#include "lib/lumitime.hpp"
#include "lib/test/test-helper.hpp"
#include "proc/mobject/placement.hpp"
#include "proc/mobject/placement-ref.hpp"
#include "proc/mobject/session/placement-index.hpp"
#include "proc/mobject/session/session-service-mock-index.hpp"
#include "proc/mobject/explicitplacement.hpp"
#include "proc/mobject/test-dummy-mobject.hpp"
#include "lib/lumitime.hpp"
#include "lib/util.hpp"
#include <iostream>
@ -150,15 +151,9 @@ namespace test {
// actually, the assignment has invalidated ref1, because of the changed ID
ASSERT (p1.getID() == p2.getID());
try
{
*ref1;
NOTREACHED();
}
catch (...)
{
ASSERT (lumiera_error () == LUMIERA_ERROR_INVALID_PLACEMENTREF);
}
VERIFY_ERROR(INVALID_PLACEMENTREF, *ref1 );
ASSERT (!index->contains(p1)); // index indeed detected the invalid ref
ASSERT (3 == ref2.use_count()); // but ref2 is still valid
@ -166,15 +161,14 @@ namespace test {
index->remove (ref2);
ASSERT (!ref2); // checks invalidity without throwing
ASSERT (!refX);
try
{
*ref2;
NOTREACHED();
}
catch (...)
{
ASSERT (lumiera_error () == LUMIERA_ERROR_INVALID_PLACEMENTREF);
}
VERIFY_ERROR(INVALID_PLACEMENTREF, *ref2 );
// deliberately create an invalid PlacementRef
PlacementRef<TestSubMO21> bottom;
ASSERT (!bottom);
VERIFY_ERROR(INVALID_PLACEMENTREF, *bottom );
VERIFY_ERROR(INVALID_PLACEMENTREF, bottom->specialAPI() );
VERIFY_ERROR(INVALID_PLACEMENTREF, bottom.resolve() );
//consistency check; then reset PlacementRef index to default
ASSERT (0 == index->size());

View file

@ -27,10 +27,10 @@
//#include "proc/mobject/session.hpp"
//#include "proc/mobject/session/edl.hpp"
#include "proc/mobject/session/placement-index.hpp"
#include "proc/mobject/session/testclip.hpp"
#include "proc/mobject/session/scope.hpp"
#include "proc/mobject/placement.hpp"
//#include "proc/mobject/explicitplacement.hpp"
#include "lib/util.hpp"
#include "proc/mobject/session/testclip.hpp"
//#include <boost/format.hpp>
//#include <iostream>
@ -137,6 +137,27 @@ namespace test {
}
void
checkInvalidRef (Idx index)
{
RefPlacement invalid;
PlacementMO::ID invalidID (invalid);
ASSERT (!bool(invalidID));
ASSERT (!bool(invalid));
VERIFY_ERROR(BOTTOM_PLACEMENTREF, index.find(invalid) );
VERIFY_ERROR(BOTTOM_PLACEMENTREF, index.find(invalidID) );
VERIFY_ERROR(BOTTOM_PLACEMENTREF, index.getScope(invalidID) );
ASSERT (!index.contains(invalidID));
PMO testObj = TestClip::create();
VERIFY_ERROR(INVALID_SCOPE, index.insert(testObj, invalidID) );
ASSERT (false == index.remove(invalidID));
}
void
checkScopeHandling (Idx index)
{