WIP test coverage, debugging...

still have to fix a segfault :-)
This commit is contained in:
Fischlurch 2007-09-16 17:17:54 +02:00
parent 5da016aa5a
commit 3a416f9e41
7 changed files with 214 additions and 21 deletions

View file

@ -59,6 +59,13 @@ namespace asset
static format id_tuple("(%2%:%3%.%1% v%4%)"); // ignoring threadsafety
return str (id_tuple % name % category % org % version);
}
Asset::operator string () const
{
static format id_tuple("Asset(%2%:%3%.%1% v%4%)"); // ignoring threadsafety
return str (id_tuple % ident.name % ident.category % ident.org % ident.version);
}
/** List of entities this asset depends on or requires to be functional.

View file

@ -181,6 +181,7 @@ namespace asset
const Ident ident; ///< Asset identification tuple
virtual const ID<Asset>& getID() const { return id; }
virtual operator string () const;
protected:
const ID<Asset> id; ///< Asset primary key.
@ -260,6 +261,15 @@ namespace asset
/** shorthand for refcounting Asset pointers */
typedef shared_ptr<Asset> PAsset;
/** convienient for debugging */
inline string str (const PAsset& a)
{
if (a)
return string (*a.get());
else
return "Asset(NULL)";
}
} // namespace asset

View file

@ -96,7 +96,7 @@ namespace asset
}
ASSERT (pM);
ENSURE (key.category.hasKind (VIDEO) || key.category.hasKind(AUDIO));
ENSURE (isnil (key.name));
ENSURE (!isnil (key.name));
ENSURE (dynamic_cast<Media*>(pM) || (isnil (file) && dynamic_cast<Unknown*>(pM)));
return aMang.getAsset (pM->getID()); // note: because we query with an ID<Media>,
@ -108,7 +108,7 @@ namespace asset
* providing most of the Asset key fields based on the filename given
*/
MediaFactory::PType
MediaFactory::operator() (const string& file, Category& cat)
MediaFactory::operator() (const string& file, const Category& cat)
{
Asset::Ident key(extractName(file), cat, "cin3", 1);
return operator() (key, file);
@ -123,7 +123,7 @@ namespace asset
MediaFactory::PType
MediaFactory::operator() (const char* file, Category& cat)
MediaFactory::operator() (const char* file, const Category& cat)
{
if (!file) file = "";
return operator() (string(file),cat);

View file

@ -97,11 +97,11 @@ namespace asset
typedef shared_ptr<asset::Media> PType;
PType operator() (Asset::Ident& key, const string& file="");
PType operator() (const string& file, Category& cat);
PType operator() (const string& file, const Category& cat);
PType operator() (const string& file, asset::Kind);
PType operator() (Asset::Ident& key, const char* file); ///< convienience overload using C-String
PType operator() (const char* file, Category& cat);
PType operator() (const char* file, const Category& cat);
PType operator() (const char* file, asset::Kind);
};

View file

@ -103,7 +103,8 @@ namespace asset
AssetManager ();
friend class cinelerra::singleton::Static<AssetManager>;
private:
static void detach_child (PAsset&, IDA);
};

View file

