cast the new spec regarding timeline/session into unit test code

This commit is contained in:
Fischlurch 2010-03-03 06:00:37 +01:00
parent 82c2768e04
commit 8eb0a16134
5 changed files with 308 additions and 123 deletions

View file

@ -52,6 +52,7 @@
#include "proc/asset/struct.hpp"
//#include "proc/mobject/mobject.hpp"
//#include "proc/mobject/placement.hpp"
#include "proc/mobject/mobject-ref.hpp"
//#include <vector>
//#include <string>
@ -59,9 +60,17 @@
//using std::vector;
//using std::string;
namespace mobject {
namespace session {
class Track;
}}
namespace asset {
typedef mobject::MORef<mobject::session::Track> RTrack;
/**
* TODO type comment

View file

@ -55,6 +55,9 @@
#include "proc/asset/struct.hpp"
//#include "proc/mobject/mobject.hpp"
//#include "proc/mobject/placement.hpp"
#include "proc/mobject/mobject-ref.hpp"
//#include "proc/mobject/session/binding.hpp" ////TODO avoidable??
//#include <vector>
//#include <string>
@ -62,8 +65,16 @@
//using std::vector;
//using std::string;
namespace mobject {
namespace session {
class Binding;
}}
namespace asset {
typedef mobject::MORef<mobject::session::Binding> RBinding;
/**
@ -81,6 +92,7 @@ namespace asset {
typedef P<Timeline> PTimeline;
///////////////////////////TODO currently just fleshing the API

View file

@ -2,7 +2,7 @@
MObjectFactory - creating concrete MObject subclass instances
Copyright (C) Lumiera.org
2008, Hermann Vosseler <Ichthyostega@web.de>
2008-2010, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@ -33,69 +33,69 @@
namespace mobject {
namespace session {
////////////////////////////////////////////////////////////////////////////////TICKET #414
/** build a new session/model root element. */
Placement<Root>
MObjectFactory::operator() (DefsManager& sessionDefaultsHandler)
{
return Placement<Root> (*new Root (sessionDefaultsHandler), &deleterFunc);
}
/** build a new session/model root element. */
Placement<Label>
MObjectFactory::operator() (Symbol labelType)
{
return Placement<Label> (*new Label (labelType), &deleterFunc);
}
/** creating a Clip-MObject to be placed within the Session,
* based on a clip asset, which typically is obtained by calling
* the createClip()-function on some asset::Media.
* The newly created Clip-MO is (back)linked with this media Asset
* internally and wrapped into a Placement, which takes ownership.
* So, when the render engine gets across this Clip-MO, it is able
* to obtain the media information contained in the corresponding
* media asset. Note this will create a single track clip.
* @param mediaDef the actual asset::Media to be used
* created Clip could be a compound (multichannel) clip
* comprised of several SimpleClip sub-objects.
*/
Placement<Clip>
MObjectFactory::operator() (const asset::Clip& clipRef, const asset::Media& mediaDef)
{
return Placement<Clip> (*new Clip (clipRef,mediaDef), &deleterFunc);
}
/** variant of the Clip-MO factory function, creating
* a multichannel (compound) clip.
* @todo work out the details of multichannel handling
*/
Placement<Clip>
MObjectFactory::operator() (const asset::Clip& clipRef, vector<const Media*> mediaTracks)
{
UNIMPLEMENTED ("build multichannel compound clip-MO");
}
/** */
Placement<Track>
MObjectFactory::operator() (PTrackAsset& trackDef)
{
TODO ("what needs to be registered when creating an Track-MO?");
return Placement<Track> (*new Track (trackDef), &deleterFunc);
}
/** */
Placement<Effect>
MObjectFactory::operator() (const asset::Effect& processorDef)
{
UNIMPLEMENTED ("fabricate effect-MO");
}
////////////////////////////////////////////////////////////////////////////////TICKET #414
/** build a new session/model root element. */
Placement<Root>
MObjectFactory::operator() (DefsManager& sessionDefaultsHandler)
{
return Placement<Root> (*new Root (sessionDefaultsHandler), &deleterFunc);
}
/** build a new session/model root element. */
Placement<Label>
MObjectFactory::operator() (Symbol labelType)
{
return Placement<Label> (*new Label (labelType), &deleterFunc);
}
/** creating a Clip-MObject to be placed within the Session,
* based on a clip asset, which typically is obtained by calling
* the createClip()-function on some asset::Media.
* The newly created Clip-MO is (back)linked with this media Asset
* internally and wrapped into a Placement, which takes ownership.
* So, when the render engine gets across this Clip-MO, it is able
* to obtain the media information contained in the corresponding
* media asset. Note this will create a single track clip.
* @param mediaDef the actual asset::Media to be used
* created Clip could be a compound (multichannel) clip
* comprised of several SimpleClip sub-objects.
*/
Placement<Clip>
MObjectFactory::operator() (const asset::Clip& clipRef, const asset::Media& mediaDef)
{
return Placement<Clip> (*new Clip (clipRef,mediaDef), &deleterFunc);
}
/** variant of the Clip-MO factory function, creating
* a multichannel (compound) clip.
* @todo work out the details of multichannel handling
*/
Placement<Clip>
MObjectFactory::operator() (const asset::Clip& clipRef, vector<const Media*> mediaTracks)
{
UNIMPLEMENTED ("build multichannel compound clip-MO");
}
/** */
Placement<Track>
MObjectFactory::operator() (PTrackAsset& trackDef)
{
TODO ("what needs to be registered when creating an Track-MO?");
return Placement<Track> (*new Track (trackDef), &deleterFunc);
}
/** */
Placement<Effect>
MObjectFactory::operator() (const asset::Effect& processorDef)
{
UNIMPLEMENTED ("fabricate effect-MO");
}
}} // namespace mobject::session

