Add licence and installation instructions.
[kaya.git] / test / ics / test_protocol.rb
blob5f436d76e7dd5e89173100db420fb51469049a5f
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 'ics/protocol'
11 class TestProtocol < Test::Unit::TestCase
12   def setup
13     @protocol = ICS::Protocol.new(false)
14   end
16   def test_create_game
17     example1 = "Creating: azsxdc (++++) Hispanico (1684) unrated crazyhouse 3 0"
18     example2 = "{Game 502 (azsxdc vs. Hispanico) Creating unrated crazyhouse match.}"
19     
20     game_info = nil
21     @protocol.observe(:creating_game) { |game_info| }
22     @protocol.process(example1)
23     @protocol.process(example2)
24     
25     assert_not_nil game_info
26     assert_equal 'azsxdc', game_info[:white][:name]
27     assert_equal 0, game_info[:white][:score]
28     assert_equal 'Hispanico', game_info[:black][:name]
29     assert_equal 1684, game_info[:black][:score]
30     assert_equal 'unrated', game_info[:rated]
31     assert_equal 'crazyhouse', game_info[:type]
32     assert_equal 3, game_info[:time]
33     assert_equal 0, game_info[:increment]
34   end
36   def test_login
37     fired = false
38     @protocol.observe :login_prompt do
39       fired = true
40     end
41     @protocol.process_partial("login: ")
42     assert fired
43   end
45   def test_login
46     fired = false
47     @protocol.observe :login_prompt do
48       fired = true
49     end
50     @protocol.process("login: ")
51     assert !fired
52   end
53   
54   def test_beep
55     fired = false
56     @protocol.observe :beep do
57       fired = true
58     end
59     @protocol.process("\a")
60     assert fired
61   end
62 end