ircguerilla-irc 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/irc/client/client_error.rb +35 -0
- data/lib/irc/client/command_handler.rb +113 -0
- data/lib/irc/client/connected_state.rb +95 -0
- data/lib/irc/client/connection.rb +119 -0
- data/lib/irc/client/connection_listener.rb +97 -0
- data/lib/irc/client/connection_state.rb +88 -0
- data/lib/irc/client/context.rb +250 -0
- data/lib/irc/client/disconnected_state.rb +132 -0
- data/lib/irc/client/message_handler.rb +87 -0
- data/lib/irc/client/registered_state.rb +90 -0
- data/lib/irc/client/unregistered_state.rb +113 -0
- data/lib/irc/commands/command.rb +57 -0
- data/lib/irc/commands/invalid_command.rb +35 -0
- data/lib/irc/commands/join_command.rb +122 -0
- data/lib/irc/commands/nick_command.rb +86 -0
- data/lib/irc/commands/part_command.rb +84 -0
- data/lib/irc/commands/password_command.rb +72 -0
- data/lib/irc/commands/ping_command.rb +79 -0
- data/lib/irc/commands/pong_command.rb +68 -0
- data/lib/irc/commands/quit_command.rb +77 -0
- data/lib/irc/commands/user_command.rb +105 -0
- data/lib/irc/messages/codes.rb +186 -0
- data/lib/irc/messages/error_join_message.rb +72 -0
- data/lib/irc/messages/error_message.rb +101 -0
- data/lib/irc/messages/factory.rb +122 -0
- data/lib/irc/messages/invalid_message.rb +35 -0
- data/lib/irc/messages/join_message.rb +130 -0
- data/lib/irc/messages/message.rb +110 -0
- data/lib/irc/messages/nick_message.rb +93 -0
- data/lib/irc/messages/notice_message.rb +87 -0
- data/lib/irc/messages/part_message.rb +95 -0
- data/lib/irc/messages/ping_message.rb +101 -0
- data/lib/irc/messages/pong_message.rb +89 -0
- data/lib/irc/messages/private_message.rb +121 -0
- data/lib/irc/models/bot.rb +159 -0
- data/lib/irc/models/channel.rb +158 -0
- data/lib/irc/models/network.rb +252 -0
- data/lib/irc/models/packet.rb +84 -0
- data/lib/irc/models/server.rb +116 -0
- data/lib/irc/models/user.rb +112 -0
- data/test/functional/irc/client/connection_test.rb +118 -0
- data/test/functional/irc/client/context_test.rb +126 -0
- data/test/test_helper.rb +32 -0
- data/test/unit/irc/client/command_handler_test.rb +137 -0
- data/test/unit/irc/commands/join_command_test.rb +72 -0
- data/test/unit/irc/commands/nick_command_test.rb +35 -0
- data/test/unit/irc/commands/part_command_test.rb +52 -0
- data/test/unit/irc/commands/password_command_test.rb +35 -0
- data/test/unit/irc/commands/ping_command_test.rb +36 -0
- data/test/unit/irc/commands/pong_command_test.rb +36 -0
- data/test/unit/irc/commands/quit_command_test.rb +35 -0
- data/test/unit/irc/commands/user_command_test.rb +35 -0
- data/test/unit/irc/messages/error_join_message_test.rb +45 -0
- data/test/unit/irc/messages/factory_test.rb +62 -0
- data/test/unit/irc/messages/join_message_test.rb +46 -0
- data/test/unit/irc/messages/message_test.rb +56 -0
- data/test/unit/irc/messages/nick_message_test.rb +48 -0
- data/test/unit/irc/messages/notice_message_test.rb +43 -0
- data/test/unit/irc/messages/part_message_test.rb +47 -0
- data/test/unit/irc/messages/ping_message_test.rb +57 -0
- data/test/unit/irc/messages/pong_message_test.rb +57 -0
- data/test/unit/irc/messages/private_message_test.rb +42 -0
- data/test/unit/irc/models/bot_test.rb +85 -0
- data/test/unit/irc/models/channel_test.rb +90 -0
- data/test/unit/irc/models/network_test.rb +210 -0
- data/test/unit/irc/models/packet_test.rb +38 -0
- data/test/unit/irc/models/server_test.rb +54 -0
- data/test/unit/irc/models/user_test.rb +67 -0
- metadata +111 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
# a copy of this software and associated documentation files (the
|
7
|
+
# "Software"), to deal in the Software without restriction, including
|
8
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
# the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
#
|
24
|
+
# $Id: pong_message_test.rb 93 2006-08-13 21:30:53Z roman $
|
25
|
+
#
|
26
|
+
require 'irc/messages/invalid_message'
|
27
|
+
require 'irc/messages/pong_message'
|
28
|
+
require 'test/unit'
|
29
|
+
|
30
|
+
class IRC::Messages::PongMessageTest < Test::Unit::TestCase
|
31
|
+
|
32
|
+
def test_invalid_messages
|
33
|
+
assert_raise(IRC::Messages::InvalidMessage) { IRC::Messages::PongMessage.new("") }
|
34
|
+
assert_raise(IRC::Messages::InvalidMessage) { IRC::Messages::PongMessage.new("PONG") }
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_daemon
|
38
|
+
|
39
|
+
message = IRC::Messages::PongMessage.new("PONG csd.bu.edu")
|
40
|
+
assert_equal ["csd.bu.edu"], message.daemons
|
41
|
+
|
42
|
+
message = IRC::Messages::PongMessage.new("PONG :csd.bu.edu")
|
43
|
+
assert_equal ["csd.bu.edu"], message.daemons
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_daemons
|
48
|
+
|
49
|
+
message = IRC::Messages::PongMessage.new("PONG csd.bu.edu tolsun.oulu.fi")
|
50
|
+
assert_equal ["csd.bu.edu", "tolsun.oulu.fi"], message.daemons
|
51
|
+
|
52
|
+
message = IRC::Messages::PongMessage.new("PONG :csd.bu.edu :tolsun.oulu.fi")
|
53
|
+
assert_equal ["csd.bu.edu", "tolsun.oulu.fi"], message.daemons
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
# a copy of this software and associated documentation files (the
|
7
|
+
# "Software"), to deal in the Software without restriction, including
|
8
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
# the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
#
|
24
|
+
# $Id$
|
25
|
+
#
|
26
|
+
require 'irc/messages/invalid_message'
|
27
|
+
require 'irc/messages/private_message'
|
28
|
+
require 'test/unit'
|
29
|
+
|
30
|
+
class IRC::Messages::PrivateMessageTest < Test::Unit::TestCase
|
31
|
+
|
32
|
+
def test_message
|
33
|
+
|
34
|
+
message = IRC::Messages::PrivateMessage.new(":Angel PRIVMSG Wiz :Hello are you receiving this message ?")
|
35
|
+
assert_equal "Angel", message.sender
|
36
|
+
assert_equal "Angel", message.nick
|
37
|
+
assert_equal "Wiz", message.target
|
38
|
+
assert_equal "Hello are you receiving this message ?", message.text
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
# a copy of this software and associated documentation files (the
|
7
|
+
# "Software"), to deal in the Software without restriction, including
|
8
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
# the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
#
|
24
|
+
# $Id: bot_test.rb 85 2006-08-13 11:42:07Z roman $
|
25
|
+
#
|
26
|
+
require 'irc/models/bot'
|
27
|
+
require 'irc/models/network'
|
28
|
+
require 'test/unit'
|
29
|
+
|
30
|
+
class IRC::Models::BotTest < Test::Unit::TestCase
|
31
|
+
|
32
|
+
def setup
|
33
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
34
|
+
@bot = network.create_bot('dr-fumanshu')
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_create_packet
|
38
|
+
|
39
|
+
packet = @bot.create_packet(1, "Mary_J_Blige-My_Collection_Of_Love_Songs-2006-CNS.tar", 1024 * 10, 10)
|
40
|
+
assert_equal 1, @bot.packets.size
|
41
|
+
assert_equal 1, packet.number
|
42
|
+
assert_equal "Mary_J_Blige-My_Collection_Of_Love_Songs-2006-CNS.tar", packet.description
|
43
|
+
assert_equal 1024 * 10, packet.size_in_bytes
|
44
|
+
assert_equal 10, packet.number_of_downloads
|
45
|
+
|
46
|
+
packet = @bot.create_packet(2, "The_Bee_Gees-Love_Songs-CD-2005-OMC.tar", 1024 * 20, 20)
|
47
|
+
assert_equal 2, @bot.packets.size
|
48
|
+
assert_equal 2, packet.number
|
49
|
+
assert_equal "The_Bee_Gees-Love_Songs-CD-2005-OMC.tar", packet.description
|
50
|
+
assert_equal 1024 * 20, packet.size_in_bytes
|
51
|
+
assert_equal 20, packet.number_of_downloads
|
52
|
+
|
53
|
+
assert_raise(Exception) { @bot.create_packet(2, "50_Cent_f_Nate_Dogg-21_Questions-SVCD-2003-Ice01-UVZ.m2v", 1024 * 20, 20) }
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_packet
|
58
|
+
|
59
|
+
packet = @bot.create_packet(2, "Mary_J_Blige-My_Collection_Of_Love_Songs-2006-CNS.tar", 1024 * 20, 20)
|
60
|
+
assert_equal 1, @bot.packets.size
|
61
|
+
|
62
|
+
# First packet doesn't exist.
|
63
|
+
assert_nil @bot.packet(1)
|
64
|
+
|
65
|
+
assert_equal packet, @bot.packet(2)
|
66
|
+
assert_equal 2, packet.number
|
67
|
+
assert_equal "Mary_J_Blige-My_Collection_Of_Love_Songs-2006-CNS.tar", packet.description
|
68
|
+
assert_equal 1024 * 20, packet.size_in_bytes
|
69
|
+
assert_equal 20, packet.number_of_downloads
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_packets
|
74
|
+
|
75
|
+
@bot.create_packet(1, "Mary_J_Blige-My_Collection_Of_Love_Songs-2006-CNS.tar", 1024 * 10, 10)
|
76
|
+
assert @bot.packets.include?(@bot.packet(1))
|
77
|
+
|
78
|
+
@bot.create_packet(3, "The_Bee_Gees-Love_Songs-CD-2005-OMC.tar", 1024 * 30, 30)
|
79
|
+
assert @bot.packets.include?(@bot.packet(3))
|
80
|
+
|
81
|
+
assert_equal 2, @bot.packets.size
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
# a copy of this software and associated documentation files (the
|
7
|
+
# "Software"), to deal in the Software without restriction, including
|
8
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
# the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
#
|
24
|
+
# $Id: channel_test.rb 85 2006-08-13 11:42:07Z roman $
|
25
|
+
#
|
26
|
+
require 'yaml'
|
27
|
+
require 'irc/models/channel'
|
28
|
+
require 'irc/models/network'
|
29
|
+
require 'irc/models/server'
|
30
|
+
require 'irc/models/user'
|
31
|
+
require 'test/unit'
|
32
|
+
|
33
|
+
class IRC::Models::ChannelTest < Test::Unit::TestCase
|
34
|
+
|
35
|
+
def setup
|
36
|
+
@network = IRC::Models::Network.new(:name => 'Efnet')
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_key
|
40
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
41
|
+
channel = network.create_channel('#ircguerilla')
|
42
|
+
assert_equal 'efnet|#ircguerilla', channel.key
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_equal
|
46
|
+
|
47
|
+
assert_equal IRC::Models::Channel.new(:network => @network, :name => '#channel'), IRC::Models::Channel.new(:network => @network, :name => '#channel')
|
48
|
+
|
49
|
+
assert_not_equal IRC::Models::Channel.new(:network => @network, :name => '#channel'), IRC::Models::Channel.new(:network => @network, :name => '#other')
|
50
|
+
assert_not_equal IRC::Models::Channel.new(:network => IRC::Models::Network.new(:name => 'Undernet'), :name => '#channel'), IRC::Models::Channel.new(:network => @network, :name => '#channel')
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_left_shift
|
55
|
+
|
56
|
+
channel_name = ""
|
57
|
+
|
58
|
+
channel = @network.create_channel("#channel")
|
59
|
+
channel_name << channel
|
60
|
+
assert_equal "#channel", channel_name
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_is_valid
|
65
|
+
assert IRC::Models::Channel.is_valid?("#channel") == true
|
66
|
+
assert IRC::Models::Channel.is_valid?("&channel") == true
|
67
|
+
assert IRC::Models::Channel.is_valid?(" #channel") == true
|
68
|
+
assert IRC::Models::Channel.is_valid?(" &channel") == true
|
69
|
+
assert IRC::Models::Channel.is_valid?("") == false
|
70
|
+
assert IRC::Models::Channel.is_valid?(" ") == false
|
71
|
+
assert IRC::Models::Channel.is_valid?(" channel") == false
|
72
|
+
assert IRC::Models::Channel.is_valid?("channel") == false
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_add_user(channel_name = "#ircguerilla", nick = "ircguerilla")
|
76
|
+
user = @network.create_user(nick)
|
77
|
+
channel = @network.create_channel(channel_name)
|
78
|
+
channel.add_user(user)
|
79
|
+
assert channel.users.include?(user)
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_remove_channel(channel_name = "#ircguerilla", nick = "ircguerilla")
|
83
|
+
test_add_user(channel_name, nick)
|
84
|
+
user = @network.lookup_user(nick)
|
85
|
+
channel = @network.lookup_channel(channel_name)
|
86
|
+
channel.remove_user(user)
|
87
|
+
assert !channel.users.include?(user)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2006 Roman Scherer | IRC Guerilla | Rapid Packet Movement
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
# a copy of this software and associated documentation files (the
|
7
|
+
# "Software"), to deal in the Software without restriction, including
|
8
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
# the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
#
|
24
|
+
# $Id: network_test.rb 85 2006-08-13 11:42:07Z roman $
|
25
|
+
#
|
26
|
+
require 'irc/models/bot'
|
27
|
+
require 'irc/models/channel'
|
28
|
+
require 'irc/models/network'
|
29
|
+
require 'irc/models/server'
|
30
|
+
require 'irc/models/user'
|
31
|
+
require 'test/unit'
|
32
|
+
|
33
|
+
class IRC::Models::NetworkTest < Test::Unit::TestCase
|
34
|
+
|
35
|
+
def test_equal
|
36
|
+
assert_equal IRC::Models::Network.new(:name => 'Efnet'), IRC::Models::Network.new(:name => 'Efnet')
|
37
|
+
assert_not_equal IRC::Models::Network.new(:name => 'Efnet'), IRC::Models::Network.new(:name => 'Undernet')
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_key
|
41
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
42
|
+
assert_equal 'efnet', network.key
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_lookup_or_create_bot
|
46
|
+
|
47
|
+
# Create the network.
|
48
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
49
|
+
|
50
|
+
# Create a new bot.
|
51
|
+
bot = network.lookup_or_create_bot('dr-fumanshu')
|
52
|
+
assert_not_nil bot
|
53
|
+
assert_equal network, bot.network
|
54
|
+
assert_equal 1, network.bots.size
|
55
|
+
assert_equal 1, network.users.size
|
56
|
+
|
57
|
+
# Create the same bot again should return the previously
|
58
|
+
# created bot.
|
59
|
+
same_bot = network.lookup_or_create_bot('dr-fumanshu')
|
60
|
+
assert_equal 1, network.bots.size
|
61
|
+
assert_equal 1, network.users.size
|
62
|
+
assert_equal bot, same_bot
|
63
|
+
|
64
|
+
# Create an other bot.
|
65
|
+
other_user = network.lookup_or_create_bot('badman')
|
66
|
+
assert_equal 2, network.bots.size
|
67
|
+
assert_equal 2, network.users.size
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_lookup_or_create_channel
|
72
|
+
|
73
|
+
# Create the network.
|
74
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
75
|
+
|
76
|
+
# Create a new channel.
|
77
|
+
channel = network.lookup_or_create_channel('#channel')
|
78
|
+
assert_not_nil channel
|
79
|
+
assert_equal(network, channel.network)
|
80
|
+
assert_equal(1, network.channels.size)
|
81
|
+
|
82
|
+
# Create the same channel again should return the previously
|
83
|
+
# created channel.
|
84
|
+
same_channel = network.lookup_or_create_channel('#channel')
|
85
|
+
assert_equal(1, network.channels.size)
|
86
|
+
assert_equal(channel, same_channel)
|
87
|
+
|
88
|
+
# Create an other channel.
|
89
|
+
other_channel = network.lookup_or_create_channel('#other')
|
90
|
+
assert_equal(2, network.channels.size)
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_lookup_or_create_server
|
95
|
+
|
96
|
+
# Create the network.
|
97
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
98
|
+
|
99
|
+
# Create a new server.
|
100
|
+
server = network.lookup_or_create_server('irc.efnet.de')
|
101
|
+
assert_not_nil server
|
102
|
+
assert_equal(network, server.network)
|
103
|
+
assert_equal(1, network.servers.size)
|
104
|
+
|
105
|
+
# Create the same server again should return the previously
|
106
|
+
# created server.
|
107
|
+
same_server = network.lookup_or_create_server('irc.efnet.de')
|
108
|
+
assert_equal(1, network.servers.size)
|
109
|
+
assert_equal(server, same_server)
|
110
|
+
|
111
|
+
# Create an other server.
|
112
|
+
other_server = network.lookup_or_create_server('irc.efnet.com')
|
113
|
+
assert_equal(2, network.servers.size)
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_lookup_or_create_user
|
118
|
+
|
119
|
+
# Create the network.
|
120
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
121
|
+
|
122
|
+
# Create a new user.
|
123
|
+
user = network.lookup_or_create_user('dr-fumanshu')
|
124
|
+
assert_not_nil user
|
125
|
+
assert_equal(network, user.network)
|
126
|
+
assert_equal(1, network.users.size)
|
127
|
+
|
128
|
+
# Create the same user again should return the previously
|
129
|
+
# created user.
|
130
|
+
same_user = network.lookup_or_create_user('dr-fumanshu')
|
131
|
+
assert_equal(1, network.users.size)
|
132
|
+
assert_equal(user, same_user)
|
133
|
+
|
134
|
+
# Create an other user.
|
135
|
+
other_user = network.lookup_or_create_user('badman')
|
136
|
+
assert_equal(2, network.users.size)
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_lookup_bot
|
141
|
+
|
142
|
+
# Create the network.
|
143
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
144
|
+
|
145
|
+
# Create and lookup bot.
|
146
|
+
bot = network.create_bot('batman')
|
147
|
+
assert_equal bot, network.lookup_bot(bot.nick)
|
148
|
+
assert_equal 1, network.bots.size
|
149
|
+
assert_equal 1, network.users.size
|
150
|
+
|
151
|
+
# Create user and lookup bot with the user's name.
|
152
|
+
user = network.create_user('dr-fumanshu')
|
153
|
+
assert_equal 1, network.bots.size
|
154
|
+
assert_equal 2, network.users.size
|
155
|
+
|
156
|
+
assert_nil network.lookup_bot('dr-fumanshu')
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_lookup_channel
|
161
|
+
|
162
|
+
# Create the network.
|
163
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
164
|
+
|
165
|
+
# Create and lookup channel.
|
166
|
+
channel = network.create_channel('#channel')
|
167
|
+
assert_equal channel, network.lookup_channel('#channel')
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_lookup_server
|
172
|
+
|
173
|
+
# Create the network.
|
174
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
175
|
+
|
176
|
+
# Create and lookup server.
|
177
|
+
server = network.create_server('irc.efnet.de', 23)
|
178
|
+
assert_equal server, network.lookup_server('irc.efnet.de', 23)
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_lookup_user
|
183
|
+
|
184
|
+
# Create the network.
|
185
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
186
|
+
|
187
|
+
# Create and lookup user.
|
188
|
+
user = network.create_user('dr-fumanshu')
|
189
|
+
assert_not_nil user
|
190
|
+
assert_equal 1, network.users.size
|
191
|
+
assert_equal 0, network.bots.size
|
192
|
+
assert_equal user, network.lookup_user(user.nick)
|
193
|
+
|
194
|
+
# Create a bot and lookup bot as user.
|
195
|
+
bot = network.create_bot('batman')
|
196
|
+
assert_not_nil bot
|
197
|
+
assert_equal 2, network.users.size
|
198
|
+
assert_equal 1, network.bots.size
|
199
|
+
|
200
|
+
assert_equal bot, network.lookup_user(bot.nick)
|
201
|
+
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_to_xml
|
205
|
+
network = IRC::Models::Network.new(:name => 'Efnet')
|
206
|
+
network.create_channel("#ircguerilla", "secret")
|
207
|
+
network.create_server("irc.efnet.pl")
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|