2008-02-14 04:12:30 +01:00
/*
BasicPipe ( Test ) - checking the basic properties of Pipe Assets
2010-12-17 23:28:49 +01:00
2008-03-10 08:38:59 +01:00
Copyright ( C ) Lumiera . org
2008 , Hermann Vosseler < Ichthyostega @ web . de >
2010-12-17 23:28:49 +01:00
2008-02-14 04:12:30 +01:00
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License as
2010-12-17 23:28:49 +01:00
published by the Free Software Foundation ; either version 2 of
the License , or ( at your option ) any later version .
2008-02-14 04:12:30 +01:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2010-12-17 23:28:49 +01:00
2008-02-14 04:12:30 +01:00
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
2010-12-17 23:28:49 +01:00
2008-02-14 04:12:30 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-01-25 00:24:42 +01:00
# include "include/logging.h"
2008-12-18 04:47:41 +01:00
# include "lib/test/run.hpp"
# include "lib/util.hpp"
2008-02-14 04:12:30 +01:00
# include "proc/asset/category.hpp"
# include "proc/asset/pipe.hpp"
# include "proc/assetmanager.hpp"
# include "proc/mobject/session.hpp"
2009-07-19 05:47:36 +02:00
# include "proc/asset/asset-diagnostics.hpp"
2012-12-03 00:18:18 +01:00
# include "lib/query-util.hpp"
2012-12-01 08:44:07 +01:00
# include "common/query.hpp"
2008-02-14 04:12:30 +01:00
# include <boost/format.hpp>
# include <iostream>
using boost : : format ;
using util : : contains ;
using util : : isnil ;
using std : : string ;
using std : : cout ;
2011-12-02 17:50:44 +01:00
namespace proc {
2010-12-10 17:39:39 +01:00
namespace asset {
namespace test {
2011-12-02 17:50:44 +01:00
using mobject : : Session ;
2012-12-01 08:44:07 +01:00
using lumiera : : Query ;
2012-12-03 00:18:18 +01:00
using lib : : query : : normaliseID ;
2011-12-02 17:50:44 +01:00
/***********************************************************************
* @ 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 ) ;
}
2011-12-02 16:10:03 +01:00
2011-12-02 17:50:44 +01:00
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 , 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 ) ;
2012-12-26 02:20:11 +01:00
PPipe pipe1 = Pipe : : query ( " pipe( " + pID + " ) " ) ;
2011-12-02 17:50:44 +01:00
CHECK ( pipe1 ) ;
CHECK ( pipe1 - > getPipeID ( ) = = pID ) ;
string pID2 = " another- " + pID ;
2012-12-26 02:20:11 +01:00
PPipe pipe2 = Pipe : : query ( " pipe( " + pID2 + " ) " ) ;
2011-12-02 17:50:44 +01:00
CHECK ( pipe2 ) ;
CHECK ( pipe2 ! = pipe1 ) ;
Category c1 = pipe1 - > ident . category ;
Category c2 = pipe2 - > ident . category ;
CHECK ( c1 = = c2 ) ;
2012-12-26 02:20:11 +01:00
PPipe pipe3 = Pipe : : query ( " pipe( " + pID2 + " ) " ) ;
2009-05-31 05:02:03 +02:00
//////////////////////////////////////////////////////////////TODO: that's broken; creating a new one instead to find the existing one, as it should be
2011-12-02 17:50:44 +01:00
CHECK ( pipe3 = = pipe2 ) ;
}
void create_using_default ( )
{
2012-12-26 02:20:11 +01:00
PPipe pipe1 = Pipe : : query ( " " ) ; // "the default pipe"
2011-12-02 17:50:44 +01:00
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 ) ;
string sID = pipe1 - > getStreamID ( ) ; // sort of a "default stream type"
2012-12-26 02:20:11 +01:00
PPipe pipe3 = Pipe : : query ( " stream( " + sID + " ) " ) ;
2011-12-02 17:50:44 +01:00
CHECK ( pipe3 ) ;
CHECK ( pipe3 - > getStreamID ( ) = = StreamType : : ID ( sID ) ) ;
CHECK ( pipe3 - > getProcPatt ( ) = = Session : : current - > defaults ( Query < const ProcPatt > ( " stream( " + sID + " ) " ) ) ) ;
}
void dependProcPatt ( string pID )
{
typedef P < Pipe > PPipe ; /////TODO: transition to P<>
typedef P < const ProcPatt > PProcPatt ;
2012-12-26 02:20:11 +01:00
PPipe thePipe = Pipe : : query ( " pipe( " + pID + " ) " ) ;
2011-12-02 17:50:44 +01:00
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
2012-12-26 02:20:11 +01:00
PPipe pipe2x = Pipe : : query ( " pattern(another) " ) ;
2011-12-02 17:50:44 +01:00
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 dependant 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....
2012-12-26 02:20:11 +01:00
PPipe pipe3x = Pipe : : query ( " pattern(another) " ) ;
2011-12-02 17:50:44 +01:00
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 proc::asset::test