1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
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 'require_bundle'
9 require_bundle 'ics', 'match_helper'
10 require 'interaction/history'
16 class TestMatchHelper < Test::Unit::TestCase
18 chess = Game.get(:chess)
19 connection = stub_everything("connection")
21 @protocol = stub_everything("protocol") do
22 stubs(:connection).returns(connection)
24 @user = stub_everything("user")
25 @match = stub_everything("match") do
26 history = History.new(chess.state.new.tap{|s| s.setup })
28 stubs(:game).returns(chess)
29 stubs(:history).returns(history)
30 stubs(:started?).returns(true)
36 :white => { :name => 'Karpov' },
37 :black => { :name => 'Fisher' },
38 :icsapi => stub_everything("icsapi"),
41 @style12 = OpenStruct.new(
43 :relation => ICS::Style12::Relation::MY_MOVE,
44 :state => chess.state.new.tap {|s| s.setup },
49 def test_default_start
50 helper = ICS::DefaultMatchHelper.instance
51 @user.expects(:name=).with("Karpov")
52 @match.expects(:start).with(@user)
53 @match.expects(:start).with{|opp| opp.name == "Fisher" }
54 helper.start(@protocol, @user, @match_info, @style12)
57 def test_default_get_match
58 helper = ICS::DefaultMatchHelper.instance
59 info = helper.get_match(@protocol, @match_info, @style12)
60 assert_same @match, info[:match]
62 info = helper.get_match(@protocol, nil, @style12)
66 def test_examination_start
67 helper = ICS::ExaminingMatchHelper.instance
68 @match.expects(:start).with{|player| player.name == "Karpov" }
69 @match.expects(:start).with{|player| player.name == "Fisher" }
70 helper.start(@protocol, @user, @match_info, @style12)
73 def test_examination_get_match
74 helper = ICS::ExaminingMatchHelper.instance
75 info = helper.get_match(@protocol, @match_info, @style12)
76 assert_same @match, info[:match]
78 @style12.match_info = @match_info
79 info = helper.get_match(@protocol, nil, @style12)
81 assert_not_nil info[:match]
82 assert_equal 37, info[:number]
85 def test_observation_start
86 helper = ICS::ObservingMatchHelper.instance
87 @match.expects(:start).with{|player| player.name == "Karpov" }
88 @match.expects(:start).with{|player| player.name == "Fisher" }
89 helper.start(@protocol, @user, @match_info, @style12)