specify (as test) how asset dependency should work
This commit is contained in:
parent
49459b4bf7
commit
66daf409d4
8 changed files with 241 additions and 20 deletions
|
|
@ -98,8 +98,10 @@ namespace util
|
|||
inline bool
|
||||
contains (SEQ& cont, typename SEQ::value_type& val)
|
||||
{
|
||||
typename SEQ::iterator end = cont.end();
|
||||
return end != std::find(cont.begin(),end, val);
|
||||
typename SEQ::const_iterator begin = cont.begin();
|
||||
typename SEQ::const_iterator end = cont.end();
|
||||
|
||||
return end != std::find(begin,end, val);
|
||||
}
|
||||
|
||||
/** shortcut for removing all copies of an Element
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ namespace asset
|
|||
* on the enablement status of parent assets as well.
|
||||
*/
|
||||
void
|
||||
Asset::enable () throw(cinelerra::error::State)
|
||||
Asset::enable (bool on) throw(cinelerra::error::State)
|
||||
{
|
||||
UNIMPLEMENTED ("enable/disable Assets.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ namespace asset
|
|||
const size_t hash;
|
||||
ID (size_t id) : hash(id) {}
|
||||
ID (const KIND& asset) : hash(asset.getID()) {}
|
||||
operator size_t() const { return hash; }
|
||||
operator size_t() const { return hash; }
|
||||
};
|
||||
|
||||
class Asset;
|
||||
|
|
@ -248,7 +248,7 @@ namespace asset
|
|||
friend class AssetManager;
|
||||
|
||||
private:
|
||||
void unregister (PAsset& other);
|
||||
void unregister (PAsset& other);
|
||||
|
||||
|
||||
|
||||
|
|
@ -274,7 +274,7 @@ namespace asset
|
|||
* Note the corresponding #isActive predicate may
|
||||
* depend on the enablement status of parent assets as well
|
||||
*/
|
||||
void enable () throw(cinelerra::error::State);
|
||||
void enable (bool on=true) throw(cinelerra::error::State);
|
||||
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,15 +22,16 @@
|
|||
|
||||
|
||||
#include "common/test/run.hpp"
|
||||
//#include "common/factory.hpp"
|
||||
//#include "common/util.hpp"
|
||||
#include "proc/asset/testasset.hpp"
|
||||
#include "common/util.hpp"
|
||||
|
||||
//#include <boost/format.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using util::isnil;
|
||||
using util::contains;
|
||||
//using boost::format;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
|
||||
|
||||
namespace asset
|
||||
|
|
@ -49,10 +50,127 @@ namespace asset
|
|||
*/
|
||||
class DependantAssets_test : public Test
|
||||
{
|
||||
virtual void run(Arg arg)
|
||||
virtual void run (Arg arg)
|
||||
{
|
||||
checkDependencyMechanics ();
|
||||
checkUnlinking ();
|
||||
TODO ("activate missing testcases");
|
||||
/////TODO checkEnablementPropagation ();
|
||||
/////TODO checkRealAssetDependencyRegistration ();
|
||||
}
|
||||
|
||||
typedef TestAsset<Asset> TA;
|
||||
typedef TA::PA PTestA;
|
||||
|
||||
/** @test check operation of basic asset dependency support
|
||||
*/
|
||||
void checkDependencyMechanics ()
|
||||
{
|
||||
PAsset a1 = TA::create();
|
||||
ASSERT (isnil (a1->getParents()));
|
||||
ASSERT (isnil (a1->getDependant()));
|
||||
|
||||
PTestA a2 = TA::create(a1);
|
||||
ASSERT (a1 == a2->getParents()[0]); // TestAsset registered a1 as parent
|
||||
ASSERT (a2 == a1->getDependant()[0]);
|
||||
|
||||
TRACE(test, "a1.cnt=%i",a1.use_count());
|
||||
TRACE(test, "a2.cnt=%i",a2.use_count());
|
||||
PAsset a3 = TA::create();
|
||||
a2->set_depend(a3);
|
||||
ASSERT (a3 == a2->getParents()[1]);
|
||||
ASSERT (a2 == a3->getDependant()[0]);
|
||||
ASSERT (!contains (a1->getDependant(), a3));
|
||||
}
|
||||
|
||||
|
||||
/** @test unlink operation removing inter asset links
|
||||
*/
|
||||
void checkUnlinking ()
|
||||
{
|
||||
PTestA a1_ = TA::create();
|
||||
PAsset a1 (a1_);
|
||||
PTestA a2_ = TA::create(a1);
|
||||
PAsset a2 (a2_);
|
||||
ASSERT (a1 == a2->getParents()[0]);
|
||||
ASSERT (a2 == a1->getDependant()[0]);
|
||||
|
||||
a2_->call_unlink();
|
||||
ASSERT (isnil (a2->getParents()));
|
||||
ASSERT (isnil (a2->getDependant()));
|
||||
ASSERT (!contains (a1->getDependant(), a2)); // has been propagated
|
||||
|
||||
a2_->set_depend(a1);
|
||||
PAsset a3 = TA::create(a1);
|
||||
ASSERT (a1 == a2->getParents()[0]);
|
||||
ASSERT (a1 == a3->getParents()[0]);
|
||||
ASSERT (a2 == a1->getDependant()[0]);
|
||||
ASSERT (a3 == a1->getDependant()[1]);
|
||||
|
||||
a1_->call_unlink(a3->getID());
|
||||
ASSERT (!contains (a1->getDependant(), a3)); // selectively removed
|
||||
ASSERT ( contains (a1->getDependant(), a2));
|
||||
ASSERT (a1 == a3->getParents()[0]); // no propagation
|
||||
}
|
||||
|
||||
|
||||
/** @test enabling and disabling an asset should
|
||||
* propagate to dependant assets
|
||||
*/
|
||||
void checkEnablementPropagation ()
|
||||
{
|
||||
PAsset a1 = TA::create();
|
||||
PAsset a2 = TA::create(a1);
|
||||
PAsset a3 = TA::create(); // not dependant
|
||||
|
||||
ASSERT (a1->isActive());
|
||||
ASSERT (a2->isActive());
|
||||
ASSERT (a3->isActive());
|
||||
|
||||
a1->enable(false);
|
||||
ASSERT (!a1->isActive());
|
||||
ASSERT (!a2->isActive());
|
||||
ASSERT (a3->isActive());
|
||||
|
||||
a2->enable(true);
|
||||
ASSERT (!a1->isActive());
|
||||
ASSERT (!a2->isActive()); // ignored because parent is disabled
|
||||
|
||||
a1->enable(true);
|
||||
ASSERT (a1->isActive());
|
||||
ASSERT (a2->isActive());
|
||||
|
||||
a2->enable(false);
|
||||
ASSERT (a1->isActive());
|
||||
ASSERT (!a2->isActive()); // disabling not propagated to parent
|
||||
a2->enable(true);
|
||||
ASSERT (a1->isActive());
|
||||
ASSERT (a2->isActive());
|
||||
|
||||
a3->enable(false);
|
||||
ASSERT (a1->isActive());
|
||||
ASSERT (a2->isActive());
|
||||
ASSERT (!a3->isActive()); // no dependency...
|
||||
|
||||
a1->enable(false);
|
||||
a3->enable();
|
||||
ASSERT (!a1->isActive());
|
||||
ASSERT (!a2->isActive());
|
||||
ASSERT (a3->isActive());
|
||||
}
|
||||
|
||||
|
||||
/** @test each real world asset subclass has to care
|
||||
* for registering and deregistering any additional
|
||||
* dependencies. Here we collect some more prominent
|
||||
* examples (and hopfully don't fail to cover any
|
||||
* important special cases...)
|
||||
*/
|
||||
void checkRealAssetDependencyRegistration ()
|
||||
{
|
||||
UNIMPLEMENTED ("handling of Asset dependencies");
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ namespace asset
|
|||
* @test creating several Assets and checking object identity,
|
||||
* detection of duplicates and version handling.
|
||||
* @see proc_interface::AssetManager#reg
|
||||
* @todo to be written; features are missing as of 9/07
|
||||
*/
|
||||
class IdentityOfAssets_test : public Test
|
||||
{
|
||||
|
|
|
|||
107
tests/components/proc/asset/testasset.hpp
Normal file
107
tests/components/proc/asset/testasset.hpp
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
TESTASSET.hpp - test asset (stub) for checking internal asset functionality
|
||||
|
||||
Copyright (C) CinelerraCV
|
||||
2007, Christian Thaeter <ct@pipapo.org>
|
||||
|
||||
This program 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.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ASSET_TESTASSET_H
|
||||
#define ASSET_TESTASSET_H
|
||||
|
||||
|
||||
#include "proc/asset.hpp"
|
||||
//#include "common/util.hpp"
|
||||
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
||||
using std::tr1::shared_ptr;
|
||||
using boost::format;
|
||||
using std::string;
|
||||
|
||||
|
||||
namespace asset
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
uint counter (0);
|
||||
|
||||
/** @internal helper generating continuosely
|
||||
* different new asset identities
|
||||
*/
|
||||
Asset::Ident
|
||||
make_ident ()
|
||||
{
|
||||
return Asset::Ident ( str(format("TestAsset.%i") % counter)
|
||||
, Category (META)
|
||||
, "test"
|
||||
, counter++
|
||||
);
|
||||
}
|
||||
Asset::Ident
|
||||
make_ident (PAsset& ref)
|
||||
{
|
||||
return Asset::Ident ( str(format("%s-TestAsset.%i") % ref->ident.name
|
||||
% counter)
|
||||
, ref->ident.category
|
||||
, "test"
|
||||
, counter++
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Test(mock) asset subclass usable for hijacking a given
|
||||
* asset class (template parameter) and subsequently accessing
|
||||
* internal facillities for writing unit tests. Prerequisite
|
||||
* for using this template is that the used asset base class
|
||||
* has a (protected) ctor taking an Asset::Ident....
|
||||
*/
|
||||
template<class A>
|
||||
class TestAsset : public A
|
||||
{
|
||||
TestAsset () : A(make_ident ()) { };
|
||||
TestAsset (PAsset& pRef) : A(make_ident (pRef)) { this->defineDependency(pRef); };
|
||||
|
||||
static void deleter (TestAsset<A>* aa) { delete aa; }
|
||||
|
||||
public:
|
||||
typedef shared_ptr<TestAsset<A> > PA;
|
||||
|
||||
static PA create () { return PA (new TestAsset<A>, &deleter); }
|
||||
static PA create (PAsset& pRef) { return PA (new TestAsset<A> (pRef), &deleter); }
|
||||
|
||||
/* === interesting asset features we want to access for tests === */
|
||||
void call_unlink () { this->unlink (); }
|
||||
void call_unlink (IDA target) { this->unlink (target); }
|
||||
void set_depend (PAsset parent) { this->defineDependency (parent); }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace asset
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
TestClip - bookkeeping (asset) view of a media clip.
|
||||
TestClip - test clip (stub) for checking EDL/Session functionality
|
||||
|
||||
Copyright (C) CinelerraCV
|
||||
2007, Christian Thaeter <ct@pipapo.org>
|
||||
|
|
@ -70,7 +70,7 @@ namespace mobject
|
|||
{ }
|
||||
};
|
||||
|
||||
cinelerra::Singleton<Testbed> testbed_1;
|
||||
cinelerra::Singleton<Testbed> testbed_1; // invoke ctor when creating first TestClip...
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,20 +25,15 @@
|
|||
#define MOBJECT_SESSION_TESTCLIP_H
|
||||
|
||||
|
||||
#include "common/test/run.hpp"
|
||||
#include "common/factory.hpp"
|
||||
|
||||
#include "proc/mobject/session/clip.hpp"
|
||||
//#include "common/util.hpp"
|
||||
|
||||
|
||||
//#include <boost/format.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using std::tr1::shared_ptr;
|
||||
//using boost::format;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
|
||||
|
||||
namespace mobject
|
||||
|
|
@ -55,7 +50,7 @@ namespace mobject
|
|||
* @todo make this usable as Mock object to record invoked operations.
|
||||
*
|
||||
*/
|
||||
class TestClip : public mobject::session::Clip /////////////TODO how this????
|
||||
class TestClip : public mobject::session::Clip
|
||||
{
|
||||
|
||||
TestClip ();
|
||||
|
|
|
|||
Loading…
Reference in a new issue