2010-12-10 01:27:17 +01:00
|
|
|
|
/*
|
|
|
|
|
|
ModelPortRegistry(Test) - verify handling of model ports
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2010, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** 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. See the file COPYING for further details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file model-port-registry-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref ModelPortRegistry_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2023-06-07 04:03:00 +02:00
|
|
|
|
#include "steam/fixture/model-port-registry.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/asset/timeline.hpp"
|
|
|
|
|
|
#include "steam/asset/pipe.hpp"
|
2012-12-01 08:44:07 +01:00
|
|
|
|
#include "common/query.hpp"
|
2010-12-10 01:27:17 +01:00
|
|
|
|
#include "lib/util.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
namespace steam {
|
2023-06-07 04:03:00 +02:00
|
|
|
|
namespace fixture {
|
2010-12-10 01:27:17 +01:00
|
|
|
|
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;
|
2023-06-07 04:03:00 +02:00
|
|
|
|
using mobject::ModelPort;
|
2012-12-01 08:44:07 +01:00
|
|
|
|
using lumiera::Query;
|
2010-12-10 18:12:56 +01:00
|
|
|
|
|
2023-06-07 04:03:00 +02:00
|
|
|
|
using PID = asset::ID<Pipe>;
|
|
|
|
|
|
using TID = asset::ID<Struct>;
|
2010-12-11 23:40:12 +01:00
|
|
|
|
|
2023-06-07 04:03:00 +02:00
|
|
|
|
using MPDescriptor = ModelPortRegistry::ModelPortDescriptor const&;
|
|
|
|
|
|
|
|
|
|
|
|
using mobject::LUMIERA_ERROR_INVALID_MODEL_PORT;
|
|
|
|
|
|
using mobject::LUMIERA_ERROR_UNCONNECTED_MODEL_PORT;
|
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)
|
|
|
|
|
|
{
|
2012-12-26 02:20:11 +01:00
|
|
|
|
return Pipe::query ("id("+id+")");
|
2010-12-10 18:12:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02: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);
|
2015-08-16 00:16:30 +02:00
|
|
|
|
CHECK (mp2x);
|
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();
|
2012-02-13 00:37:57 +01:00
|
|
|
|
CHECK ( registry.contains (pipeA)); // no effect to the officially visible state
|
2010-12-11 23:40:12 +01:00
|
|
|
|
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... */
|
2023-06-07 04:03:00 +02:00
|
|
|
|
LAUNCHER (ModelPortRegistry_test, "unit fixture session builder");
|
2010-12-10 01:27:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-07 04:03:00 +02:00
|
|
|
|
}}} // namespace steam::fixture::test
|