@ -22,18 +22,17 @@
#include "common/test/run.hpp"
//#include "common/factory.hpp"
#include "common/util.hpp"
#include "proc/assetmanager.hpp"
#include "proc/asset/media.hpp"
#include "proc/asset/proc.hpp"
//#include <boost/format.hpp>
#include <boost/format.hpp>
#include <iostream>
using boost::format;
using util::isnil;
//using boost::format;
using std::string;
using std::cout;
@ -43,7 +42,6 @@ namespace asset
namespace test
{
// typedef Category::Kind Kind;
@ -56,15 +54,23 @@ namespace asset
virtual void run(Arg arg)
{
createMedia();
}
factoryVariants();
}
typedef shared_ptr<asset::Media> PM;
/** @test Creating and automatically registering Asset instances.
* Re-Retrieving the newly created objects from AssetManager.
* Checking AssetManager access functions, esp. getting
* different kinds of Assets by ID, querying with the
* wrong Category and querying unknown IDs.
*/
void createMedia()
{
typedef shared_ptr<asset::Media> PM;
Category cat(VIDEO,"bin1");
Asset::Ident key("Name-1", cat, "ichthyo", 5);
PM mm1 = asset::Media::create(key,"testfile.mov");
PM mm2 = asset::Media::create(key);
PM mm2 = asset::Media::create("testfile1.mov", cat);
PM mm3 = asset::Media::create("testfile2.mov", VIDEO);
// Assets have been registered and can be retrieved by ID
@ -91,12 +97,18 @@ namespace asset
aMang.getAsset (ID<asset::Proc>(mm1->getID()));
NOTREACHED;
}
catch (cinelerra::error::Invalid) { }
catch (cinelerra::error::Invalid& exe) {ASSERT (exe.getID()==CINELERRA_ERROR_WRONG_ASSET_KIND);}
try
{ // try accessing nonexistant ID
aMang.getAsset (ID<Asset> (1234567890));
NOTREACHED;
}
catch (cinelerra::error::Invalid& exe) {ASSERT (exe.getID()==CINELERRA_ERROR_UNKNOWN_ASSET_ID);}
// checking the Ident-Fields
ASSERT (mm1->ident.name == "Name-1");
ASSERT (mm2->ident.name == "Name-1");
ASSERT (mm2->ident.name == "testfile1");
ASSERT (mm3->ident.name == "testfile2");
ASSERT (cat == Category (VIDEO,"bin1"));
@ -105,19 +117,72 @@ namespace asset
ASSERT (mm3->ident.category == Category (VIDEO ));
ASSERT (mm1->ident.org == "ichthyo");
ASSERT (mm2->ident.org == "ichthyo");
ASSERT (mm2->ident.org == "cin3");
ASSERT (mm3->ident.org == "cin3");
ASSERT (mm1->ident.version == 5);
ASSERT (mm2->ident.version == 5);
ASSERT (mm2->ident.version == 1);
ASSERT (mm3->ident.version == 1);
ASSERT (mm1->getFilename() == "testfile.mov");
ASSERT (isnil (mm2->getFilename()));
ASSERT (mm2->getFilename() == "testfile1.mov");
ASSERT (mm3->getFilename() == "testfile2.mov");
/*
////////////////////////////////////////////////////////////////////////////////TODO fuck the compiler!!!
*/
showPtr (mm1);
showPtr (mm2);
showPtr (mm3);
showPtr (mX1);
}
/** @test different variants of calling the MediaFactory,
* with focus on the behaviour of the basic Asset
* creation machinery. Covers filling out Asset's
* datafields, amending missing pieces of information.
*/
void factoryVariants()
{
PM candi;
Asset::Ident key1("Au-1", Category(AUDIO), "ichthyo", 5);
candi = asset::Media::create(key1);
ASSERT ( checkProperties (candi, key1, ""));
candi = asset::Media::create(key1, string("testfile.wav"));
ASSERT ( checkProperties (candi, key1, "testfile.wav"));
Asset::Ident key2("", Category(AUDIO), "ichthyo", 5);
candi = asset::Media::create(key2, string("testfile2.wav"));
ASSERT ( checkProperties (candi, key2, "testfile2.wav"));
ASSERT (key2.name == "testfile2"); // name filled in automatically
candi = asset::Media::create(string("testfile3.wav"), Category(AUDIO));
ASSERT ( checkProperties (candi, Asset::Ident("testfile3", Category(AUDIO), "cin3", 1)
, "testfile3.wav"));
candi = asset::Media::create("some/path/testfile4.wav", Category(AUDIO));
ASSERT ( checkProperties (candi, Asset::Ident("testfile4", Category(AUDIO), "cin3", 1)
, "some/path/testfile4.wav"));
candi = asset::Media::create("", Category(AUDIO,"sub/bin"));
ASSERT ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO,"sub/bin"), "cin3", 1)
, ""));
candi = asset::Media::create("", AUDIO);
ASSERT ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO), "cin3", 1)
, ""));
}
bool checkProperties (PM object, Asset::Ident identity, string filename)
{
return identity == object->ident
&& filename == object->getFilename();
}
void showPtr (PM m)
{
static format fmt("Asset(%s) .... ptr=%d use-count=%d");
cout << fmt % str(m) % &m % m.use_count() << "\n";
}
};

View file

@ -0,0 +1,110 @@
/*
IdentityOfAssets(Test) - Asset object identity and versioning
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 "common/test/run.hpp"
#include "common/util.hpp"
#include "proc/assetmanager.hpp"
#include "proc/asset/media.hpp"
#include "proc/asset/proc.hpp"
#include <boost/format.hpp>
#include <iostream>
using boost::format;
using util::isnil;
using std::string;
using std::cout;
namespace asset
{
namespace test
{
/***********************************************************************
* @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
{
virtual void run(Arg arg)
{
createDuplicate();
}
typedef shared_ptr<asset::Media> PM;
/** @test produce an ID clash.
* documents the current behaviour of the code as of 9/07
* @todo this test is expected to break when the detection
* of duplicate registrations is implemented.
*/
void createDuplicate()
{
PM mm1 = asset::Media::create ("testfile1.mov", VIDEO);
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.
PM mm2 = asset::Media::create (idi,"testfile2.mov");
ASSERT (mm1->getID() == mm2->getID()); // different object, same hash
AssetManager& aMang = AssetManager::instance();
ASSERT (aMang.getAsset (mm1->getID()) == mm2); // record of mm1 was replaced by mm2
ASSERT (aMang.getAsset (mm2->getID()) == mm2);
ASSERT (aMang.known (mm1->getID()));
ASSERT (aMang.known (mm2->getID()));
ASSERT (mm1->ident.name == "testfile1");
ASSERT (mm2->ident.name == "testfile1");
ASSERT (mm1->getFilename() == "testfile1.mov");
ASSERT (mm2->getFilename() == "testfile2.mov");
showPtr (mm1);
showPtr (mm1X);
showPtr (mm2);
}
void showPtr (PM m)
{
static format fmt("Asset(%s) .... ptr=%d use-count=%d");
cout << fmt % str(m) % &m % m.use_count() << "\n";
}
};
/** Register this test class... */
LAUNCHER (IdentityOfAssets_test, "unit asset");
} // namespace test
} // namespace asset