Implement ActionList::Entry#clear.
[kaya.git] / test / test_controller.rb
blob6e28817d9df48ed1eef45535883a3b50ca1bf2b5
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'
10 require 'controller'
11 require 'helpers/stubs.rb'
12 require "games/all"
13 require 'dummy_player'
14 require 'board/scene'
15 require 'toolkits/qt'
16 require 'board/element_manager'
18 class TestController < Test::Unit::TestCase
19   class FakeTable
20     include ElementManager
21     attr_reader :scene, :elements, :game, :theme
22     
23     def initialize(game)
24       @game = game
25       @scene = Scene.new
26       @loader = PluginLoader.new
27     end
28     
29     def reset(match)
30       @theme = @loader.get_matching(:theme_loader).new.load(@game)
31       @elements = create_elements(@game)
32     end
33     
34     def flip(value)
35     end
36   end
37   
38   def setup
39     $qApp or Qt::Application.new([])
40     field = GeneralMock.new
41     @game = Game.get(:shogi)
42     @table = FakeTable.new(@game)
43     @controller = Controller.new(@table, field)
44   end
45   
46   def teardown
47     @table.scene.dispose
48   end
49   
50         def test_initial_state
51                 assert_nil @controller.match
52   end
53   
54   def test_single_player
55     match = Match.new(@game)
56     setup_single_player(match)
57     @controller.reset(match)
58     assert_equal match, @controller.match
59   end
60   
61   private
62   
63   def setup_single_player(match)
64     @controller.color = :white
65     @controller.premove = false
66     opponent = DummyPlayer.new(:black)
67     @controller.add_controlled_player(opponent) 
68     match.register(@controller)
69     match.register(opponent)
70     match.start(@controller)
71     match.start(opponent)
72     assert match.started?
73   end
74 end