2010-12-10 01:27:17 +01:00
|
|
|
|
/*
|
|
|
|
|
|
ModelPortRegistry(Test) - verify handling of model ports
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
2010-12-10 01:27:17 +01:00
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
|
2010, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
2010-12-10 01:27:17 +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
|
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 01:27:17 +01: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-17 23:28:49 +01:00
|
|
|
|
|
2010-12-10 01:27:17 +01: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-17 23:28:49 +01:00
|
|
|
|
|
2010-12-10 01:27:17 +01:00
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
|
|
|
|
|
#include "proc/mobject/builder/model-port-registry.hpp"
|
2010-12-10 18:12:56 +01:00
|
|
|
|
#include "proc/asset/timeline.hpp"
|
2010-12-11 23:40:12 +01:00
|
|
|
|
#include "proc/asset/pipe.hpp"
|
2010-12-10 18:12:56 +01:00
|
|
|
|
#include "lib/query.hpp"
|
2010-12-10 01:27:17 +01:00
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace mobject {
|
|
|
|
|
|
namespace builder {
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
2010-12-10 18:12:56 +01:00
|
|
|
|
using util::isSameObject;
|
|
|
|
|
|
using util::isnil;
|
|
|
|
|
|
|
2010-12-10 01:27:17 +01:00
|
|
|
|
using asset::Pipe;
|
|
|
|
|
|
using asset::PPipe;
|
2010-12-10 18:12:56 +01:00
|
|
|
|
using asset::Struct;
|
|
|
|
|
|
using asset::Timeline;
|
|
|
|
|
|
using asset::PTimeline;
|
|
|
|
|
|
using lumiera::Query;
|
|
|
|
|
|
|
|
|
|
|
|
typedef asset::ID<Pipe> PID;
|
|
|
|
|
|
typedef asset::ID<Struct> TID;
|
2010-12-11 23:40:12 +01:00
|
|
|
|
|
|
|
|
|
|
typedef ModelPortRegistry::ModelPortDescriptor const& MPDescriptor;
|
2010-12-10 18:12:56 +01:00
|
|
|
|
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
|
|
|
|
|
namespace { // test environment
|
|
|
|
|
|
|
2010-12-10 18:12:56 +01:00
|
|
|
|
inline PID
|
|
|
|
|
|
getPipe (string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Pipe::query("id("+id+")");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline TID
|
|
|
|
|
|
getTimeline (string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return asset::Struct::retrieve (Query<Timeline> ("id("+id+")"))->getID();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2010-12-10 01:27:17 +01:00
|
|
|
|
struct TestContext
|
|
|
|
|
|
{
|
|
|
|
|
|
ModelPortRegistry registry_;
|
2010-12-11 01:52:02 +01:00
|
|
|
|
ModelPortRegistry* previous_;
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
|
|
|
|
|
/** setup */
|
|
|
|
|
|
TestContext()
|
|
|
|
|
|
: registry_()
|
|
|
|
|
|
, previous_(ModelPortRegistry::setActiveInstance (registry_))
|
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
/** tear-down */
|
|
|
|
|
|
~TestContext()
|
|
|
|
|
|
{
|
2010-12-11 01:52:02 +01:00
|
|
|
|
if (previous_)
|
|
|
|
|
|
ModelPortRegistry::setActiveInstance (*previous_);
|
|
|
|
|
|
else
|
|
|
|
|
|
ModelPortRegistry::shutdown();
|
2010-12-10 01:27:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-11 23:40:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
2010-12-10 01:27:17 +01:00
|
|
|
|
/*********************************************************************************
|
|
|
|
|
|
* @test create a standalone model port registry to verify the behaviour of
|
2010-12-11 23:40:12 +01:00
|
|
|
|
* model ports, accessed through reference handles. This test provides an
|
|
|
|
|
|
* example setup detached from the real usage situation within the builder.
|
2010-12-10 01:27:17 +01:00
|
|
|
|
* The ModelPortRegistry management interface is used to create and track a
|
|
|
|
|
|
* set of model ports, to be made visible by an atomic, transactional switch.
|
|
|
|
|
|
* The access for client code through the ModelPort frontend is then verified.
|
|
|
|
|
|
*
|
|
|
|
|
|
* @see mobject::ModelPort
|
|
|
|
|
|
* @see mobject::builder::ModelPortRegistry
|
|
|
|
|
|
*/
|
|
|
|
|
|
class ModelPortRegistry_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
|
|
|
|
|
{
|
|
|
|
|
|
TestContext ctx;
|
|
|
|
|
|
|
2010-12-10 18:12:56 +01:00
|
|
|
|
fabricating_ModelPorts (ctx.registry_);
|
2010-12-10 01:27:17 +01:00
|
|
|
|
accessing_ModelPorts();
|
2010-12-10 18:12:56 +01:00
|
|
|
|
transactionalSwitch (ctx.registry_);
|
2010-12-10 01:27:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
fabricating_ModelPorts (ModelPortRegistry& registry)
|
|
|
|
|
|
{
|
2010-12-10 18:12:56 +01:00
|
|
|
|
/* == some Assets to play with == */
|
|
|
|
|
|
PID pipeA = getPipe ("pipeA");
|
|
|
|
|
|
PID pipeB = getPipe ("pipeB");
|
|
|
|
|
|
TID someTimeline = getTimeline ("some_test_Timeline");
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
2010-12-10 18:12:56 +01:00
|
|
|
|
// start out with defining some new model ports......
|
|
|
|
|
|
MPDescriptor p1 = registry.definePort (pipeA, someTimeline);
|
|
|
|
|
|
MPDescriptor p2 = registry.definePort (pipeB, someTimeline);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (registry.contains (pipeA));
|
|
|
|
|
|
CHECK (registry.contains (pipeB));
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
|
|
|
|
|
VERIFY_ERROR (DUPLICATE_MODEL_PORT, registry.definePort(pipeB, someTimeline) );
|
2010-12-10 18:12:56 +01:00
|
|
|
|
CHECK (registry.contains (pipeB));
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
2010-12-11 01:52:02 +01:00
|
|
|
|
CHECK (pipeA == p1.id());
|
|
|
|
|
|
CHECK (pipeB == p2.id());
|
|
|
|
|
|
CHECK (someTimeline == p1.holder());
|
|
|
|
|
|
CHECK (someTimeline == p2.holder());
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
|
|
|
|
|
registry.commit();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
accessing_ModelPorts ()
|
|
|
|
|
|
{
|
2010-12-10 18:12:56 +01:00
|
|
|
|
PID pipeA = getPipe ("pipeA");
|
|
|
|
|
|
PID pipeB = getPipe ("pipeB");
|
|
|
|
|
|
PID pipeWC = getPipe ("WCpipe");
|
|
|
|
|
|
|
2010-12-10 01:27:17 +01:00
|
|
|
|
ModelPort mp1(pipeA);
|
|
|
|
|
|
ModelPort mp2(pipeB);
|
|
|
|
|
|
|
2010-12-11 23:40:12 +01:00
|
|
|
|
VERIFY_ERROR (INVALID_MODEL_PORT, ModelPort unbefitting(pipeWC) );
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
2010-12-11 23:40:12 +01:00
|
|
|
|
ModelPort mp1x(pipeA); // can be created multiple times
|
|
|
|
|
|
ModelPort mp2x(mp1x); // can be copied at will
|
|
|
|
|
|
ModelPort mpNull; // can be default constructed (->unconnected)
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (mp1);
|
|
|
|
|
|
CHECK (mp2);
|
|
|
|
|
|
CHECK (mp1x);
|
2010-12-11 23:40:12 +01:00
|
|
|
|
CHECK (!mpNull); // bool check verifies setup and connected state
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
2010-12-11 23:40:12 +01:00
|
|
|
|
CHECK ( ModelPort::exists (pipeA)); // this is the same check, but invoked just with an pipe-ID
|
2010-12-10 01:27:17 +01:00
|
|
|
|
CHECK ( ModelPort::exists (pipeB));
|
|
|
|
|
|
CHECK (!ModelPort::exists (pipeWC));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (mp1 == mp1x);
|
|
|
|
|
|
CHECK (!isSameObject (mp1, mp1x));
|
|
|
|
|
|
CHECK (mp1 != mp2);
|
|
|
|
|
|
CHECK (mp2 != mp1);
|
|
|
|
|
|
CHECK (mp1 != mpNull);
|
|
|
|
|
|
CHECK (mp2 != mpNull);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (mp1.pipe() == pipeA);
|
|
|
|
|
|
CHECK (mp2.pipe() == pipeB);
|
|
|
|
|
|
CHECK (mp1x.pipe() == pipeA);
|
2010-12-11 23:40:12 +01:00
|
|
|
|
VERIFY_ERROR (UNCONNECTED_MODEL_PORT, mpNull.pipe()); // any further operations on an unconnected port will throw
|
|
|
|
|
|
VERIFY_ERROR (UNCONNECTED_MODEL_PORT, mpNull.holder());
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
2010-12-10 18:12:56 +01:00
|
|
|
|
CHECK (mp1.streamType() == pipeA.streamType());
|
2010-12-10 01:27:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
transactionalSwitch (ModelPortRegistry& registry)
|
|
|
|
|
|
{
|
2010-12-10 18:12:56 +01:00
|
|
|
|
PID pipeA = getPipe ("pipeA");
|
|
|
|
|
|
PID pipeB = getPipe ("pipeB");
|
|
|
|
|
|
PID pipeWC = getPipe ("WCpipe");
|
|
|
|
|
|
|
2010-12-10 01:27:17 +01:00
|
|
|
|
CHECK ( ModelPort::exists (pipeB));
|
|
|
|
|
|
CHECK (!ModelPort::exists (pipeWC));
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (ModelPort::exists (pipeA));
|
|
|
|
|
|
CHECK (registry.contains (pipeA));
|
|
|
|
|
|
registry.remove (pipeA);
|
2010-12-11 23:40:12 +01:00
|
|
|
|
CHECK (!registry.contains (pipeA)); // removed from the current (pending) transaction
|
|
|
|
|
|
CHECK ( ModelPort::exists (pipeA)); // but not yet publicly visible
|
2010-12-10 18:12:56 +01:00
|
|
|
|
|
|
|
|
|
|
// now create a new and differing definition of port A
|
|
|
|
|
|
TID anotherTimeline = getTimeline ("another_test_Timeline");
|
|
|
|
|
|
MPDescriptor p1 = registry.definePort (pipeA, anotherTimeline);
|
2010-12-10 01:27:17 +01:00
|
|
|
|
CHECK (registry.contains (pipeA));
|
2010-12-11 01:52:02 +01:00
|
|
|
|
CHECK (anotherTimeline == p1.holder());
|
2010-12-10 18:12:56 +01:00
|
|
|
|
CHECK (ModelPort(pipeA).holder() != anotherTimeline);
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
2010-12-11 23:40:12 +01:00
|
|
|
|
registry.remove (pipeB); // some more wired definitions
|
|
|
|
|
|
registry.definePort (pipeWC, anotherTimeline);
|
2010-12-10 01:27:17 +01:00
|
|
|
|
CHECK (!registry.contains (pipeB));
|
|
|
|
|
|
CHECK ( registry.contains (pipeWC));
|
|
|
|
|
|
CHECK ( ModelPort::exists (pipeB));
|
|
|
|
|
|
CHECK (!ModelPort::exists (pipeWC));
|
2010-12-11 23:40:12 +01:00
|
|
|
|
CHECK ( registry.isRegistered (pipeB)); // this is the same as ModelPort::exists
|
|
|
|
|
|
CHECK (!registry.isRegistered (pipeWC)); //
|
|
|
|
|
|
// Note: pending transaction not yet committed
|
|
|
|
|
|
ModelPort portA(pipeA); // ...... thus the changes aren't reflected to client code
|
2010-12-10 01:27:17 +01:00
|
|
|
|
ModelPort portB(pipeB);
|
2010-12-11 23:40:12 +01:00
|
|
|
|
VERIFY_ERROR (INVALID_MODEL_PORT, ModelPort ineptly(pipeWC));
|
2010-12-10 01:27:17 +01:00
|
|
|
|
CHECK (portA);
|
|
|
|
|
|
CHECK (portB);
|
|
|
|
|
|
CHECK (portA.pipe() == pipeA);
|
|
|
|
|
|
CHECK (portB.pipe() == pipeB);
|
2010-12-10 18:12:56 +01:00
|
|
|
|
CHECK (portA.holder() != anotherTimeline);
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
|
|
|
|
|
registry.commit();
|
2010-12-11 23:40:12 +01:00
|
|
|
|
CHECK ( ModelPort::exists (pipeA)); // now all our changes got publicly visible
|
2010-12-10 01:27:17 +01:00
|
|
|
|
CHECK (!ModelPort::exists (pipeB));
|
|
|
|
|
|
CHECK ( ModelPort::exists (pipeWC));
|
|
|
|
|
|
CHECK ( portA);
|
|
|
|
|
|
CHECK (!portB);
|
2010-12-10 18:12:56 +01:00
|
|
|
|
CHECK (portA.holder() == anotherTimeline);
|
2010-12-10 01:27:17 +01:00
|
|
|
|
CHECK (portA.pipe() == pipeA);
|
2010-12-11 23:40:12 +01:00
|
|
|
|
VERIFY_ERROR (INVALID_MODEL_PORT, portB.pipe());
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
2010-12-11 23:40:12 +01:00
|
|
|
|
ModelPort pwc(pipeWC); // now clients may also use the now officially promoted new port
|
2010-12-10 01:27:17 +01:00
|
|
|
|
CHECK (pwc);
|
|
|
|
|
|
CHECK (pwc.pipe() == pipeWC);
|
2010-12-10 18:12:56 +01:00
|
|
|
|
CHECK (pwc.holder() == anotherTimeline);
|
|
|
|
|
|
|
2010-12-11 23:40:12 +01:00
|
|
|
|
// Next: doing several changes,
|
|
|
|
|
|
// but finally *not* committing them...
|
|
|
|
|
|
CHECK ( registry.contains (pipeA));
|
|
|
|
|
|
CHECK (!registry.contains (pipeB));
|
|
|
|
|
|
CHECK ( registry.contains (pipeWC));
|
2010-12-10 18:12:56 +01:00
|
|
|
|
registry.remove (pipeA);
|
2010-12-11 23:40:12 +01:00
|
|
|
|
registry.clear(); // remove everything from the pending transaction
|
2010-12-10 18:12:56 +01:00
|
|
|
|
CHECK (!registry.contains (pipeA));
|
|
|
|
|
|
CHECK (!registry.contains (pipeB));
|
|
|
|
|
|
CHECK (!registry.contains (pipeWC));
|
|
|
|
|
|
|
2010-12-11 23:40:12 +01:00
|
|
|
|
registry.definePort (pipeB, anotherTimeline);
|
2010-12-10 18:12:56 +01:00
|
|
|
|
CHECK ( registry.contains (pipeB));
|
2010-12-11 23:40:12 +01:00
|
|
|
|
CHECK (!portB); // not committed and thus not visible
|
|
|
|
|
|
CHECK (portA);
|
|
|
|
|
|
CHECK (pwc);
|
|
|
|
|
|
|
|
|
|
|
|
registry.rollback();
|
|
|
|
|
|
CHECK ( registry.contains (pipeA)); // no effect to the officialy visible state
|
|
|
|
|
|
CHECK (!registry.contains (pipeB));
|
2010-12-10 18:12:56 +01:00
|
|
|
|
CHECK ( registry.contains (pipeWC));
|
2010-12-11 23:40:12 +01:00
|
|
|
|
|
|
|
|
|
|
VERIFY_ERROR(INVALID_MODEL_PORT, registry.get(pipeB) );
|
|
|
|
|
|
CHECK (!portB);
|
2010-12-10 01:27:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (ModelPortRegistry_test, "unit session builder");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}} // namespace mobject::builder::test
|