Add StatusNotifier to ICS plugin.
[kaya.git] / test / test_animation_field.rb
blobdea3dd9e88b91e5dd91c6af17165086c94c31286
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 require 'test/unit'
9 require 'animation_field'
10 require 'toolkits/qt'
11 require 'rubygems'
12 require 'mocha'
14 class TestAnimationField < Test::Unit::TestCase
15   def setup
16     # remove connection with timer
17     Qt::Timer.stubs(:every) {}
18     
19     # create a field with an accessor for actions
20     @field = AnimationField.new(10)
21     @field.metaclass_eval do
22       attr_reader :actions
23     end
24   end
25   
26   def test_initialization
27     assert_equal [], @field.actions
28   end
29   
30   def test_tick_empty
31     @field.tick(1.0)
32     assert_equal [], @field.actions
33   end
34   
35   def test_tick_exit
36     action = mock("action") {|x| x.expects(:[]).with(1.0).returns(true) }
37     @field.run action
38     @field.tick(1.0)
39     assert_equal [], @field.actions
40   end
41   
42   def test_long_action
43     @field.run create_action(10)
44     10.times do |i|
45       assert_equal 1, @field.actions.size
46       @field.tick(i.to_f)
47     end
48     
49     assert_equal [], @field.actions
50   end
51   
52   def test_multiple_actions
53     @field.run create_action(3)
54     @field.run create_action(2)
55     
56     assert_equal 2, @field.actions.size
57     @field.tick 1.0
58     assert_equal 2, @field.actions.size
59     @field.tick 2.0
60     assert_equal 1, @field.actions.size
61     @field.tick 3.0
62     assert_equal [], @field.actions
63   end
64   
65 private
66   def create_action(length)
67     x = length
68     lambda { x -= 1; x <= 0 }
69   end
70 end