2008-02-20 04:05:37 +01:00
|
|
|
/*
|
|
|
|
|
DefsManager(Test) - checking basic behaviour of the defaults manager
|
|
|
|
|
|
2008-03-10 08:38:59 +01:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2008-02-20 04:05:37 +01:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
2008-04-12 04:55:18 +02:00
|
|
|
#include "pre_a.hpp"
|
|
|
|
|
|
2008-02-20 04:05:37 +01:00
|
|
|
#include "common/test/run.hpp"
|
|
|
|
|
#include "common/util.hpp"
|
|
|
|
|
|
|
|
|
|
#include "proc/asset.hpp"
|
|
|
|
|
#include "proc/asset/pipe.hpp"
|
|
|
|
|
#include "common/query.hpp"
|
2008-04-08 04:39:07 +02:00
|
|
|
#include "common/configrules.hpp" ///////TODO just temp
|
2008-02-20 04:05:37 +01:00
|
|
|
#include "proc/assetmanager.hpp"
|
|
|
|
|
#include "proc/mobject/session.hpp"
|
|
|
|
|
|
|
|
|
|
#include <boost/format.hpp>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
|
|
using boost::format;
|
|
|
|
|
using util::isnil;
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace asset
|
|
|
|
|
{
|
|
|
|
|
namespace test
|
|
|
|
|
{
|
|
|
|
|
using mobject::Session;
|
2008-03-10 08:38:59 +01:00
|
|
|
using lumiera::Query;
|
|
|
|
|
using lumiera::query::normalizeID;
|
2008-02-20 04:05:37 +01:00
|
|
|
|
2008-04-08 04:39:07 +02:00
|
|
|
using lumiera::ConfigRules; ////TODO just temp
|
|
|
|
|
using lumiera::query::QueryHandler; ////TODO just temp
|
|
|
|
|
|
2008-02-20 04:05:37 +01:00
|
|
|
|
2008-02-29 04:27:24 +01:00
|
|
|
/** shortcut: run just a query
|
|
|
|
|
* without creating new instances
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
find (Query<Pipe>& q)
|
|
|
|
|
{
|
|
|
|
|
return Session::current->defaults.search (q);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-20 04:05:37 +01:00
|
|
|
|
|
|
|
|
/***********************************************************************
|
2008-04-08 04:39:07 +02:00
|
|
|
* @test basic behaviour of the defaults manager ("the big picture")
|
2008-02-20 04:05:37 +01:00
|
|
|
* <ol><li>retrieving a "default" object repeatedly</li>
|
|
|
|
|
* <li>retrieving a more constrained "default" object</li>
|
|
|
|
|
* <li>failure registers a new "default"</li>
|
|
|
|
|
* </ol>
|
|
|
|
|
* Using pipe assets as an example. The defaults manager shouldn't
|
|
|
|
|
* interfere with memory management (it holds weak refs).
|
|
|
|
|
*/
|
|
|
|
|
class DefsManager_test : public Test
|
|
|
|
|
{
|
|
|
|
|
virtual void run(Arg arg)
|
|
|
|
|
{
|
|
|
|
|
string pipeID = isnil(arg)? "Black Hole" : arg[1];
|
|
|
|
|
string streamID = 2>arg.size()? "teststream" : arg[2] ;
|
|
|
|
|
|
|
|
|
|
normalizeID (pipeID);
|
|
|
|
|
normalizeID (streamID);
|
|
|
|
|
|
|
|
|
|
retrieveSimpleDefault (pipeID);
|
|
|
|
|
retrieveConstrainedDefault (pipeID, streamID);
|
|
|
|
|
pipeID = failureCreatesNewDefault();
|
|
|
|
|
verifyRemoval (pipeID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-29 04:27:24 +01:00
|
|
|
void retrieveSimpleDefault (string pID)
|
2008-02-20 04:05:37 +01:00
|
|
|
{
|
|
|
|
|
PPipe pipe1 = Pipe::query (""); // "the default pipe"
|
|
|
|
|
PPipe pipe2;
|
|
|
|
|
|
|
|
|
|
// several variants to query for "the default pipe"
|
|
|
|
|
pipe2 = Pipe::query ("");
|
|
|
|
|
ASSERT (pipe2 == pipe1);
|
|
|
|
|
pipe2 = Pipe::query ("default(X)");
|
|
|
|
|
ASSERT (pipe2 == pipe1);
|
|
|
|
|
pipe2 = Session::current->defaults(Query<Pipe> ());
|
|
|
|
|
ASSERT (pipe2 == pipe1);
|
|
|
|
|
pipe2 = asset::Struct::create (Query<Pipe> ());
|
|
|
|
|
ASSERT (pipe2 == pipe1);
|
2008-04-08 04:39:07 +02:00
|
|
|
pipe2 = asset::Struct::create (Query<Pipe> ("default(P)"));
|
2008-02-20 04:05:37 +01:00
|
|
|
ASSERT (pipe2 == pipe1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-29 04:27:24 +01:00
|
|
|
void retrieveConstrainedDefault (string pID, string sID)
|
2008-02-20 04:05:37 +01:00
|
|
|
{
|
|
|
|
|
PPipe pipe1 = Pipe::query (""); // "the default pipe"
|
|
|
|
|
ASSERT (sID != pipe1->getProcPatt()->queryStreamID(),
|
|
|
|
|
"stream-ID \"%s\" not suitable for test, because "
|
|
|
|
|
"the default-pipe \"%s\" happens to have the same "
|
|
|
|
|
"stream-ID. We need it to be different",
|
|
|
|
|
sID.c_str(), pID.c_str()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
string query_for_sID ("stream("+sID+")");
|
|
|
|
|
PPipe pipe2 = Pipe::query (query_for_sID);
|
|
|
|
|
ASSERT (sID == pipe2->getProcPatt()->queryStreamID());
|
|
|
|
|
ASSERT (pipe2 != pipe1);
|
|
|
|
|
ASSERT (pipe2 == Pipe::query (query_for_sID)); // reproducible
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string failureCreatesNewDefault ()
|
|
|
|
|
{
|
|
|
|
|
PPipe pipe1 = Session::current->defaults(Query<Pipe> ()); // "the default pipe"
|
|
|
|
|
|
|
|
|
|
string new_pID (str (format ("dummy_%s_%i")
|
|
|
|
|
% pipe1->getPipeID()
|
|
|
|
|
% std::rand()
|
|
|
|
|
)); // make random new pipeID
|
2008-02-29 04:27:24 +01:00
|
|
|
Query<Pipe> query_for_new ("pipe("+new_pID+")");
|
2008-02-20 04:05:37 +01:00
|
|
|
|
2008-02-29 04:27:24 +01:00
|
|
|
ASSERT (!find (query_for_new)); // check it doesn't exist
|
|
|
|
|
PPipe pipe2 = Session::current->defaults (query_for_new); // triggers creation
|
|
|
|
|
ASSERT ( find (query_for_new)); // check it exists now
|
2008-02-20 04:05:37 +01:00
|
|
|
|
|
|
|
|
ASSERT (pipe1 != pipe2);
|
2008-02-29 04:27:24 +01:00
|
|
|
ASSERT (pipe2 == Session::current->defaults (query_for_new));
|
2008-02-20 04:05:37 +01:00
|
|
|
return new_pID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-04-08 04:39:07 +02:00
|
|
|
/** verify the defaults manager holds only weak refs,
|
|
|
|
|
* so if an object goes out of scope, any defaults entries
|
|
|
|
|
* are purged silently
|
|
|
|
|
*/
|
2008-02-29 04:27:24 +01:00
|
|
|
void verifyRemoval (string pID)
|
2008-02-20 04:05:37 +01:00
|
|
|
{
|
2008-02-29 04:27:24 +01:00
|
|
|
Query<Pipe> query_for_pID ("pipe("+pID+")");
|
2008-02-20 04:05:37 +01:00
|
|
|
size_t hash;
|
|
|
|
|
{
|
2008-02-29 04:27:24 +01:00
|
|
|
PPipe pipe1 = Session::current->defaults (query_for_pID);
|
2008-04-08 04:39:07 +02:00
|
|
|
//
|
|
|
|
|
// this is fine but doesn't work as long as there is another entry in the mock table...
|
|
|
|
|
// ...for now we use hack to overwrite the reference in the mock table
|
|
|
|
|
//
|
|
|
|
|
ASSERT (3 == pipe1.use_count()); // that's the problem; it should be 2
|
|
|
|
|
|
|
|
|
|
QueryHandler<Pipe>& typeHandler = ConfigRules::instance();
|
|
|
|
|
PPipe pipe2 = asset::Struct::create (pID, "quatsch");
|
|
|
|
|
|
|
|
|
|
typeHandler.resolve (pipe2, query_for_pID); // in the mock impl this has the side effect
|
|
|
|
|
ASSERT (pipe2); // of replacing the mock entry
|
|
|
|
|
//////////////////////////////////////////// so from now on the test works as intended....
|
|
|
|
|
|
|
|
|
|
ASSERT (2 == pipe1.use_count());
|
2008-02-20 04:05:37 +01:00
|
|
|
hash = pipe1->getID();
|
|
|
|
|
}
|
2008-04-01 06:57:00 +02:00
|
|
|
// now AssetManager should hold the only ref
|
2008-02-20 04:05:37 +01:00
|
|
|
ID<Asset> assetID (hash);
|
|
|
|
|
|
|
|
|
|
AssetManager& aMang (AssetManager::instance());
|
|
|
|
|
ASSERT ( aMang.known (assetID));
|
|
|
|
|
aMang.remove (assetID);
|
|
|
|
|
ASSERT (!aMang.known (assetID));
|
|
|
|
|
|
2008-02-29 04:27:24 +01:00
|
|
|
|
|
|
|
|
ASSERT (!find(query_for_pID)); // bare default-query should fail...
|
|
|
|
|
PPipe pipe2 = Session::current->defaults (query_for_pID); // triggers re-creation
|
|
|
|
|
ASSERT ( find(query_for_pID)); // should succeed again
|
2008-02-20 04:05:37 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
LAUNCHER (DefsManager_test, "function session");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
|
|
|
|
|
} // namespace asset
|