Fix minishogi notation, enabling play against gnuminishogi.
[kaya/ydirson.git] / test / test_controller.rb
blobb6e0a386b0c52da307d0c156709901bc32add797
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 'qtutils'
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
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 test_initial_state
47                 assert_nil @controller.match
48   end
49   
50   def test_single_player
51     match = Match.new(@game)
52     setup_single_player(match)
53     @controller.reset(match)
54     assert_equal match, @controller.match
55   end
56   
57   private
58   
59   def setup_single_player(match)
60     @controller.color = :white
61     @controller.premove = false
62     opponent = DummyPlayer.new(:black)
63     @controller.add_controlled_player(opponent) 
64     match.register(@controller)
65     match.register(opponent)
66     match.start(@controller)
67     match.start(opponent)
68     assert match.started?
69   end
70 end