2008-02-08 15:38:31 -07:00
|
|
|
open Unixqueue
|
|
|
|
open OUnit
|
|
|
|
open Chat
|
2008-02-27 22:50:27 -07:00
|
|
|
open Irc
|
2008-02-08 15:38:31 -07:00
|
|
|
|
|
|
|
let do_chat script () =
|
2008-02-08 18:11:49 -07:00
|
|
|
let ircd_instance ues fd =
|
2008-02-27 22:50:27 -07:00
|
|
|
let g = Unixqueue.new_group ues in
|
2008-03-04 21:38:19 -07:00
|
|
|
Iobuf.add_event_handler ues g;
|
|
|
|
Iobuf.bind ues g fd (Client.create_command_handler ())
|
2008-02-08 15:38:31 -07:00
|
|
|
in
|
2008-02-08 18:11:49 -07:00
|
|
|
chat script ircd_instance
|
2008-02-08 15:38:31 -07:00
|
|
|
|
2008-02-27 22:50:27 -07:00
|
|
|
let unit_tests =
|
|
|
|
"Unit tests" >:::
|
|
|
|
[
|
|
|
|
"command_of_string" >::
|
|
|
|
(fun () ->
|
|
|
|
assert_equal
|
2008-02-28 22:00:24 -07:00
|
|
|
~printer:Command.as_string
|
2008-03-02 21:30:37 -07:00
|
|
|
(Command.create None "NICK" ["name"] None)
|
2008-02-28 22:00:24 -07:00
|
|
|
(Command.from_string "NICK name");
|
2008-02-27 22:50:27 -07:00
|
|
|
assert_equal
|
2008-02-28 22:00:24 -07:00
|
|
|
~printer:Command.as_string
|
2008-03-02 21:30:37 -07:00
|
|
|
(Command.create (Some "foo") "NICK" ["name"] None)
|
2008-02-28 22:00:24 -07:00
|
|
|
(Command.from_string ":foo NICK name");
|
2008-02-27 22:50:27 -07:00
|
|
|
assert_equal
|
2008-02-28 22:00:24 -07:00
|
|
|
~printer:Command.as_string
|
2008-03-02 21:34:27 -07:00
|
|
|
(Command.create (Some "foo.bar") "PART" ["#foo"; "#bar"]
|
2008-03-02 21:30:37 -07:00
|
|
|
(Some "ta ta"))
|
2008-02-28 22:00:24 -07:00
|
|
|
(Command.from_string ":foo.bar PART #foo #bar :ta ta");
|
2008-02-27 22:50:27 -07:00
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2008-03-02 21:30:37 -07:00
|
|
|
let do_login nick =
|
|
|
|
[
|
|
|
|
Send ("USER " ^ nick ^ " +iw " ^ nick ^ " :gecos\r\n");
|
|
|
|
Send ("NICK " ^ nick ^ "\r\n");
|
|
|
|
Recv (":testserver.test 001 " ^ nick ^ " :Welcome to IRC.\r\n");
|
2008-03-05 17:51:13 -07:00
|
|
|
Recv (":testserver.test 002 " ^ nick ^ " :I am testserver.test Running version " ^ Irc.version ^ "\r\n");
|
2008-03-02 21:30:37 -07:00
|
|
|
Recv (":testserver.test 003 " ^ nick ^ " :This server was created sometime\r\n");
|
|
|
|
Recv (":testserver.test 004 " ^ nick ^ " :testserver.test 0.1 l t\r\n");
|
|
|
|
]
|
|
|
|
|
2008-02-27 22:50:27 -07:00
|
|
|
let regression_tests =
|
2008-03-02 21:30:37 -07:00
|
|
|
"Regression tests" >:::
|
2008-02-08 15:38:31 -07:00
|
|
|
[
|
2008-03-02 21:30:37 -07:00
|
|
|
"Simple connection" >::
|
|
|
|
(do_chat ((do_login "nick") @
|
|
|
|
[Send "WELCOME :datacomp\r\n";
|
|
|
|
Recv "WELCOME :datacomp\r\n"]));
|
2008-02-08 15:38:31 -07:00
|
|
|
]
|
|
|
|
|
|
|
|
let _ =
|
2008-02-28 22:24:52 -07:00
|
|
|
Irc.name := "testserver.test";
|
2008-02-27 22:50:27 -07:00
|
|
|
run_test_tt_main (TestList [unit_tests; regression_tests])
|
2008-02-08 15:38:31 -07:00
|
|
|
|
|
|
|
|