2010-04-02 21:51:39 +02:00
|
|
|
/*
|
|
|
|
|
CreateAsset(Test) - constructing and registering Assets
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
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.
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
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.
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "include/logging.h"
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
|
|
|
|
#include "proc/assetmanager.hpp"
|
|
|
|
|
#include "proc/asset/media.hpp"
|
|
|
|
|
#include "proc/asset/proc.hpp"
|
|
|
|
|
|
|
|
|
|
#include "proc/asset/asset-diagnostics.hpp"
|
2011-05-20 02:59:29 +02:00
|
|
|
#include "backend/media-access-mock.hpp"
|
2010-04-02 21:51:39 +02:00
|
|
|
|
2011-05-20 02:59:29 +02:00
|
|
|
using lib::test::Use4Test;
|
2010-04-02 21:51:39 +02:00
|
|
|
using util::isnil;
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
namespace proc {
|
|
|
|
|
namespace asset{
|
2010-04-02 21:51:39 +02:00
|
|
|
namespace test {
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
/***********************************************************************
|
|
|
|
|
* @test creating new Assets and registering them with the AssetManager.
|
|
|
|
|
* @see proc_interface::AssetManager#reg
|
|
|
|
|
*/
|
|
|
|
|
class CreateAsset_test : public Test
|
|
|
|
|
{
|
2010-12-10 02:55:40 +01:00
|
|
|
virtual void run(Arg arg)
|
2010-04-02 21:51:39 +02:00
|
|
|
{
|
2011-05-20 02:59:29 +02:00
|
|
|
Use4Test<backend::test::MediaAccessMock> within_this_scope;
|
|
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
createMedia();
|
|
|
|
|
factoryVariants();
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
if (!isnil (arg))
|
|
|
|
|
dumpAssetManager();
|
|
|
|
|
TRACE (asset_mem, "leaving CreateAsset_test::run()");
|
|
|
|
|
}
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
////////////////////////////////////TICKET #589
|
|
|
|
|
typedef P<Media> PM; /////TODO: transition to P<>
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
/** @test Creating and automatically registering Asset instances.
|
|
|
|
|
* Re-Retrieving the newly created objects from AssetManager.
|
2010-12-10 02:55:40 +01:00
|
|
|
* Checking AssetManager access functions, esp. getting
|
2010-04-02 21:51:39 +02:00
|
|
|
* different kinds of Assets by ID, querying with the
|
2010-12-10 02:55:40 +01:00
|
|
|
* wrong Category and querying unknown IDs.
|
2010-04-02 21:51:39 +02:00
|
|
|
*/
|
|
|
|
|
void createMedia()
|
2010-12-10 02:55:40 +01:00
|
|
|
{
|
2010-04-02 21:51:39 +02:00
|
|
|
Category cat(VIDEO,"bin1");
|
2011-05-20 02:59:29 +02:00
|
|
|
Asset::Ident key("test-1", cat, "ichthyo", 5);
|
2010-04-02 21:51:39 +02:00
|
|
|
PM mm1 = asset::Media::create(key,"testfile.mov");
|
2011-05-20 02:59:29 +02:00
|
|
|
PM mm2 = asset::Media::create("test-1.mov", cat);
|
|
|
|
|
PM mm3 = asset::Media::create("test-2.mov", VIDEO);
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
// Assets have been registered and can be retrieved by ID
|
|
|
|
|
AssetManager& aMang = AssetManager::instance();
|
|
|
|
|
PM registered; /////TODO: transition to P<>
|
|
|
|
|
registered = aMang.getAsset (mm1->getID());
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (registered == mm1);
|
2010-04-02 21:51:39 +02:00
|
|
|
registered = aMang.getAsset (mm2->getID());
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (registered == mm2);
|
2010-04-02 21:51:39 +02:00
|
|
|
registered = aMang.getAsset (mm3->getID());
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (registered == mm3);
|
|
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
registered = aMang.getAsset (mm1->getID());
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (registered != mm2);
|
|
|
|
|
/*
|
2010-04-02 21:51:39 +02:00
|
|
|
* TODO: switch back to original version
|
|
|
|
|
* once the transition to P<XX> is done...
|
2010-12-10 02:55:40 +01:00
|
|
|
*
|
|
|
|
|
CHECK (aMang.getAsset (mm1->getID()) == mm1);
|
|
|
|
|
CHECK (aMang.getAsset (mm2->getID()) == mm2);
|
|
|
|
|
CHECK (aMang.getAsset (mm3->getID()) == mm3);
|
|
|
|
|
|
|
|
|
|
CHECK (aMang.getAsset (mm1->getID()) != mm2);
|
|
|
|
|
*/
|
2010-04-02 21:51:39 +02:00
|
|
|
PAsset aa1 = aMang.getAsset (ID<Asset>(mm1->getID())); // note we get an Asset ref
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (aa1 == mm1);
|
2010-04-02 21:51:39 +02:00
|
|
|
PM mX1 = aMang.getAsset (mm1->getID()); // ..and now we get a Media ref
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (mX1 == mm1);
|
|
|
|
|
CHECK (mX1 == aa1);
|
|
|
|
|
|
|
|
|
|
CHECK (aMang.known (mm1->getID()));
|
|
|
|
|
CHECK (aMang.known (mm2->getID()));
|
|
|
|
|
CHECK (aMang.known (mm3->getID()));
|
|
|
|
|
|
|
|
|
|
CHECK ( !aMang.known (mm3->getID(), Category(AUDIO))); // not found within AUDIO-Category
|
|
|
|
|
try
|
|
|
|
|
{ // can't be found if specifying wrong Asset kind....
|
2010-04-02 21:51:39 +02:00
|
|
|
aMang.getAsset (ID<asset::Proc>(mm1->getID()));
|
|
|
|
|
NOTREACHED();
|
|
|
|
|
}
|
2010-12-10 02:55:40 +01:00
|
|
|
catch (lumiera::error::Invalid& xxx) {CHECK (xxx.getID()==LUMIERA_ERROR_WRONG_ASSET_KIND);}
|
|
|
|
|
try
|
|
|
|
|
{ // try accessing nonexistent ID
|
2010-04-02 21:51:39 +02:00
|
|
|
aMang.getAsset (ID<Asset> (1234567890));
|
|
|
|
|
NOTREACHED();
|
|
|
|
|
}
|
2010-12-10 02:55:40 +01:00
|
|
|
catch (lumiera::error::Invalid& xxx) {CHECK (xxx.getID()==LUMIERA_ERROR_UNKNOWN_ASSET_ID);}
|
2010-04-02 21:51:39 +02:00
|
|
|
lumiera_error (); // reset errorflag
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
// checking the Ident-Fields
|
2011-05-20 02:59:29 +02:00
|
|
|
CHECK (mm1->ident.name == "test-1");
|
|
|
|
|
CHECK (mm2->ident.name == "test-1");
|
|
|
|
|
CHECK (mm3->ident.name == "test-2");
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
|
|
|
CHECK (cat == Category (VIDEO,"bin1"));
|
|
|
|
|
CHECK (mm1->ident.category == Category (VIDEO,"bin1"));
|
|
|
|
|
CHECK (mm2->ident.category == Category (VIDEO,"bin1"));
|
|
|
|
|
CHECK (mm3->ident.category == Category (VIDEO ));
|
|
|
|
|
|
|
|
|
|
CHECK (mm1->ident.org == "ichthyo");
|
|
|
|
|
CHECK (mm2->ident.org == "lumi");
|
|
|
|
|
CHECK (mm3->ident.org == "lumi");
|
|
|
|
|
|
|
|
|
|
CHECK (mm1->ident.version == 5);
|
|
|
|
|
CHECK (mm2->ident.version == 1);
|
|
|
|
|
CHECK (mm3->ident.version == 1);
|
|
|
|
|
|
|
|
|
|
CHECK (mm1->getFilename() == "testfile.mov");
|
2011-05-20 02:59:29 +02:00
|
|
|
CHECK (mm2->getFilename() == "test-1.mov");
|
|
|
|
|
CHECK (mm3->getFilename() == "test-2.mov");
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
TRACE (asset_mem, "leaving test method scope");
|
|
|
|
|
}
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
/** @test different variants of calling the MediaFactory,
|
2010-12-10 02:55:40 +01:00
|
|
|
* with focus on the behaviour of the basic Asset
|
|
|
|
|
* creation machinery. Covers filling out Asset's
|
2010-04-02 21:51:39 +02:00
|
|
|
* datafields, amending missing pieces of information.
|
|
|
|
|
*/
|
|
|
|
|
void factoryVariants()
|
2010-12-10 02:55:40 +01:00
|
|
|
{
|
2010-04-02 21:51:39 +02:00
|
|
|
PM candi;
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2011-05-20 02:59:29 +02:00
|
|
|
Asset::Ident key1("test-1", Category(AUDIO), "ichthyo", 5);
|
2010-04-02 21:51:39 +02:00
|
|
|
candi = asset::Media::create(key1);
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK ( checkProperties (candi, key1, ""));
|
|
|
|
|
|
2011-05-20 02:59:29 +02:00
|
|
|
candi = asset::Media::create(key1, string("test-1.wav"));
|
|
|
|
|
CHECK ( checkProperties (candi, key1, "test-1.wav"));
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
Asset::Ident key2("", Category(AUDIO), "ichthyo", 5);
|
2011-05-20 02:59:29 +02:00
|
|
|
candi = asset::Media::create(key2, string("test-2.wav"));
|
|
|
|
|
CHECK ( checkProperties (candi, key2, "test-2.wav"));
|
|
|
|
|
CHECK (key2.name == "test-2"); // name filled in automatically
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2011-05-20 02:59:29 +02:00
|
|
|
candi = asset::Media::create(string("test-3.wav"), Category(AUDIO));
|
|
|
|
|
CHECK ( checkProperties (candi, Asset::Ident("test-3", Category(AUDIO), "lumi", 1)
|
|
|
|
|
, "test-3.wav"));
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2011-05-20 02:59:29 +02:00
|
|
|
candi = asset::Media::create("some/path/test-4.wav", Category(AUDIO));
|
|
|
|
|
CHECK ( checkProperties (candi, Asset::Ident("test-4", Category(AUDIO), "lumi", 1)
|
|
|
|
|
, "some/path/test-4.wav"));
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
candi = asset::Media::create("", Category(AUDIO,"sub/bin"));
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO,"sub/bin"), "lumi", 1)
|
2010-04-02 21:51:39 +02:00
|
|
|
, ""));
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
candi = asset::Media::create("", AUDIO);
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO), "lumi", 1)
|
2010-04-02 21:51:39 +02:00
|
|
|
, ""));
|
|
|
|
|
}
|
2010-12-10 02:55:40 +01:00
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
bool checkProperties (PM object, Asset::Ident identity, string filename)
|
|
|
|
|
{
|
2010-12-10 02:55:40 +01:00
|
|
|
return identity == object->ident
|
2010-04-02 21:51:39 +02:00
|
|
|
&& filename == object->getFilename();
|
|
|
|
|
}
|
|
|
|
|
};
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
|
|
|
|
2010-04-02 21:51:39 +02:00
|
|
|
/** Register this test class... */
|
|
|
|
|
LAUNCHER (CreateAsset_test, "unit asset");
|
2010-12-10 02:55:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
}}} // namespace proc::asset::test
|