# Author:: Nicolas Pouillard . # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved. # License:: LGPL # $Id: /w/fey/uttk/trunk/lib/uttk/strategies/Composite.rb 22102 2006-02-21T23:03:39.538964Z pouillar $ module Uttk module Strategies # I'm the super class of every strategy class that are composed by other # strategies. class Composite < Strategy include Abstract require 'uttk/strategies/Composite/contents_eval' def initialize ( *a, &b ) @contents = [] @status_list = [] super end def initialize_copy ( aTest ) super aTest.contents = @contents.dup end def initialize_test ( aTest ) aTest.wclass = @wclass end def create ( anObject, &block ) res = anObject.testify(new_symtbl.merge!(testify_options)) do |aTest| initialize_test(aTest) raise "nil symtbl" if aTest.symtbl.nil? block[aTest] if block end @contents << res res end def << ( anObject ) create(anObject) self end def new_symtbl @symtbl.new_child end protected :new_symtbl def testify_options {} end protected :testify_options def contents(other=nil, &block) if other.nil? if block.nil? internal_contents else self.contents = ContentsEval.new(&block).contents end else self.contents = other end end def internal_contents @contents end protected :internal_contents 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 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 ) st = test.status if test.fatal and not (st.pass? or (st.is_a? SkipStatus and st.weight.max?)) @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, :ordered => true do @contents.each do |t| if defined? @fatal_failure st = FailStatus.new st.weight *= t.weight @status_list << st else run_test(t, @log) end 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.new_child else @contents.last.symtbl.new_child end end protected :new_symtbl end end end # module Ordered end # class Composite end # module Strategies end # module Uttk