# Author:: Nicolas Pouillard . # Copyright:: Copyright (c) 2004, 2005 TTK team. All rights reserved. # License:: LGPL # $Id: Stream.rb 567 2005-04-13 08:00:06Z polrop $ require 'mktemp' module TTK module Streams # # Internal classes # Pathname.glob(SRC_DIR + 'strategies' + 'Streams' + '*.rb') do |path| name = path.basename.to_s.sub(/\.rb$/, '') autoload(name.to_sym, "ttk/strategies/Streams/#{name}") end class Stream # # Attributes # attr_accessor :name, :my, :ref # # Constructor # def initialize ( name, ref=nil ) @name, @my, @ref = name.to_s, TempPath.new("#{ME}-#{name}"), ref end # # Methods # def compare_streams return @cmp if defined? @cmp @cmp = @ref.compare_stream(@my) @status = @cmp ? :PASS : :FAILED @cmp end def status compare_streams @status end def to_ttk_log ( log ) log["my_#@name"] = @my.to_s_for_ttk_log log["ref_#@name"] = @ref.to_s_for_ttk_log unless @ref.nil? end def clean if @my.is_a? Pathname @my.unlink if @my.exist? and @my.temp? end if @ref.is_a? Pathname @ref.unlink if @ref.exist? and @ref.temp? elsif @ref.is_a? File ref = Pathname.new(@ref.path) ref.unlink if ref.exist? and ref.temp? end end end # class Stream end # module Streams end # module TTK class Object def compare_stream ( stream ) to_s.compare_stream(stream) end def to_s_for_ttk_log to_s end end class NilClass def compare_stream ( stream ) true end def to_s_for_ttk_log false end end class Regexp def compare_stream ( stream ) stream.read =~ self end def to_s_for_ttk_log "/#{source.sub(/\//, '\\/')}/" end end class String def compare_stream ( stream ) self == stream.read end end class Pathname def compare_stream ( stream ) read.compare_stream(stream) end def to_s_for_ttk_log read end end class IO def compare_stream ( stream ) rewind read.compare_stream(stream) end def to_s_for_ttk_log rewind read end end