# Author:: Yannick Lacaute # Copyright:: Copyright (c) 2004, 2005 Uttk team. All rights reserved. # License:: LGPL # $Id: Buffer.rb 645 2005-07-11 21:52:01 thor $ test_section __FILE__ do module Uttk module Filters class BufferTest < Test::Unit::TestCase include Mocks::Assertions include Buffer::Assertions @@ordered = { :ordered => true } def get_notifs ( anObject ) mo = Mocks::Observer.new log = Logger.new(mo) log << anObject mo.mock_args end def setup @notif_one_leaf = [ [ [], :foo ] ] @notif_two_leaves = [ [ [], :foo ], [ [], :bar ] ] @notifs_simple_map = [ [ [:foo], :bar ] ] @notifs_simple_omap = [ [ [[:foo, @@ordered], :bar], :baz ] ] @complex_tree_with_array = { :root => { :strategy => :cmd, :contents => [ { :test1 => { :cmd => [:a], :exit => [:aa] }, }, { :test2 => { :cmd => :b, :exit => :bb }, } ] } } @complex_tree_with_ohash = { :root => { :strategy => :cmd, :contents => OHash[ :test1, { :cmd => [:a], :exit=> [:aa] }, :test2, { :cmd => :b, :exit => :bb } ] } } @notifs_complex_gen_from_ohash = get_notifs(@complex_tree_with_ohash) @notifs_complex_gen_from_array = get_notifs(@complex_tree_with_array) @notifs_complex = [ [ [:root, [:strategy, @@ordered]], :cmd ], [ [:root,[:contents, @@ordered],:test1,[:cmd, @@ordered]], [:a] ], [ [:root,[:contents, @@ordered],:test1,[:exit, @@ordered]], [:aa] ], [ [:root,[:contents, @@ordered],:test2,:cmd], :b ], [ [:root,[:contents, @@ordered],:test2,:exit], :bb ] ] @notifs_map_with_two_leaves = [ [ [:foo], :bar ], [ [:foo], :baz ] ] @notifs_omap_with_two_leaves = [ [ [[:foo, @@ordered]], :bar ], [ [[:foo, @@ordered]], :baz ] ] self.mock_object = Mocks::Observer.new @buffer = Buffer.new([mock_object]) end def inject(notifs) notifs.each do |n| @buffer.update(*Logger.make_notif(n)) end end def test_buffer_one_leaf inject @notif_one_leaf assert_buffer :foo end def test_buffer_two_leaves inject @notif_two_leaves assert_buffer :bar end def test_buffer_simple_map inject @notifs_simple_map assert_buffer :foo => :bar assert_not_buffer :foo => { :wrong_value => nil } end def test_buffer_simple_omap inject @notifs_simple_omap assert_buffer :foo => OHash[:bar, :baz] end def test_buffer_complex inject @notifs_complex assert_buffer @complex_tree_with_ohash end def test_buffer_complex_from_ohash inject @notifs_complex_gen_from_ohash assert_buffer @complex_tree_with_ohash end def test_buffer_complex_from_array inject @notifs_complex_gen_from_array assert_buffer @complex_tree_with_ohash end # FIXME restore me when the DuplicatedPath exception will be reloaded def test_buffer_map_with_two_leaves # assert_raise(Logger::DuplicatedPath) { inject @notifs_map_with_two_leaves } assert_nothing_raised { inject @notifs_map_with_two_leaves } end def test_buffer_omap_with_two_leaves inject @notifs_omap_with_two_leaves assert_buffer :foo => [ :bar, :baz ] end end # class BufferTest end # module Filters end # module Uttk end