LUMIERA.clone/tests/core/steam/asset/basicpipetest.cpp
Ichthyostega 806db414dd 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

207 lines
7.5 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
BasicPipe(Test) - checking the basic properties of Pipe Assets
Copyright (C)
2008, Hermann Vosseler <Ichthyostega@web.de>
  **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.
* *****************************************************************/
/** @file basicpipetest.cpp
** unit test \ref BasicPipe_test
*/
#include "include/logging.h"
#include "lib/test/run.hpp"
#include "lib/util.hpp"
#include "steam/asset/category.hpp"
#include "steam/asset/pipe.hpp"
#include "steam/assetmanager.hpp"
#include "steam/mobject/session.hpp"
#include "steam/asset/asset-diagnostics.hpp"
#include "lib/query-util.hpp"
#include "common/query.hpp"
using util::contains;
using util::isnil;
using std::string;
namespace steam {
namespace asset {
namespace test {
using mobject::Session;
using lumiera::Query;
using lib::query::normaliseID;
/*******************************************************************//**
* @test basic properties of Pipe (structural) Assets.
* <ul><li>created by referral</li>
* <li>access existing pipe by referral</li>
* <li>create with full properties</li>
* <li>access ProcPatt</li>
* <li>check dependency</li>
* </ul>
*/
class BasicPipe_test : public Test
{
virtual void
run (Arg arg)
{
string pipeID = isnil (arg)? "Black Hole" : arg[1];
string streamID = 2>arg.size()? "teststream" : arg[2] ;
createExplicit (pipeID,streamID);
create_or_ref (pipeID);
create_using_default ();
dependProcPatt (pipeID);
}
void createExplicit (string pID, string sID)
{
string pID_sane{pID};
normaliseID (pID_sane);
CHECK (pID_sane != pID);
PPipe thePipe = asset::Struct::retrieve.newPipe (pID,sID);
CHECK (thePipe);
CHECK (thePipe->getProcPatt());
CHECK (thePipe->getPipeID() == pID_sane);
CHECK (thePipe->getStreamID() == StreamType::ID{sID});
CHECK (thePipe->shortDesc == pID_sane);
Asset::Ident idi = thePipe->ident;
CHECK (idi.org == "lumi");
CHECK (contains (idi.name, thePipe->getPipeID()));
CHECK (contains (idi.name, string{thePipe->getStreamID()}));
Category cat{idi.category};
Category refcat{STRUCT,"pipes"};
CHECK ( cat.hasKind (STRUCT) );
CHECK ( cat.isWithin(refcat) );
}
void create_or_ref(string pID)
{
normaliseID (pID);
PPipe pipe1 = Pipe::query ("pipe("+pID+")");
CHECK (pipe1);
CHECK (pipe1->getPipeID() == pID);
string pID2 = "another-" + pID;
PPipe pipe2 = Pipe::query ("pipe("+pID2+")");
CHECK (pipe2);
CHECK (pipe2 != pipe1);
Category c1 = pipe1->ident.category;
Category c2 = pipe2->ident.category;
CHECK (c1 == c2);
PPipe pipe3 = Pipe::query ("pipe("+pID2+")");
//////////////////////////////////////////////////////////////TODO: that's broken; creating a new one instead to find the existing one, as it should be
CHECK (pipe3 == pipe2);
}
void create_using_default()
{
PPipe pipe1 = Pipe::query (""); // "the default pipe"
PPipe pipe2;
CHECK (pipe1);
CHECK (pipe1 == Session::current->defaults (Query<Pipe>{}));
CHECK (pipe1->ident.category.hasKind(VIDEO));
CHECK (pipe1->getProcPatt());
PProcPatt propa = Session::current->defaults (Query<const ProcPatt>{"pipe(default)"});
CHECK (propa == pipe1->getProcPatt());
// several variants to query for "the default pipe"
pipe2 = Session::current->defaults(Query<Pipe>{});
CHECK (pipe2 == pipe1);
pipe2 = asset::Struct::retrieve (Query<Pipe>{});
CHECK (pipe2 == pipe1);
pipe2 = asset::Struct::retrieve (Query<Pipe>{"pipe(default)"});
CHECK (pipe2 == pipe1);
auto sID = string{pipe1->getStreamID()}; // sort of a "default stream type"
PPipe pipe3 = Pipe::query ("stream("+sID+")");
CHECK (pipe3);
CHECK (pipe3->getStreamID() == StreamType::ID{sID});
CHECK (pipe3->getProcPatt() == Session::current->defaults (Query<const ProcPatt>{"stream("+sID+")"}));
}
void dependProcPatt(string pID)
{
typedef lib::P<Pipe> PPipe; /////TODO: transition to P<>
typedef lib::P<const ProcPatt> PProcPatt;
PPipe thePipe = Pipe::query ("pipe("+pID+")");
CHECK (thePipe);
PProcPatt thePatt = thePipe->getProcPatt();
CHECK (thePatt);
CHECK (dependencyCheck (thePipe, thePatt));
PProcPatt pattern2 = thePatt->newCopy("another");
CHECK (thePatt != pattern2);
CHECK (!dependencyCheck (thePipe, pattern2));
TODO ("add something to the new pattern, e.g. an effect");
// now querying for a pipe using this pattern (created on-the-fly)
// note: because the pattern is new, this new pipe will be used as
// default pipe for this pattern automatically
PPipe pipe2x = Pipe::query ("pattern(another)");
CHECK (pattern2 == pipe2x->getProcPatt());
CHECK (pipe2x == Session::current->defaults (Query<Pipe>{"pattern(another)"}));
thePipe->switchProcPatt(pattern2);
CHECK ( dependencyCheck (thePipe, pattern2));
CHECK (!dependencyCheck (thePipe, thePatt));
AssetManager& aMang = AssetManager::instance();
CHECK ( aMang.known (thePipe->getID()));
CHECK ( aMang.known (thePatt->getID()));
CHECK ( aMang.known (pattern2->getID()));
aMang.remove (pattern2->getID());
CHECK ( aMang.known (thePatt->getID()));
CHECK (!aMang.known (pattern2->getID()));
CHECK (!aMang.known (thePipe->getID())); // has been unlinked too, because dependent on pattern2
CHECK (thePipe);
PProcPatt pattern3 = thePipe->getProcPatt(); /////TODO: transition to P<>
CHECK (thePipe->getProcPatt());
CHECK ( pattern3 == pattern2); // but is still valid, as long as the ref is alive....
PPipe pipe3x = Pipe::query ("pattern(another)");
pattern3 = pipe3x->getProcPatt(); /////TODO: transition to P<>
CHECK (pattern3 != pattern2); // because pattern2 is already unlinked...
CHECK (pipe3x == Session::current->defaults (Query<Pipe>{"pattern(another)"}));
CHECK (pipe3x != pipe2x); // ..we got a new default pipe for "pattern(another)" too!
TRACE (asset_mem, "leaving BasicPipe_test::dependProcPatt()");
// expect now pipe2x and pattern2 to be destroyed...
}
};
/** Register this test class... */
LAUNCHER (BasicPipe_test, "unit asset");
}}} // namespace steam::asset::test