# -*- coding: utf-8 -*-

## @file   testsuite/python/modDataSeqTest.py
## @date   feb. 2016
## @author PhRG - opticalp.fr
##
## Test the data push system 

#
# Copyright (c) 2016 Ph. Renaud-Goud / Opticalp
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.


def myMain():
    """Main function. Run the tests. """
    
    print "Test the basic features of the data push system. "
    
    fac = Factory("DemoRootFactory")
    print "Retrieved factory: " + fac.name
    
    print "Create module from leafDataSeq factory"
    mod1 = fac.select("branch").select("leafDataSeq").create("mod1")
    print "module " + mod1.name + " created. "
    
    print "Create module from leafSeqAccu factory"
    mod2a = fac.select("branch").select("leafSeqAccu").create("mod2a")
    print "module " + mod2a.name + " created. "
    
    print "Create module from leafSeqMax factory"
    mod2b = fac.select("branch").select("leafSeqAccu").create("mod2b")
    print "module " + mod2b.name + " created. "
    
    bind(mod1.outPorts()[0], mod2a.inPorts()[0])
    bind(mod1.outPorts()[0], mod2b.inPorts()[0])
    
    print "Query mod1 output targets: "
    for target in mod1.outPorts()[0].getTargetPorts():    
        print ( target.name + ", from module: " +
            target.parent().name )
            
    # launch action

    print "End of script modDataSeqTest.py"
    
# main body    
import sys
import os
    
if len(sys.argv) >= 1:
    # probably called from InstrumentAll
    checker = os.path.basename(sys.argv[0])
    if checker == "instrumentall":
        print "current script: ",os.path.realpath(__file__)
        
        from instru import *

        myMain()
        exit(0)

print "Presumably not called from InstrumentAll >> Exiting..."

exit("This script has to be launched from inside InstrumentAll")
Add a simple test for the push model
Add a simple test for the push model
