LUMIERA.clone/tests/core/steam/mobject/session/output-mapping-test.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

179 lines
5.2 KiB
C++
Raw 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.

/*
OutputMapping(Test) - verify generic output designation mapping
Copyright (C)
2010, 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 output-mapping-test.cpp
** unit test \ref OutputMapping_test
*/
#include "lib/test/run.hpp"
#include "lib/test/test-helper.hpp"
#include "steam/mobject/output-mapping.hpp"
#include "steam/asset/pipe.hpp"
#include "lib/format-string.hpp"
#include "lib/util.hpp"
#include <string>
using util::_Fmt;
using util::isnil;
using std::string;
namespace steam {
namespace mobject {
namespace test {
using asset::Pipe;
using asset::PPipe;
using mobject::OutputMapping;
typedef asset::ID<Pipe> PID;
/*****************************************************************************//**
* @test create a synthetic / example mapping to verify generic mapping behaviour.
* We're creating a custom mapping type here, for this test only: The
* struct DummyDef provides a "definition context" for this custom mapping
* - there is a function to retrieve the actual target object
* for any target pipe stored in the mapping. In this case,
* we just extract the name-ID string from the pipe as result
* - as an additional sideeffect, this DummyDef::output functor
* also defines the Target type of this custom mapping to be std::string
* - DummyDef::buildQuery provides a template query, to be issued whenever
* a yet nonexistent mapping is requested. In this special case here
* we query for a pipe with the name "master_XXX", where XXX denotes
* the stream-type of the source pipe to be mapped.
*
* @see mobject::OutputDesignation
* @see mobject::session::Binding
*/
class OutputMapping_test : public Test
{
struct DummyDef
{
string
output (PID target)
{
return Pipe::lookup(target)->ident.name;
}
Query<Pipe>
buildQuery (PID sourcePipeID, uint seqNr =0)
{
PPipe srcP = Pipe::lookup (sourcePipeID);
_Fmt queryPattern{"id(master_%1%), stream(%1%), ord(%2%)"};
return Query<Pipe> (queryPattern % srcP->getStreamID().getSym() % seqNr);
}
};
typedef OutputMapping<DummyDef> Mapping;
virtual void
run (Arg)
{
map_and_retrieve();
instance_copy();
default_mapping();
}
void
map_and_retrieve()
{
Mapping map;
CHECK (isnil (map));
PPipe p1 = Pipe::query("id(hairy)");
PPipe p2 = Pipe::query("id(furry)");
PPipe pX = Pipe::query("id(curly)");
map[p1] = p2;
CHECK (!isnil (map));
CHECK (1 == map.size());
CHECK (map[p1] == "furry");
CHECK (map[p1].isValid());
CHECK (map[p1]);
CHECK (!map.contains (pX));
CHECK (!map.contains (p2));
// create an unconnected mapping
map[pX].disconnect();
CHECK (map.contains (pX));
CHECK (!map[pX].isValid());
CHECK (!map[pX]);
}
void
instance_copy()
{
Mapping m1;
PPipe p1 = Pipe::query("id(hairy)");
PPipe p2 = Pipe::query("id(furry)");
PPipe pi = Pipe::query("id(nappy)");
m1[pi] = p1;
Mapping m2(m1);
CHECK (!isnil (m2));
CHECK (1 == m2.size());
CHECK (m1[pi] == "hairy");
CHECK (m2[pi] == "hairy");
m1[pi] = p2;
CHECK (m1[pi] == "furry");
CHECK (m2[pi] == "hairy");
m2 = m1;
CHECK (m1[pi] == "furry");
CHECK (m2[pi] == "furry");
m1.clear();
CHECK (isnil(m1));
CHECK (!isnil(m2));
CHECK (m2[pi] == "furry");
CHECK (!m1.contains (pi));
}
void
default_mapping()
{
Mapping map;
CHECK (isnil (map));
PPipe p1 = Pipe::query("stream(hairy)");
PPipe p2 = Pipe::query("stream(furry)");
CHECK (map[p1] == "master_hairy");
CHECK (map[p2] == "master_furry");
// create new mapping to an explicitly queried target
Query<Pipe> some_pipe ("pipe(super_curly)");
CHECK (map[some_pipe] == "super_curly");
// create a new mapping to the 2nd master for "furry" data
Query<Pipe> special_bus ("stream(furry), ord(2)");
CHECK (map[special_bus] == "master_furry.2");
}
};
/** Register this test class... */
LAUNCHER (OutputMapping_test, "unit session");
}}} // namespace steam::mobject::test