DependantAssets_test now (partially) running
This commit is contained in:
parent
95af2d50cc
commit
393f0944c1
5 changed files with 143 additions and 38 deletions
|
|
@ -103,8 +103,15 @@ namespace asset
|
|||
return dynamic_pointer_cast<KIND,Asset> (find (hash));
|
||||
}
|
||||
|
||||
/** removes all registered assets and invokes
|
||||
* Asset::unlink() on each to break cyclic dependencies
|
||||
/** removes all registered assets and does something similar
|
||||
* to Asset::unlink() on each to break cyclic dependencies
|
||||
* (we can't use the real unlink()-function, because this
|
||||
* will propagate, including calls to the AssetManager.
|
||||
* As the destructor of DB needs to call clear(), this
|
||||
* could result in segfaults. This doesn't seem to be
|
||||
* a problem, though, because we register and process
|
||||
* \i all assets and the net effect is just breaking
|
||||
* any cyclic dependencies)
|
||||
*/
|
||||
void
|
||||
clear () throw()
|
||||
|
|
@ -113,8 +120,8 @@ namespace asset
|
|||
{
|
||||
IdHashtable::const_iterator i = table.begin();
|
||||
IdHashtable::const_iterator e = table.end();
|
||||
for ( ; i!=e ; ++i )
|
||||
i->second->unlink();
|
||||
for ( ; i!=e ; ++i )
|
||||
i->second->dependants.clear();
|
||||
|
||||
table.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ PLANNED "DeleteAsset_test" DeleteAsset_test <<END
|
|||
END
|
||||
|
||||
|
||||
PLANNED "DependantAssets_test" DependantAssets_test <<END
|
||||
TEST "DependantAssets_test" DependantAssets_test <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ namespace asset
|
|||
ASSERT (!isnil (a2->getParents()));
|
||||
ASSERT (contains (a3->getParents(), a2)); // but up-links remain intact
|
||||
|
||||
a2_->call_unlink(a1->getID());
|
||||
a2_->set_depend(a1);
|
||||
PAsset a4 = TA::create(a1);
|
||||
ASSERT (a1 == a2->getParents()[0]);
|
||||
|
|
|
|||
123
tests/components/proc/asset/testasset.cpp
Normal file
123
tests/components/proc/asset/testasset.cpp
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
TestClip - test clip (stub) for checking EDL/Session 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.
|
||||
|
||||
* *****************************************************/
|
||||
|
||||
|
||||
#include "proc/asset/testasset.hpp"
|
||||
#include "proc/assetmanager.hpp"
|
||||
|
||||
using std::tr1::static_pointer_cast;
|
||||
|
||||
namespace asset
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
uint counter (0);
|
||||
|
||||
/** @internal helper generating continuosely
|
||||
* different new asset identities
|
||||
*/
|
||||
Asset::Ident
|
||||
make_new_ident ()
|
||||
{
|
||||
return Asset::Ident ( str(format("TestAsset.%i") % counter)
|
||||
, Category (META)
|
||||
, "test"
|
||||
, counter++
|
||||
);
|
||||
}
|
||||
Asset::Ident
|
||||
make_new_ident (PAsset& ref)
|
||||
{
|
||||
return Asset::Ident ( str(format("%s-TestAsset.%i") % ref->ident.name
|
||||
% counter)
|
||||
, ref->ident.category
|
||||
, "test"
|
||||
, counter++
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class A>
|
||||
TestAsset<A>::TestAsset ()
|
||||
: A(make_new_ident ())
|
||||
{ };
|
||||
|
||||
|
||||
template<class A>
|
||||
TestAsset<A>::TestAsset (PAsset& pRef)
|
||||
: A(make_new_ident (pRef))
|
||||
{
|
||||
this->defineDependency(pRef);
|
||||
};
|
||||
|
||||
|
||||
/** @internal helper for the create()-Functions
|
||||
* retrieving the smart ptr created automatically
|
||||
* within AssetManager by the Asset base class ctor
|
||||
*/
|
||||
template<class A>
|
||||
shared_ptr<TestAsset<A> >
|
||||
TestAsset<A>::ptrFromThis ()
|
||||
{
|
||||
return static_pointer_cast<TestAsset<A>,Asset>
|
||||
(AssetManager::instance().getAsset (this->id));
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace asset
|
||||
|
||||
|
||||
|
||||
|
||||
/*********************************************************/
|
||||
/* explicit template instantiations for some Asset Kinds */
|
||||
/*********************************************************/
|
||||
|
||||
#include "proc/asset/unknown.hpp"
|
||||
|
||||
|
||||
namespace asset
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
template TestAsset<Asset>::TestAsset ();
|
||||
template TestAsset<Unknown>::TestAsset ();
|
||||
|
||||
template TestAsset<Asset>::TestAsset (PAsset& pRef);
|
||||
template TestAsset<Unknown>::TestAsset (PAsset& pRef);
|
||||
|
||||
template shared_ptr<TestAsset<Asset> > TestAsset<Asset>::ptrFromThis ();
|
||||
template shared_ptr<TestAsset<Unknown> > TestAsset<Unknown>::ptrFromThis ();
|
||||
|
||||
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace asset
|
||||
|
|
@ -41,35 +41,6 @@ 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
|
||||
|
|
@ -81,22 +52,24 @@ namespace asset
|
|||
template<class A>
|
||||
class TestAsset : public A
|
||||
{
|
||||
TestAsset () : A(make_ident ()) { };
|
||||
TestAsset (PAsset& pRef) : A(make_ident (pRef)) { this->defineDependency(pRef); };
|
||||
TestAsset () ;
|
||||
TestAsset (PAsset&); ///< declared dependant on the given Asset
|
||||
|
||||
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); }
|
||||
static PA create () { return (new TestAsset<A> )->ptrFromThis(); }
|
||||
static PA create (PAsset& pRef) { return (new TestAsset<A> (pRef))->ptrFromThis(); }
|
||||
|
||||
/* === 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); }
|
||||
|
||||
private:
|
||||
PA ptrFromThis ();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue