# Author:: Nicolas Pouillard . # Copyright:: Copyright (c) 2004, 2005 TTK team. All rights reserved. # License:: LGPL # $Id: Composite.rb 567 2005-04-13 08:00:06Z polrop $ module TTK module Strategies class Composite < Strategy include Abstract def initialize ( *a, &b ) @contents = [] @status_list = [] super end def initialize_test ( aTest ) aTest.wclass = @wclass aTest.symtbl = new_symtbl end def create ( anObject, &block ) res = @symtbl[:loader].load(anObject) do |aTest| initialize_test(aTest) block[aTest] if block_given? end @contents << res res end def << ( anObject ) create(anObject) self end def new_symtbl @symtbl.class.new(@symtbl) end def prologue begin super ensure @composite_saved_path_size = @log.path_size end # @contents.map! do |t| # t.testify # end end protected :prologue def run_impl skip if @contents.empty? run_composite() end protected :run_impl def compute_final_weight return if defined? @final_weight @tmp_weight = @wclass.new(:START) @status_list.each { |status| @tmp_weight += status.weight } @final_weight = @tmp_weight.normalize(@weight) end private :compute_final_weight def assertion compute_final_weight fail @final_weight, @fatal_failure if defined? @fatal_failure skip if @tmp_weight.start? pass if @final_weight.pass? fail @final_weight end protected :assertion def epilogue compute_final_weight (@log.path_size - @composite_saved_path_size).times { @log.up } super end protected :epilogue # Do some tasks before a test of the composite is run. def prologue_test ( test, log ) end protected :prologue_test # Do some tasks at the moment where a test of the composite is run. def run_impl_test ( test, log ) test.run(log) end protected :run_impl_test # Do some tasks after a test of the composite has been run. def epilogue_test ( test, log ) if test.fatal and not test.status.pass? @fatal_failure = "Last test was fatal (#{test.name})" end end protected :epilogue_test def run_test ( test, log ) prologue_test(test, log) @status_list << run_impl_test(test, log) epilogue_test(test, log) end protected :run_test def run_composite @log.new_node :contents, :seq do @contents.each do |t| run_test(t, @log) break if defined? @fatal_failure end end end protected :run_composite def assign_at_last :contents end protected :assign_at_last attribute :contents, 'an array of tests', :invisible, :dont_expand do [] end module Ordered def self.included ( aClass ) aClass.module_eval do def new_symtbl if @contents.empty? @symtbl.class.new(@symtbl) else @symtbl.class.new(@contents.last.symtbl) end end protected :new_symtbl end end end # module Ordered end # class Composite end # module Strategies end # module TTK