cleanup and write tests covering the newly implemented stuff
This commit is contained in:
parent
feb4480f85
commit
488039c4c6
5 changed files with 121 additions and 40 deletions
|
|
@ -61,7 +61,7 @@ namespace session {
|
|||
using std::tr1::unordered_map;
|
||||
using std::tr1::unordered_multimap;
|
||||
using lib::TypedAllocationManager;
|
||||
using util::getValue_or_default;
|
||||
//using util::getValue_or_default;
|
||||
//using util::contains;
|
||||
//using std::string;
|
||||
//using std::map;
|
||||
|
|
@ -76,22 +76,6 @@ namespace session {
|
|||
|
||||
|
||||
|
||||
namespace { // implementation helpers
|
||||
|
||||
template <typename MAP>
|
||||
inline typename MAP::mapped_type const&
|
||||
getEntry_or_throw (MAP& map, typename MAP::key_type const& key)
|
||||
{
|
||||
typename MAP::const_iterator pos = map.find (key);
|
||||
if (pos == map.end())
|
||||
throw error::Logic("lost a Placement expected to be registered in the index.");
|
||||
|
||||
return pos->second;
|
||||
}
|
||||
|
||||
} // (End) impl.helpers
|
||||
|
||||
|
||||
/* some type shorthands */
|
||||
typedef PlacementIndex::PlacementMO PlacementMO;
|
||||
typedef PlacementIndex::PRef PRef;
|
||||
|
|
@ -152,7 +136,7 @@ namespace session {
|
|||
fetch (ID id) const
|
||||
{
|
||||
REQUIRE (contains (id));
|
||||
PPlacement const& entry = getEntry_or_throw (placementTab_,id).element;
|
||||
PPlacement const& entry = base_entry(id).element;
|
||||
|
||||
ENSURE (entry);
|
||||
ENSURE (id == entry->getID());
|
||||
|
|
@ -163,7 +147,7 @@ namespace session {
|
|||
fetchScope (ID id) const
|
||||
{
|
||||
REQUIRE (contains (id));
|
||||
PPlacement const& scope = getEntry_or_throw (placementTab_,id).scope;
|
||||
PPlacement const& scope = base_entry(id).scope;
|
||||
|
||||
ENSURE (scope);
|
||||
ENSURE (contains (scope->getID()));
|
||||
|
|
@ -189,9 +173,8 @@ namespace session {
|
|||
* @see Placement#isCompatible
|
||||
*/
|
||||
ID
|
||||
addEntry (PlacementMO const& newObj, PlacementMO const& targetScope)
|
||||
addEntry (PlacementMO const& newObj, ID scopeID)
|
||||
{
|
||||
ID scopeID = targetScope.getID();
|
||||
REQUIRE (contains (scopeID));
|
||||
|
||||
PPlacement newEntry = allocator_.create<PlacementMO> (newObj);
|
||||
|
|
@ -229,10 +212,22 @@ namespace session {
|
|||
|
||||
|
||||
private:
|
||||
typedef IDTable::const_iterator Slot;
|
||||
|
||||
PlacementEntry const&
|
||||
base_entry (ID key) const
|
||||
{
|
||||
Slot pos = placementTab_.find (key);
|
||||
if (pos == placementTab_.end())
|
||||
throw error::Logic("lost a Placement expected to be registered in the index.");
|
||||
|
||||
return pos->second;
|
||||
}
|
||||
|
||||
PlacementEntry
|
||||
remove_base_entry (ID key)
|
||||
{
|
||||
IDTable::iterator pos = placementTab_.find (key);
|
||||
Slot pos = placementTab_.find (key);
|
||||
REQUIRE (pos != placementTab_.end());
|
||||
PlacementEntry dataToRemove (pos->second);
|
||||
placementTab_.erase(pos);
|
||||
|
|
@ -242,7 +237,7 @@ namespace session {
|
|||
void
|
||||
remove_from_scope (ID scopeID, ID entryID)
|
||||
{
|
||||
typedef ScopeTable::iterator Pos;
|
||||
typedef ScopeTable::const_iterator Pos;
|
||||
pair<Pos,Pos> searchRange = scopeTab_.equal_range(scopeID);
|
||||
|
||||
Pos pos = searchRange.first;
|
||||
|
|
@ -340,7 +335,7 @@ namespace session {
|
|||
* @note the newly added Placement has an identity of its own.
|
||||
*/
|
||||
ID
|
||||
PlacementIndex::insert (PlacementMO const& newObj, PlacementMO const& targetScope)
|
||||
PlacementIndex::insert (PlacementMO const& newObj, ID targetScope)
|
||||
{
|
||||
if (!contains (targetScope))
|
||||
throw error::Logic ("Specified a non-registered Placement as scope "
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ namespace session {
|
|||
|
||||
/* == mutating operations == */
|
||||
|
||||
ID insert (PlacementMO const& newObj, PlacementMO const& targetScope);
|
||||
ID insert (PlacementMO const& newObj, ID targetScope);
|
||||
bool remove (PlacementMO&);
|
||||
bool remove (ID);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
|
||||
#include "lib/test/run.hpp"
|
||||
#include "lib/test/test-helper.hpp"
|
||||
//#include "proc/asset/media.hpp"
|
||||
//#include "proc/mobject/session.hpp"
|
||||
//#include "proc/mobject/session/edl.hpp"
|
||||
|
|
@ -29,7 +30,7 @@
|
|||
#include "proc/mobject/session/testclip.hpp"
|
||||
#include "proc/mobject/placement.hpp"
|
||||
//#include "proc/mobject/explicitplacement.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
//#include <boost/format.hpp>
|
||||
//#include <iostream>
|
||||
|
|
@ -37,6 +38,7 @@
|
|||
//using boost::format;
|
||||
//using lumiera::Time;
|
||||
//using util::contains;
|
||||
using util::isSameObject;
|
||||
using std::string;
|
||||
//using std::cout;
|
||||
|
||||
|
|
@ -60,20 +62,36 @@ namespace test {
|
|||
*/
|
||||
class PlacementIndex_test : public Test
|
||||
{
|
||||
typedef shared_ptr<PlacementIndex> PIdx;
|
||||
|
||||
virtual void
|
||||
run (Arg)
|
||||
{
|
||||
PIdx index (PlacementIndex::create());
|
||||
PPIdx index (PlacementIndex::create());
|
||||
ASSERT (index);
|
||||
|
||||
/////////////////////////////////TODO
|
||||
checkSimpleInsert (index);
|
||||
checkSimpleInsertRemove (index);
|
||||
has_size (0, index);
|
||||
|
||||
checkSimpleAccess (index);
|
||||
has_size (1, index);
|
||||
|
||||
checkScopeHandling (index);
|
||||
has_size (7, index);
|
||||
|
||||
////////////////////////////TODO
|
||||
|
||||
index->clear();
|
||||
has_size (0, index);
|
||||
}
|
||||
|
||||
void
|
||||
checkSimpleInsert (PIdx index)
|
||||
has_size(uint siz, PPIdx index)
|
||||
{
|
||||
ASSERT (siz == index->size());
|
||||
}
|
||||
|
||||
void
|
||||
checkSimpleInsertRemove (PPIdx index)
|
||||
{
|
||||
PMO clip = TestClip::create();
|
||||
PMO& root = index->getRoot();
|
||||
|
|
@ -90,6 +108,73 @@ namespace test {
|
|||
ASSERT (!index->contains (clip));
|
||||
ASSERT ( index->contains (root));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
checkSimpleAccess (PPIdx index)
|
||||
{
|
||||
PMO testObj = TestClip::create();
|
||||
PMO& root = index->getRoot();
|
||||
PMO::ID elmID = index->insert (testObj, root);
|
||||
|
||||
PMO& elm = index->find(elmID);
|
||||
ASSERT (elmID == elm.getID());
|
||||
ASSERT (!isSameObject (elm,testObj)); // note: placements are registered as copy
|
||||
ASSERT (elm == testObj); // they are semantically equivalent
|
||||
ASSERT (elmID != testObj.getID()); // but have a distinct identity
|
||||
|
||||
PMO::ID elmID2 = index->insert(testObj, root);
|
||||
ASSERT (elmID != elmID); // ...and each insert creates a new instance
|
||||
ASSERT (testObj == index->find(elmID2));
|
||||
ASSERT (!isSameObject (elm, index->find(elmID2)));
|
||||
ASSERT ( isSameObject (elm, index->find(elmID )));
|
||||
|
||||
// can also re-access objects by previous ref
|
||||
ASSERT ( isSameObject (elm, index->find(elm)));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
checkScopeHandling (PPIdx index)
|
||||
{
|
||||
PMO testObj = TestClip::create();
|
||||
PMO& root = index->getRoot();
|
||||
|
||||
typedef PMO::ID ID;
|
||||
ID e1 = index->insert (testObj, root);
|
||||
ID e11 = index->insert (testObj, e1);
|
||||
ID e12 = index->insert (testObj, e1);
|
||||
ID e13 = index->insert (testObj, e1);
|
||||
ID e131 = index->insert (testObj, e13);
|
||||
ID e132 = index->insert (testObj, e13);
|
||||
ID e133 = index->insert (testObj, e13);
|
||||
ID e1331 = index->insert (testObj, e133);
|
||||
|
||||
ASSERT (root == index->getScope(e1));
|
||||
ASSERT (e1 == index->getScope(e11).getID());
|
||||
ASSERT (e1 == index->getScope(e12).getID());
|
||||
ASSERT (e1 == index->getScope(e13).getID());
|
||||
ASSERT (e13 == index->getScope(e131).getID());
|
||||
ASSERT (e13 == index->getScope(e132).getID());
|
||||
ASSERT (e13 == index->getScope(e133).getID());
|
||||
ASSERT (e133 == index->getScope(e1331).getID());
|
||||
ASSERT (e1 != e13);
|
||||
ASSERT (e13 != e133);
|
||||
|
||||
ASSERT (index->getScope(e11) == index->getScope(index->find(e11)));
|
||||
ASSERT (index->getScope(e131) == index->getScope(index->find(e131)));
|
||||
|
||||
VERIFY_ERROR(NONEMPTY_SCOPE, index->remove(e13) ); // can't remove a scope-constituting element
|
||||
VERIFY_ERROR(NONEMPTY_SCOPE, index->remove(e133) );
|
||||
|
||||
ASSERT (index->contains(e1331));
|
||||
ASSERT (index->remove(e1331));
|
||||
ASSERT (!index->contains(e1331));
|
||||
ASSERT (!index->remove(e1331));
|
||||
|
||||
ASSERT (index->remove(e133)); // but can remove an scope, after emptying it
|
||||
ASSERT (!index->contains(e133));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -68,15 +68,16 @@ namespace test {
|
|||
SessionServiceMockIndex::reset_PlacementIndex(index);
|
||||
PMO& root = index->getRoot();
|
||||
|
||||
index->insert (p1, root);
|
||||
index->insert (p2, p1 );
|
||||
index->insert (p3, p2 );
|
||||
index->insert (p4, p3 );
|
||||
index->insert (p5, p4 );
|
||||
typedef PMO::ID ID;
|
||||
ID i1 = index->insert (p1, root);
|
||||
ID i2 = index->insert (p2, i1 );
|
||||
ID i3 = index->insert (p3, i2 );
|
||||
ID i4 = index->insert (p4, i3 );
|
||||
ID i5 = index->insert (p5, i4 );
|
||||
|
||||
index->insert (ps1,root);
|
||||
index->insert (ps2,root);
|
||||
index->insert (ps3, ps2);
|
||||
ID is1 = index->insert (ps1,root);
|
||||
ID is2 = index->insert (ps2,root);
|
||||
ID is3 = index->insert (ps3, is2);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace test {
|
|||
/**
|
||||
* Sample or Test Clip for checking
|
||||
* various EDL, session and builder operations.
|
||||
* @todo make this usable as Mock object to record invoked operations.
|
||||
* @todo maybe use this as Mock object to record invoked operations?
|
||||
*
|
||||
*/
|
||||
class TestClip : public mobject::session::Clip
|
||||
|
|
|
|||
Loading…
Reference in a new issue