diff --git a/src/proc/asset.cpp b/src/proc/asset.cpp index 622311863..460464a8e 100644 --- a/src/proc/asset.cpp +++ b/src/proc/asset.cpp @@ -27,6 +27,8 @@ #include +#include +#include using boost::format; using util::cStr; @@ -46,12 +48,12 @@ namespace asset */ Asset::Asset (const Ident& idi) : ident(idi), id(AssetManager::reg (this, idi)) - { TRACE (assetmem, "ctor Asset(id=%d) : %s p=%x", size_t(id), cStr(this->ident), this ); + { TRACE (assetmem, "ctor Asset(id=%lu) : adr=%x %s", size_t(id), this, cStr(this->ident) ); } Asset::~Asset () { - TRACE (assetmem, "dtor Asset(id=%d) : %s p=%x", size_t(id), cStr(this->ident), this ); + TRACE (assetmem, "dtor Asset(id=%lu) : adr=%x", size_t(id), this ); } diff --git a/src/proc/asset.hpp b/src/proc/asset.hpp index e6fd207c6..a6e3b1ad8 100644 --- a/src/proc/asset.hpp +++ b/src/proc/asset.hpp @@ -175,20 +175,30 @@ namespace asset && name == other.name && category == other.category; } + bool operator!= (const Ident& other) const + { + return !operator==(other); + } + int compare (const Ident& other) const; operator string () const; }; + + + /* ===== Asset ID and Datafields ===== */ + public: const Ident ident; ///< Asset identification tuple + virtual const ID& getID() const { return id; } + virtual operator string () const; + protected: const ID id; ///< Asset primary key. - - protected: /** additional classification, selections or departments this asset belongs to. * Groups are optional, non-exclusive and may be overlapping. */ @@ -209,7 +219,7 @@ namespace asset * Calling this base ctor causes registration with AssetManager. */ Asset (const Ident& idi); - virtual ~Asset() = 0; + virtual ~Asset() = 0; ///< @note Asset is abstract /** release all links to other Asset objects held internally. * The lifecycle of Asset objects is managed by smart pointers @@ -230,6 +240,7 @@ namespace asset friend class AssetManager; + public: /** List of entities this asset depends on or requires to be functional. * May be empty. The head of this list can be considered the primary prerequisite diff --git a/src/proc/asset/db.hpp b/src/proc/asset/db.hpp index 76be677f0..b9faa0a42 100644 --- a/src/proc/asset/db.hpp +++ b/src/proc/asset/db.hpp @@ -88,6 +88,7 @@ namespace asset friend class cinelerra::singleton::Static; + public: template void put (ID hash, shared_ptr& ptr) { table[hash] = static_pointer_cast (ptr); } @@ -95,20 +96,33 @@ namespace asset template shared_ptr - get (ID hash) + get (ID hash) const { - return dynamic_pointer_cast (table[hash]); + return dynamic_pointer_cast (find (hash)); } + /** intended for diagnostics */ void - asList (list& output) const + asList (list& output) const { IdHashtable::const_iterator i = table.begin(); IdHashtable::const_iterator e = table.end(); for ( ; i!=e ; ++i ) output.push_back (i->second); } + + private: + const PAsset & + find (size_t hash) const + { + static const PAsset NULLP; + IdHashtable::const_iterator i = table.find (hash); + if (i == table.end()) + return NULLP; // empty ptr signaling "not found" + else + return i->second; + } }; diff --git a/src/proc/assetmanager.hpp b/src/proc/assetmanager.hpp index 8ccf0ac61..c677f6ef4 100644 --- a/src/proc/assetmanager.hpp +++ b/src/proc/assetmanager.hpp @@ -102,8 +102,7 @@ namespace asset throw(cinelerra::error::Invalid); /** deleter function used by the Asset smart pointers to delet Asset objects */ - static void destroy (Asset* m) { TRACE (assetmem, "call destroy (Asset(id=%d)) p=%x", m? size_t(m->getID()):0, m ); - delete m; } + static void destroy (Asset* m) { delete m; } friend Asset::Asset (const Asset::Ident& idi); diff --git a/tests/51asset.tests b/tests/51asset.tests index 37b7dac4f..4c87542f4 100644 --- a/tests/51asset.tests +++ b/tests/51asset.tests @@ -2,7 +2,8 @@ TESTING "Component Test Suite: Asset Manager" ./test-components --group=asset -PLANNED "CreateAsset_test" CreateAsset_test <getID() % &aa % aa.get() % aa.use_count() << "\n"; + format fmt("%s %|50T.| id=%s adr=%x smart-ptr=%x use-count=%d"); + cout << fmt % str(aa) % aa->getID() % aa.get() % &aa % (aa.use_count() - 1) << "\n"; } } inline void dumpAssetManager () diff --git a/tests/components/proc/asset/createassettest.cpp b/tests/components/proc/asset/createassettest.cpp index b5f449787..00fa049f0 100644 --- a/tests/components/proc/asset/createassettest.cpp +++ b/tests/components/proc/asset/createassettest.cpp @@ -52,9 +52,14 @@ namespace asset { createMedia(); factoryVariants(); - dumpAssetManager(); + + if (!isnil (arg)) + dumpAssetManager(); + TRACE (assetmem, "leaving CreateAsset_test::run()"); } + + typedef shared_ptr PM; /** @test Creating and automatically registering Asset instances. @@ -79,9 +84,6 @@ namespace asset ASSERT (aMang.getAsset (mm1->getID()) != mm2); - cout << "== 1 ==\n"; - dumpAssetManager(); - PAsset aa1 = aMang.getAsset (ID(mm1->getID())); // note we get an Asset ref ASSERT (aa1 == mm1); PM mX1 = aMang.getAsset (mm1->getID()); // ..and now we get a Media ref @@ -92,22 +94,19 @@ namespace asset ASSERT (aMang.known (mm2->getID())); ASSERT (aMang.known (mm3->getID())); - cout << "== 2 ==\n"; - dumpAssetManager(); - ASSERT ( !aMang.known (mm3->getID(), Category(AUDIO))); // not found within AUDIO-Category try { // can't be found if specifying wrong Asset kind.... aMang.getAsset (ID(mm1->getID())); NOTREACHED; } - catch (cinelerra::error::Invalid& exe) {ASSERT (exe.getID()==CINELERRA_ERROR_WRONG_ASSET_KIND);} + catch (cinelerra::error::Invalid& xxx) {ASSERT (xxx.getID()==CINELERRA_ERROR_WRONG_ASSET_KIND);} try { // try accessing nonexistant ID aMang.getAsset (ID (1234567890)); NOTREACHED; } - catch (cinelerra::error::Invalid& exe) {ASSERT (exe.getID()==CINELERRA_ERROR_UNKNOWN_ASSET_ID);} + catch (cinelerra::error::Invalid& xxx) {ASSERT (xxx.getID()==CINELERRA_ERROR_UNKNOWN_ASSET_ID);} // checking the Ident-Fields @@ -132,12 +131,8 @@ namespace asset ASSERT (mm2->getFilename() == "testfile1.mov"); ASSERT (mm3->getFilename() == "testfile2.mov"); - dump (mm1); - dump (mm2); - dump (mm3); - dump (mX1); - cout << "== 3 ==\n"; - dumpAssetManager(); + + TRACE (assetmem, "leaving test method scope"); } diff --git a/tests/components/proc/asset/identityofassetstest.cpp b/tests/components/proc/asset/identityofassetstest.cpp index d55623538..2e62963bc 100644 --- a/tests/components/proc/asset/identityofassetstest.cpp +++ b/tests/components/proc/asset/identityofassetstest.cpp @@ -53,9 +53,14 @@ namespace asset virtual void run(Arg arg) { createDuplicate(); - cout << "ausis\n"; + + if (!isnil (arg)) + dumpAssetManager(); + TRACE (assetmem, "leaving IdentityOfAssets_test::run()"); } + + typedef shared_ptr PM; /** @test produce an ID clash. @@ -70,9 +75,9 @@ namespace asset Asset::Ident idi (mm1->ident); // duplicate Ident record PM mm1X = asset::Media::create (idi); // note: we actually don't call any ctor ASSERT (mm1 == mm1X); // instead, we got mm1 back. - cout << "usi-v " << mm1.use_count() <<"\n"; + PM mm2 = asset::Media::create (idi,"testfile2.mov"); - cout << "usi-n " << mm1.use_count() <<"\n"; + ASSERT (mm1->getID() == mm2->getID()); // different object, same hash AssetManager& aMang = AssetManager::instance(); @@ -86,11 +91,8 @@ namespace asset ASSERT (mm1->getFilename() == "testfile1.mov"); ASSERT (mm2->getFilename() == "testfile2.mov"); - cout << "use-cnt at end " << mm1.use_count() <<"\n"; - dump (mm1); - dump (mm1X); - dump (mm2); - dumpAssetManager(); + + TRACE (assetmem, "leaving test method scope"); } }; diff --git a/tests/components/proc/asset/orderingofassetstest.cpp b/tests/components/proc/asset/orderingofassetstest.cpp new file mode 100644 index 000000000..4e6137224 --- /dev/null +++ b/tests/components/proc/asset/orderingofassetstest.cpp @@ -0,0 +1,125 @@ +/* + OrderingOfAssets(Test) - equality and comparisons + + Copyright (C) CinelerraCV + 2007, Christian Thaeter + + 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 "common/test/run.hpp" +#include "common/util.hpp" + +#include "proc/assetmanager.hpp" +#include "proc/asset/media.hpp" +#include "proc/asset/proc.hpp" + +#include "proc/asset/assetdiagnostics.hpp" + +using util::isnil; +using std::string; + + +namespace asset + { + namespace test + { + + + + + /****************************************************** + * @test validate the equality and order relations of + * Asset::Ident and Asset objects. + * @see Asset::Ident#compare + */ + class OrderingOfAssets_test : public Test + { + virtual void run(Arg arg) + { + typedef shared_ptr PM; + + Asset::Ident key1("Au-1", Category(AUDIO), "ichthyo", 5); + PM mm1 = asset::Media::create(key1, "Name-1"); + + Asset::Ident key2("Au-1", Category(AUDIO), "ichthyo", 7); + PM mm2 = asset::Media::create(key2, "Name-2"); + + Asset::Ident key3("Au-2", Category(AUDIO), "ichthyo", 5); + PM mm3 = asset::Media::create(key3, "Name-3"); + + Asset::Ident key4("Au-2", Category(AUDIO), "stega", 5); + PM mm4 = asset::Media::create(key4, "Name-4"); + + Asset::Ident key5("Au-1", Category(VIDEO), "ichthyo", 5); + PM mm5 = asset::Media::create(key5, "Name-5"); + + + // ordering of keys + ASSERT (key1 == key2); + ASSERT (key2 != key3); + ASSERT (key3 != key4); + ASSERT (key4 != key5); + ASSERT (key1 != key5); + + ASSERT (-1 == key2.compare(key3)); + ASSERT (+1 == key3.compare(key2)); + + ASSERT (-1 == key3.compare(key4)); + ASSERT (-1 == key4.compare(key5)); + ASSERT (-1 == key1.compare(key5)); + ASSERT (-1 == key2.compare(key5)); + ASSERT (-1 == key3.compare(key5)); + ASSERT (-1 == key1.compare(key3)); + ASSERT (-1 == key1.compare(key4)); + ASSERT (-1 == key2.compare(key4)); + + + // ordering of Asset smart ptrs + ASSERT (mm1 == mm2); + ASSERT (mm2 != mm3); + ASSERT (mm3 != mm4); + ASSERT (mm4 != mm5); + ASSERT (mm1 != mm5); + + ASSERT (mm2 < mm3); + ASSERT (mm2 <= mm3); + ASSERT (mm3 > mm2); + ASSERT (mm3 >= mm2); + + ASSERT (mm3 < mm4); + ASSERT (mm4 < mm5); + ASSERT (mm1 < mm5); + ASSERT (mm2 < mm5); + ASSERT (mm3 < mm5); + ASSERT (mm1 < mm3); + ASSERT (mm1 < mm4); + ASSERT (mm2 < mm4); + + } + + }; + + + /** Register this test class... */ + LAUNCHER (OrderingOfAssets_test, "unit asset"); + + + + } // namespace test + +} // namespace asset