View file

@ -2,7 +2,7 @@
MOBJECTFACTORY.hpp - creating concrete MObject subclass instances
Copyright (C) Lumiera.org
2008, Hermann Vosseler <Ichthyostega@web.de>
2008-2010, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@ -30,7 +30,7 @@
namespace asset {
class Clip;
class Media;
class Track;
@ -39,40 +39,39 @@ namespace asset {
}
namespace mobject {
namespace session {
class Root;
class Clip;
class Track;
class Effect;
class Label;
typedef P<asset::Track> PTrackAsset;
class DefsManager;
class MObjectFactory
{
/** custom deleter func allowing class Placement
* to take ownership of MObjct instances
*/
static void deleterFunc (MObject* o) { delete o; }
public:
Placement<Root> operator() (DefsManager&);
Placement<Clip> operator() (asset::Clip const&, asset::Media const&);
Placement<Clip> operator() (asset::Clip const&, vector<asset::Media const*>);
Placement<Track> operator() (PTrackAsset&);
Placement<Effect> operator() (asset::Effect const&);
Placement<Label> operator() (lib::Symbol);
////////////////////////////////////////////////////////////////////////////////TICKET #414
};
} // namespace mobject::session
} // namespace mobject
namespace session {
class Root;
class Clip;
class Track;
class Effect;
class Label;
typedef P<asset::Track> PTrackAsset;
class DefsManager;
class MObjectFactory
{
/** custom deleter function allowing
* Placement to take ownership of MObjct instances
*/
static void deleterFunc (MObject* o) { delete o; }
public:
Placement<Root> operator() (DefsManager&);
Placement<Clip> operator() (asset::Clip const&, asset::Media const&);
Placement<Clip> operator() (asset::Clip const&, vector<asset::Media const*>);
Placement<Track> operator() (PTrackAsset&);
Placement<Effect> operator() (asset::Effect const&);
Placement<Label> operator() (lib::Symbol);
////////////////////////////////////////////////////////////////////////////////TICKET #414
};
}} // namespace mobject::session
#endif

View file

@ -23,8 +23,10 @@
#include "lib/test/run.hpp"
#include "proc/mobject/session.hpp"
#include "proc/mobject/mobject-ref.hpp"
#include "proc/mobject/session/binding.hpp"
//#include "proc/mobject/session/fixture.hpp" // TODO only temporarily needed
#include "proc/assetmanager.hpp" ///??
#include "proc/assetmanager.hpp"
#include "proc/asset/timeline.hpp"
#include "proc/asset/sequence.hpp"
#include "proc/asset/pipe.hpp"
@ -35,6 +37,7 @@
#include <iostream>
using util::isSameObject;
using util::contains;
using std::string;
using std::cout;
@ -48,6 +51,8 @@ namespace test {
using asset::PTimeline;
using asset::PSequence;
using asset::RBinding;
using asset::RTrack;
using asset::Pipe;
using lumiera::Query;
@ -64,6 +69,7 @@ namespace test {
* just by querying the respective asset.
*
* @todo specify how deletion is handled
* @todo specify how to \em move objects by placement
*
* @see session-structure-test.cpp
* @see Timeline
@ -76,10 +82,15 @@ namespace test {
run (Arg)
{
Session::current.reset();
ASSERT (Session::current.isUp());
CHECK (Session::current.isUp());
verify_retrieval();
verify_creation();
verify_removalTimeline();
verify_removalBinding();
verify_removalSequence();
indirect_SequenceHandling();
}
@ -87,23 +98,23 @@ namespace test {
verify_retrieval()
{
PSess sess = Session::current;
ASSERT (sess->isValid());
ASSERT (0 < sess->timelines.size());
CHECK (sess->isValid());
CHECK (0 < sess->timelines.size());
PTimeline defaultTimeline = sess->defaults (Query<Timeline> ()); //////////////////////TICKET #549
Query<Timeline> query1 = "id("+defaultTimeline->getNameID()+").";
PTimeline queriedTimeline = asset::Struct::create (query1);
ASSERT (queriedTimeline);
ASSERT (queriedTimeline == defaultTimeline); // retrieved the existing timeline asset again
ASSERT (queriedTimeline == sess->timelines[0]);
CHECK (queriedTimeline);
CHECK (queriedTimeline == defaultTimeline); // retrieved the existing timeline asset again
CHECK (queriedTimeline == sess->timelines[0]);
Query<Sequence> query2 = "id("+defaultTimeline->getSequence()->getNameID()+").";
PSequence queriedSequence = asset::Struct::create (query2);
ASSERT (queriedSequence);
ASSERT (queriedSequence == sess->sequences[0]);
ASSERT (queriedSequence == sess->timelines[0]->getSequence());
ASSERT (queriedSequence == defaultTimeline->getSequence());
CHECK (queriedSequence);
CHECK (queriedSequence == sess->sequences[0]);
CHECK (queriedSequence == sess->timelines[0]->getSequence());
CHECK (queriedSequence == defaultTimeline->getSequence());
}
@ -111,25 +122,179 @@ namespace test {
verify_creation()
{
PSess sess = Session::current;
ASSERT (sess->isValid());
CHECK (sess->isValid());
uint num_timelines = sess->timelines.size();
ASSERT (0 < num_timelines);
CHECK (0 < num_timelines);
Query<Timeline> special = "id(aSillyName), sequence("
+ sess->sequences[0]->getNameID()
+ "), pipe(ambiance).";
PTimeline specialTimeline (asset::Struct::create (special));
ASSERT (specialTimeline);
ASSERT (num_timelines + 1 == sess->timelines.size());
ASSERT (specialTimeline == session->timelines[num_timelines]); // new one got appended at the end
CHECK (specialTimeline);
CHECK (num_timelines + 1 == sess->timelines.size());
CHECK (specialTimeline == session->timelines[num_timelines]); // new one got appended at the end
// verify the properties
ASSERT (specialTimeline->getSequence() == sess->sequences[0]); // the already existing sequence got bound into that timeline too
ASSERT (contains (specialTimeline->pipes, Pipe::query("pipe(ambiance)")));
CHECK (specialTimeline->getSequence() == sess->sequences[0]); // the already existing sequence got bound into that timeline too
CHECK (contains (specialTimeline->pipes, Pipe::query("pipe(ambiance)")));
ASSERT (specialTimeline.use_count() == 3); // we, the AssetManager and the session
CHECK (specialTimeline.use_count() == 3); // we, the AssetManager and the session
}
void
verify_removalTimeline()
{
PSess sess (Session::current);
AssetManager& assetM (AssetManager::instance());
CHECK (sess->isValid());
uint num_timelines = sess->timelines.size();
CHECK (2 <= num_timelines);
PTimeline specialTimeline = sess->timelines[num_timelines-1];
CHECK ("aSillyName" == specialTimeline->getNameID());
RBinding binding = specialTimeline->getBinding();
CHECK (binding);
PSequence theSeq = binding->getSequence();
CHECK (theSeq == sess->sequences[0]);
CHECK (theSeq == specialTimeline->getSequence());
CHECK (assetM.known (theSeq->getID()));
// cause removal of the timeline
assetM.remove (specialTimeline->getID()); //////////////TICKET #550
CHECK (!assetM.known (specialTimeline->getID()));
CHECK (1 == specialTimeline.use_count()); // we hold the only remaining ref
CHECK ( assetM.known (theSeq->getID())); // bound sequence isn't affected
CHECK (theSeq == sess->sequences[0]);
CHECK (num_timelines - 1 == sess->timelines.size());
CHECK (!binding); // got purged from the model
}
void
verify_removalBinding()
{
PSess sess (Session::current);
AssetManager& assetM (AssetManager::instance());
CHECK (sess->isValid());
uint num_timelines = sess->timelines.size();
CHECK (0 < num_timelines);
// create a new Timeline to play with, using the default sequence...
PTimeline aTimeline (asset::Struct::create (Query<Timeline> ("sequence("+
+ sess->sequences[0]->getNameID()
+ ").")));
CHECK (num_timelines + 1 == sess->timelines.size());
RBinding binding = aTimeline->getBinding();
CHECK (binding);
PSequence theSeq = binding->getSequence();
CHECK (theSeq == sess->sequences[0]);
CHECK (theSeq == aTimeline->getSequence());
CHECK (assetM.known (aTimeline->getID()));
CHECK (assetM.known (theSeq->getID()));
// indirectly cause removal of the timeline by dropping the binding
sess->remove(binding);
CHECK (!binding);
CHECK (!assetM.known (aTimeline->getID()));
CHECK (1 == aTimeline.use_count());
CHECK ( assetM.known (theSeq->getID()));
CHECK (num_timelines == sess->timelines.size());
CHECK (!contains (sess->timelines, aTimeline));
CHECK ( contains (sess->sequences, theSeq)); // unaffected
}
void
verify_removalSequence()
{
PSess sess (Session::current);
AssetManager& assetM (AssetManager::instance());
CHECK (sess->isValid());
uint num_timelines = sess->timelines.size();
uint num_sequences = sess->sequences.size();
// create a new timeline, bound to a new sequence...
PTimeline aTimeline (asset::Struct::create (Query<Timeline> ()));
PSequence aSequence (aTimeline->getSequence());
CHECK (num_timelines + 1 == sess->timelines.size());
CHECK (num_sequences + 1 == sess->sequences.size());
RBinding binding = aTimeline->getBinding();
RTrack rootTrack = aSequence->getTracks();
CHECK (rootTrack);
CHECK (binding);
CHECK (aSequence == binding->getSequence());
CHECK (assetM.known (aTimeline->getID()));
CHECK (assetM.known (aSequence->getID()));
// purging the sequence cascades to all linked entities
assetM.remove (aSequence->getID()); //////////////TICKET #550
CHECK (!assetM.known (aTimeline->getID()));
CHECK (!assetM.known (aSequence->getID()));
CHECK (!rootTrack);
CHECK (!binding);
CHECK (num_timelines == sess->timelines.size());
CHECK (num_sequences == sess->sequences.size());
CHECK (!contains (sess->timelines, aTimeline));
CHECK (!contains (sess->sequences, aSequence));
CHECK (1 == aTimeline.use_count());
CHECK (1 == aSequence.use_count());
}
void
indirect_SequenceHandling()
{
PSess sess (Session::current);
AssetManager& assetM (AssetManager::instance());
CHECK (sess->isValid());
uint num_sequences = sess->sequences.size();
RTrack someTrack = sess->sequences[0]->getTracks();
// indirectly cause a new sequence to come to life...
RTrack newTrack = sess->getRoot().attach (someTrack); /////////////////TICKET #412 does attaching new objects really work this way??
CHECK (newTrack != someTrack); // it's a new placement
CHECK (num_sequences + 1 == sess->sequences.size());
PSequence aSequence = sess->sequences[num_sequences];
CHECK (newTrack == aSequence->getTracks());
CHECK (newTrack);
CHECK (someTrack);
CHECK (assetM.known (aSequence->getID()));
//TODO maybe even bind it into a new timeline. Then verify this new timeline gets removed alongside with the sequence below!
// just moving the new track away from root position
// causes the sequence to disappear
newTrack.getPlacement().chain (someTrack, Time(20)); /////////////////TICKET #555 does moving by placement really work this way??
//TODO how to verify the changed placement??
CHECK (!assetM.known (aSequence->getID()));
CHECK (num_sequences == sess->sequences.size());
CHECK (!contains (sess->sequences, aSequence));
CHECK (someTrack);
CHECK (newTrack);
}
};