2007-09-03 02:33:47 +02:00
/*
2024-12-06 23:43:18 +01:00
NodeBase ( Test ) - unit test to cover the render node base elements
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 )
2009 , 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
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2007-09-03 02:33:47 +02:00
2024-12-06 23:43:18 +01:00
/** @file node-base-test.cpp
* * Unit test \ ref NodeBase_test covers elementary components of render nodes .
2016-11-03 18:20:10 +01:00
*/
2007-09-03 02:33:47 +02:00
2008-12-18 04:47:41 +01:00
# include "lib/test/run.hpp"
2024-12-07 18:15:44 +01:00
//#include "lib/test/test-helper.hpp"
2024-12-14 03:50:10 +01:00
# include "lib/meta/function.hpp"
2024-12-06 23:43:18 +01:00
# include "steam/engine/proc-node.hpp"
# include "steam/engine/turnout.hpp"
2024-05-12 17:27:07 +02:00
# include "steam/engine/turnout-system.hpp"
2024-12-15 23:25:01 +01:00
# include "steam/engine/feed-manifold.hpp"
2024-12-16 02:26:26 +01:00
# include "steam/engine/diagnostic-buffer-provider.hpp"
# include "steam/engine/buffhandle-attach.hpp"
2016-01-07 03:58:29 +01:00
//#include "lib/format-cout.hpp"
2024-12-17 23:32:11 +01:00
# include "lib/test/diagnostic-output.hpp" /////////////////////TODO
2024-12-18 03:54:31 +01:00
# include "lib/util.hpp"
2007-09-03 02:33:47 +02:00
2009-08-31 01:32:53 +02:00
//using std::string;
2024-12-17 23:32:11 +01:00
using std : : tuple ; /////////////TODO
using std : : array ;
2024-12-18 03:54:31 +01:00
using util : : isSameAdr ;
2007-09-03 02:33:47 +02:00
2018-11-15 23:55:13 +01:00
namespace steam {
2009-08-31 00:49:08 +02:00
namespace engine {
namespace test {
2009-08-31 01:32:53 +02:00
namespace { // Test fixture
/**
*/
}
2009-08-31 00:49:08 +02:00
2013-10-24 23:06:36 +02:00
/***************************************************************/ /**
2009-08-31 00:49:08 +02:00
* @ test basic render node properties and behaviour .
*/
2024-12-06 23:43:18 +01:00
class NodeBase_test : public Test
2007-09-03 02:33:47 +02:00
{
2024-12-07 18:15:44 +01:00
virtual void
run ( Arg )
2009-08-31 00:49:08 +02:00
{
2024-12-07 18:15:44 +01:00
seedRand ( ) ;
verify_TurnoutSystem ( ) ;
2024-12-15 23:25:01 +01:00
verify_FeedManifold ( ) ;
2009-08-31 00:49:08 +02:00
UNIMPLEMENTED ( " build a simple render node and then activate it " ) ;
2024-12-07 18:15:44 +01:00
}
/** @test the TurnoutSystem as transient coordinator for node invocation
*/
void
verify_TurnoutSystem ( )
{
Time nomTime { rani ( 10'000 ) , 0 } ; // drive test with a random »nominal Time« <10s with ms granularity
TurnoutSystem invoker { nomTime } ; // a time spec is mandatory, all further parameters are optional
}
2024-12-15 23:25:01 +01:00
/** @test the FeedManifold as adapter between Engine and processing library
*/
void
verify_FeedManifold ( )
{
// some random numbers to test...
long r1 = rani ( 100 ) ;
2024-12-18 03:54:31 +01:00
// Prepare setup to build a suitable FeedManifold
2024-12-15 23:25:01 +01:00
using Buffer = long ;
2024-12-17 23:32:11 +01:00
/////////////////////////////////////////////////////////////////////////////////TODO
using T1 = tuple < int , double > ;
using T2 = array < int * , 3 > ;
using T3 = int ;
using T4 = int * ;
2024-12-18 03:54:31 +01:00
using T5 = lib : : HeteroData < int * , long , double * > ;
2024-12-17 23:32:11 +01:00
/////////////////////////////////////////////////////////////////////////////////TODO
2024-12-15 23:25:01 +01:00
auto fun_singleOut = [ & ] ( Buffer * buff ) { * buff = r1 ; } ;
2024-12-18 03:54:31 +01:00
// Example-1: a FeedManifold to adapt a simple generator function
2024-12-15 23:25:01 +01:00
using M1 = FeedManifold < decltype ( fun_singleOut ) > ;
CHECK ( not M1 : : hasInput ( ) ) ;
CHECK ( not M1 : : hasParam ( ) ) ;
2024-12-18 03:54:31 +01:00
// instantiate...
2024-12-17 23:32:11 +01:00
M1 m1 { fun_singleOut } ;
2024-12-16 02:26:26 +01:00
CHECK ( 1 = = m1 . outBuff . array ( ) . size ( ) ) ;
CHECK ( nullptr = = m1 . outArgs ) ;
// CHECK (m1.inArgs ); // does not compile because storage field is not provided
// CHECK (m1.param );
BufferProvider & provider = DiagnosticBufferProvider : : build ( ) ;
2024-12-18 17:04:30 +01:00
BuffHandle buff = provider . lockBufferFor < Buffer > ( - 55 ) ;
2024-12-16 02:26:26 +01:00
CHECK ( buff . isValid ( ) ) ;
CHECK ( buff . accessAs < long > ( ) = = - 55 ) ;
2024-12-18 03:54:31 +01:00
m1 . outBuff . createAt ( 0 , buff ) ; // plant a copy of the BuffHandle into the output slot
2024-12-16 02:26:26 +01:00
CHECK ( m1 . outBuff [ 0 ] . isValid ( ) ) ;
CHECK ( m1 . outBuff [ 0 ] . accessAs < long > ( ) = = - 55 ) ;
2024-12-17 23:32:11 +01:00
2024-12-18 03:54:31 +01:00
m1 . connect ( ) ; // instruct the manifold to connect buffers to arguments
CHECK ( isSameAdr ( m1 . outArgs , * buff ) ) ;
CHECK ( * m1 . outArgs = = - 55 ) ;
m1 . invoke ( ) ; // invoke the adapted processing function (fun_singleOut)
CHECK ( buff . accessAs < long > ( ) = = r1 ) ; // result: the random number r1 was written into the buffer.
// Example-2: adapt a function to process input -> output buffer
2024-12-18 17:04:30 +01:00
auto fun_singleInOut = [ ] ( Buffer * in , Buffer * out ) { * out = * in + 1 ; } ;
2024-12-18 03:54:31 +01:00
using M2 = FeedManifold < decltype ( fun_singleInOut ) > ;
2024-12-18 17:04:30 +01:00
CHECK ( M2 : : hasInput ( ) ) ;
2024-12-18 03:54:31 +01:00
CHECK ( not M2 : : hasParam ( ) ) ;
CHECK ( 1 = = M2 : : FAN_I ) ;
CHECK ( 1 = = M2 : : FAN_O ) ;
// instantiate...
M2 m2 { fun_singleInOut } ;
2024-12-18 17:04:30 +01:00
CHECK ( 1 = = m2 . inBuff . array ( ) . size ( ) ) ;
2024-12-18 03:54:31 +01:00
CHECK ( 1 = = m2 . outBuff . array ( ) . size ( ) ) ;
2024-12-18 17:04:30 +01:00
CHECK ( nullptr = = m2 . inArgs ) ;
2024-12-18 03:54:31 +01:00
CHECK ( nullptr = = m2 . outArgs ) ;
2024-12-18 17:04:30 +01:00
// use the result of the preceding Example-1 as input
// and get a new buffer to capture the output
BuffHandle buffOut = provider . lockBufferFor < Buffer > ( - 99 ) ;
CHECK ( buff . accessAs < long > ( ) = = r1 ) ;
SHOW_EXPR ( buff . accessAs < long > ( ) )
SHOW_EXPR ( buffOut . accessAs < long > ( ) )
CHECK ( buffOut . accessAs < long > ( ) = = - 55 ) ; ///////////////////////////////////////OOO should be -99 --> aliasing of buffer meta records due to bug with hash generation
// configure the Manifold-2 with this input and output buffer
m2 . inBuff . createAt ( 0 , buff ) ;
m2 . outBuff . createAt ( 0 , buffOut ) ;
CHECK ( m2 . inBuff [ 0 ] . isValid ( ) ) ;
CHECK ( m2 . inBuff [ 0 ] . accessAs < long > ( ) = = r1 ) ;
CHECK ( m2 . outBuff [ 0 ] . isValid ( ) ) ;
CHECK ( m2 . outBuff [ 0 ] . accessAs < long > ( ) = = - 55 ) ; ////////////////////////////////OOO should be -99
// connect arguments to buffers
m2 . connect ( ) ;
CHECK ( isSameAdr ( m2 . inArgs , * buff ) ) ;
CHECK ( isSameAdr ( m2 . outArgs , * buffOut ) ) ;
CHECK ( * m2 . outArgs = = - 55 ) ; ////////////////////////////////OOO should be -99
m2 . invoke ( ) ;
SHOW_EXPR ( r1 )
SHOW_EXPR ( * m1 . outArgs )
SHOW_EXPR ( * m2 . outArgs )
CHECK ( buffOut . accessAs < long > ( ) = = r1 + 1 ) ;
2024-12-15 23:25:01 +01:00
}
2009-08-31 00:49:08 +02:00
} ;
/** Register this test class... */
2024-12-06 23:43:18 +01:00
LAUNCHER ( NodeBase_test , " unit node " ) ;
2009-08-31 00:49:08 +02:00
2018-11-15 23:55:13 +01:00
} } } // namespace steam::engine::test