194 lines
7.2 KiB
C++
194 lines
7.2 KiB
C++
/*
|
|
BasicPort(Test) - checking the basic properties of Port Assets
|
|
|
|
Copyright (C) CinelerraCV
|
|
2007, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
This program 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.
|
|
|
|
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.
|
|
|
|
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 02139, USA.
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
#include "common/test/run.hpp"
|
|
#include "common/util.hpp"
|
|
|
|
#include "proc/asset/category.hpp"
|
|
#include "proc/asset/port.hpp"
|
|
#include "proc/assetmanager.hpp"
|
|
#include "proc/mobject/session.hpp"
|
|
#include "proc/asset/assetdiagnostics.hpp"
|
|
|
|
#include <boost/format.hpp>
|
|
#include <iostream>
|
|
|
|
using boost::format;
|
|
using util::contains;
|
|
using util::isnil;
|
|
using std::string;
|
|
using std::cout;
|
|
|
|
|
|
namespace asset
|
|
{
|
|
namespace test
|
|
{
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
* @test basic properties of Port (structural) Assets.
|
|
* <ul><li>created by referral</li>
|
|
* <li>access existing port by referral</li>
|
|
* <li>create with full properties</li>
|
|
* <li>access ProcPatt</li>
|
|
* <li>check dependency</li>
|
|
* </ul>
|
|
*/
|
|
class BasicPort_test : public Test
|
|
{
|
|
virtual void run(Arg arg)
|
|
{
|
|
string portID = isnil(arg)? "blackHole" : arg[1];
|
|
string streamID = 2>arg.size()? "teststream" : arg[2] ;
|
|
|
|
createExplicit (portID,streamID);
|
|
create_or_ref (portID);
|
|
dependProcPatt (portID);
|
|
}
|
|
|
|
|
|
|
|
|
|
void createExplicit (string pID, string sID)
|
|
{
|
|
PPort thePort = asset::Struct::create (pID,sID);
|
|
|
|
ASSERT (thePort);
|
|
ASSERT (thePort->getProcPatt());
|
|
ASSERT (thePort->getPortID() == util::sanitize(pID));
|
|
ASSERT (thePort->getProcPatt()->getStreamID() == sID);
|
|
ASSERT (thePort->getShortDesc() == thePort->getPortID());
|
|
|
|
ID<Port> assetID = thePort->getID();
|
|
ASSERT (assetID.org = "cin3");
|
|
ASSERT (contains (assetID.name, thePort->getPortID()));
|
|
ASSERT (contains (assetID.name, thePort->getProcPatt()->getStreamID()));
|
|
|
|
Category cat (assetID.category);
|
|
Category refcat (STRUCT,"ports");
|
|
ASSERT ( cat.hasKind(STRUCT) );
|
|
ASSERT ( cat.isWithin(refcat) );
|
|
}
|
|
|
|
|
|
void create_or_ref(string pID)
|
|
{
|
|
pID = util::sanitize (pID);
|
|
PPort port1 = asset::Struct::query<Port> ("port("+pID+")");
|
|
ASSERT (port1);
|
|
ASSERT (port1->getPortID() == pID);
|
|
|
|
string pID2 = "another-" + pID;
|
|
PPort port2 = asset::Struct::query<Port> ("port("+pID2+")");
|
|
ASSERT (port2);
|
|
ASSERT (port2 != port1);
|
|
Category c1 = port1->getID().category;
|
|
Category c2 = port2->getID().category;
|
|
ASSERT (c1 == c2);
|
|
|
|
PPort port3 = asset::Struct::query<Port> ("port("+pID2+")");
|
|
ASSERT (port3 == port2);
|
|
}
|
|
|
|
|
|
void create_using_default()
|
|
{
|
|
PPort port1 = asset::Struct::query<Port> ("");
|
|
ASSERT (port1);
|
|
ASSERT (port1 == mobject::Session::current->getDefault<Port>());
|
|
ASSERT (port1->getID().category.hasKind(VIDEO));
|
|
ASSERT (port1->getProcPatt());
|
|
PProcPatt popa = mobject::Session::current->getDefault<ProcPatt>("port()");
|
|
ASSERT (popa == port1->getProcPatt());
|
|
|
|
PPort port2 = asset::Struct::query<Port> ("port()");
|
|
ASSERT (port2 == port1);
|
|
|
|
string sID = popa->getStreamID(); // sort of a "default stream type"
|
|
PPort port3 = asset::Struct::query<Port> ("stream("+sID+")");
|
|
ASSERT (port3);
|
|
ASSERT (port3->getProcPatt()->getStreamID() == sID);
|
|
ASSERT (port3->getProcPatt() == mobject::Session::current->getDefault<ProcPatt>("stream("+sID+")");
|
|
}
|
|
|
|
|
|
void dependProcPatt(string pID)
|
|
{
|
|
PPort thePort = asset::Struct::query<Port> ("port("+pID+")");
|
|
ASSERT (thePort);
|
|
PProcPatt thePatt = thePort->getProcPatt();
|
|
ASSERT (thePatt);
|
|
ASSERT (dependencyCheck (thePort, thePatt));
|
|
|
|
PProcPatt pattern2 = thePatt->newCopy("another");
|
|
ASSERT (thePatt != pattern2);
|
|
ASSERT (!dependencyCheck (thePort, pattern2));
|
|
TODO ("add something to the new pattern, e.g. an effect");
|
|
|
|
// now querying for a port using this pattern (created on-the-fly)
|
|
// note: because the pattern is new, this new port will be used as
|
|
// default port for this pattern automatically
|
|
PPort port2x = asset::Struct::query<Port> ("pattern(another)");
|
|
ASSERT (pattern2 == port2x->getProcPatt());
|
|
ASSERT (port2x == mobject::Session::current->getDefault<Port>("pattern(another)"));
|
|
|
|
thePort->switchProcPatt(pattern2);
|
|
ASSERT ( dependencyCheck (thePort, pattern2));
|
|
ASSERT (!dependencyCheck (thePort, thePatt));
|
|
|
|
AssetManager& aMang = AssetManager::instance();
|
|
ASSERT ( aMang.known (thePort->getID()));
|
|
ASSERT ( aMang.known (thePatt->getID()));
|
|
ASSERT ( aMang.known (pattern2->getID()));
|
|
aMang.remove (pattern2->getID());
|
|
ASSERT ( aMang.known (thePatt->getID()));
|
|
ASSERT (!aMang.known (pattern2->getID()));
|
|
ASSERT (!aMang.known (thePort->getID())); // has been unlinked too, because dependant on pattern2
|
|
|
|
ASSERT (thePort);
|
|
ASSERT (thePort->getProcPatt());
|
|
ASSERT (thePort->getProcPatt() == pattern2); // but is still valid, as long as the ref is alive....
|
|
|
|
PPort port3x = asset::Struct::query<Port> ("pattern(another)");
|
|
ASSERT (port3x->getProcPatt() != pattern2); // because pattern2 is already unlinked...
|
|
ASSERT (port3x == mobject::Session::current->getDefault<Port>("pattern(another)"));
|
|
ASSERT (port3x != port2x); // ..we got a new default port for "pattern(another)" too!
|
|
|
|
|
|
TRACE (assetmem, "leaving BasicPort_test::dependProcPatt()");
|
|
// expect now port2x and pattern2 to be destroyed...
|
|
}
|
|
};
|
|
|
|
|
|
/** Register this test class... */
|
|
LAUNCHER (BasicPort_test, "unit asset");
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
} // namespace asset
|