LUMIERA.clone/tests/core/steam/mobject/placement-ref-test.cpp

187 lines
6.8 KiB
C++
Raw Normal View History

/*
PlacementRef(Test) - generic reference to a Placement within the Session
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)
2009, Hermann Vosseler <Ichthyostega@web.de>
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.
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
* *****************************************************************/
/** @file placement-ref-test.cpp
** unit test \ref PlacementRef_test
*/
#include "lib/test/run.hpp"
#include "lib/test/test-helper.hpp"
#include "steam/mobject/placement.hpp"
#include "steam/mobject/placement-ref.hpp"
#include "steam/mobject/session/placement-index.hpp"
#include "steam/mobject/session/session-service-mock-index.hpp"
#include "steam/mobject/explicitplacement.hpp"
#include "steam/mobject/test-dummy-mobject.hpp"
#include "lib/time/timevalue.hpp"
#include "lib/format-cout.hpp"
#include "lib/util.hpp"
namespace steam {
namespace mobject {
namespace session {
namespace test {
2009-06-01 04:53:45 +02:00
using namespace mobject::test;
using util::isSameObject;
using LERR_(NOT_IN_SESSION);
using LERR_(BOTTOM_PLACEMENTREF);
using PSub = TestPlacement<TestSubMO21>;
using P_ID = PlacementMO::ID;
/***********************************************************************//**
* @test properties and behaviour of the reference-mechanism for Placements.
2009-06-01 04:53:45 +02:00
* We create an mock placement index and install it to be used
* by all PlacementRef instances while conducting this test.
* Then we add two dummy placements and create some
* references to conduct placement operations
* through these references.
* @see mobject::Placement
* @see mobject::MObject#create
* @see mobject::Placement#addPlacement
* @see mobject::Placement#resolve
*/
class PlacementRef_test : public Test
{
virtual void
run (Arg)
{
PSub testPlacement1(*new TestSubMO21);
PSub testPlacement2(*new TestSubMO21);
lib::time::Time twoSec(0,2);
testPlacement2.chain (twoSec); // define start time of Placement-2 to be at t=2sec
2009-06-01 04:53:45 +02:00
// Prepare an (test)Index backing the PlacementRefs
PPIdx index = SessionServiceMockIndex::install();
2009-06-01 04:53:45 +02:00
PMO& root = index->getRoot();
P_ID id1 = index->insert (testPlacement1, root);
P_ID tmpID = index->insert (testPlacement2, root);
CHECK (2 == index->size());
2009-06-01 04:53:45 +02:00
// References to the "live" placements within our test index
PMO& p1 = index->find(id1);
PMO& p2 = index->find(tmpID);
PlacementMO::Id<TestSubMO21> id2 = p2.recastID<TestSubMO21>();
CHECK (id2);
CHECK (id2 != p1.getID());
2009-06-01 04:53:45 +02:00
// create placement refs
PlacementRef<TestSubMO21> ref1 (p1);
PlacementRef<TestSubMO21> ref2 (id2);
PlacementRef<MObject> refX (ref2);
CHECK (ref1);
CHECK (ref2);
CHECK (refX);
CHECK (ref1 != ref2);
CHECK (ref2 == refX);
2009-06-01 04:53:45 +02:00
// indeed a "reference": resolves to the same memory location
CHECK (isSameObject (p1, *ref1));
CHECK (isSameObject (p2, *ref2));
CHECK (isSameObject (p2, *refX));
cout << *ref1 << endl;
cout << *ref2 << endl;
cout << *refX << endl;
2009-06-01 04:53:45 +02:00
// PlacementRef mimics placement behaviour
ref1->specialAPI();
CHECK (2 == ref1.use_count());
CHECK (2 == ref2.use_count());
2009-06-01 04:53:45 +02:00
ExplicitPlacement exPla = refX.resolve();
CHECK (exPla.time == twoSec); // indeed get back the time we set on p2 above
CHECK (3 == ref2.use_count()); // exPla shares ownership with p2
2009-06-01 04:53:45 +02:00
CHECK (index->contains(ref1)); // ref can stand-in for a placement-ID
CHECK (sizeof(id2) == sizeof(ref2)); // (and is actually implemented based on an ID)
2009-06-01 04:53:45 +02:00
// assignment on placement refs
refX = ref1;
CHECK (ref1 != ref2);
CHECK (ref1 == refX);
CHECK (ref2 != refX);
2009-06-01 04:53:45 +02:00
// re-assignment with a new placement
refX = p2;
CHECK (refX == ref2);
CHECK (isSameObject (*refX, p2));
refX = p1.getID();
CHECK (refX == ref1);
CHECK (refX != ref2);
CHECK (isSameObject (*refX, p1));
LumieraUid luid2 (p2.getID().get());
refX = luid2; // assignment works even based on a plain LUID
ref2 = ref1;
ref1 = refX; // dynamic type check when downcasting
CHECK (isSameObject (p1, *ref2));
CHECK (isSameObject (p2, *ref1));
refX = ref2;
ref2 = ref1;
ref1 = refX;
CHECK (isSameObject (p1, *ref1));
CHECK (isSameObject (p1, *refX));
CHECK (isSameObject (p2, *ref2));
CHECK (ref1 != ref2);
CHECK (ref1 == refX);
CHECK (ref2 != refX);
2009-06-01 04:53:45 +02:00
// resolution is indeed "live", we see changes to the referred placement
CHECK (refX.resolve().time == lib::time::Time::MIN);
p1.chain = p2.chain; // do a change on the placement within index....
CHECK (refX.resolve().time == twoSec); // now we get the time tie we originally set on p2
CHECK (p1.getID() != p2.getID()); // but the instance identities are still unaltered
CHECK (2 == ref1.use_count());
CHECK (3 == ref2.use_count()); // one more because of shared ownership with exPla
2009-06-01 04:53:45 +02:00
// actively removing p2 invalidates the other refs to
index->remove (ref1);
CHECK (!ref1); // checks invalidity without throwing
CHECK (!refX);
VERIFY_ERROR(NOT_IN_SESSION, *ref1 );
// deliberately create an invalid PlacementRef
PlacementRef<TestSubMO21> bottom;
CHECK (!bottom);
VERIFY_ERROR(BOTTOM_PLACEMENTREF, *bottom );
VERIFY_ERROR(BOTTOM_PLACEMENTREF, bottom->specialAPI() );
VERIFY_ERROR(BOTTOM_PLACEMENTREF, bottom.resolve() );
2009-06-01 04:53:45 +02:00
//consistency check; then reset PlacementRef index to default
CHECK (1 == index->size());
CHECK (index->isValid());
index.reset();
}
};
/** Register this test class... */
LAUNCHER (PlacementRef_test, "unit session");
}}}} // namespace steam::mobject::session::test