Fixed compilation of test cases and made API changes for testing where
necessary.
This commit is contained in:
parent
75bcc42af5
commit
52027f7834
4 changed files with 140 additions and 163 deletions
|
@ -2,11 +2,13 @@
|
|||
#[cfg(feature = "ssl")] use std::error::Error as StdError;
|
||||
use std::io::prelude::*;
|
||||
use std::io::{BufReader, BufWriter, Cursor, Result};
|
||||
use std::io::Error;
|
||||
use std::io::ErrorKind;
|
||||
#[cfg(feature = "ssl")] use std::io::Error;
|
||||
#[cfg(feature = "ssl")] use std::io::ErrorKind;
|
||||
use std::net::TcpStream;
|
||||
#[cfg(feature = "ssl")] use std::result::Result as StdResult;
|
||||
use std::sync::Mutex;
|
||||
#[cfg(feature = "encode")] use encoding::DecoderTrap;
|
||||
#[cfg(feature = "encode")] use encoding::label::encoding_from_whatwg_label;
|
||||
#[cfg(feature = "ssl")] use openssl::ssl::{SslContext, SslMethod, SslStream};
|
||||
#[cfg(feature = "ssl")] use openssl::ssl::error::SslError;
|
||||
|
||||
|
@ -30,6 +32,12 @@ pub trait Connection {
|
|||
|
||||
/// Gets the full record of all sent messages if the Connection records this.
|
||||
/// This is intended for use in writing tests.
|
||||
#[cfg(feature = "encoding")]
|
||||
fn written(&self, encoding: &str) -> Option<String>;
|
||||
|
||||
/// Gets the full record of all sent messages if the Connection records this.
|
||||
/// This is intended for use in writing tests.
|
||||
#[cfg(not(feature = "encoding"))]
|
||||
fn written(&self) -> Option<String>;
|
||||
|
||||
/// Re-establishes this connection, disconnecting from the existing case if necessary.
|
||||
|
@ -129,6 +137,12 @@ impl Connection for NetConnection {
|
|||
imp::recv(&self.reader)
|
||||
}
|
||||
|
||||
#[cfg(feature = "encoding")]
|
||||
fn written(&self, _: &str) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "encoding"))]
|
||||
fn written(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
@ -159,6 +173,11 @@ pub struct MockConnection {
|
|||
}
|
||||
|
||||
impl MockConnection {
|
||||
/// Creates a new mock connection with an empty read buffer.
|
||||
pub fn empty() -> MockConnection {
|
||||
MockConnection::from_byte_vec(Vec::new())
|
||||
}
|
||||
|
||||
/// Creates a new mock connection with the specified string in the read buffer.
|
||||
pub fn new(input: &str) -> MockConnection {
|
||||
MockConnection::from_byte_vec(input.as_bytes().to_vec())
|
||||
|
@ -194,6 +213,14 @@ impl Connection for MockConnection {
|
|||
imp::recv(&self.reader)
|
||||
}
|
||||
|
||||
#[cfg(feature = "encoding")]
|
||||
fn written(&self, encoding: &str) -> Option<String> {
|
||||
encoding_from_whatwg_label(encoding).and_then(|enc|
|
||||
enc.decode(&self.writer.lock().unwrap(), DecoderTrap::Replace).ok()
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "encoding"))]
|
||||
fn written(&self) -> Option<String> {
|
||||
String::from_utf8(self.writer.lock().unwrap().clone()).ok()
|
||||
}
|
||||
|
@ -234,7 +261,7 @@ mod imp {
|
|||
|
||||
#[cfg(not(feature = "encode"))]
|
||||
pub fn send<T: IrcWrite>(writer: &Mutex<T>, msg: &str) -> Result<()> {
|
||||
let mut writer = self.writer.lock().unwrap();
|
||||
let mut writer = writer.lock().unwrap();
|
||||
try!(writer.write_all(msg.as_bytes()));
|
||||
writer.flush()
|
||||
}
|
||||
|
@ -311,19 +338,28 @@ impl Write for NetStream {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::Connection;
|
||||
use std::io::{Cursor, sink};
|
||||
use super::{Connection, MockConnection};
|
||||
use std::io::Result;
|
||||
use client::data::Message;
|
||||
use client::data::Command::PRIVMSG;
|
||||
use client::test::buf_empty;
|
||||
#[cfg(feature = "encode")] use encoding::{DecoderTrap, Encoding};
|
||||
#[cfg(feature = "encode")] use encoding::all::{ISO_8859_15, UTF_8};
|
||||
|
||||
#[cfg(feature = "encode")]
|
||||
fn send_to<C: Connection, M: Into<Message>>(conn: &C, msg: M, encoding: &str) -> Result<()> {
|
||||
conn.send(&msg.into().into_string(), encoding)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "encode"))]
|
||||
fn send_to<C: Connection, M: Into<Message>>(conn: &C, msg: M) -> Result<()> {
|
||||
conn.send(&msg.into().into_string())
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "encode"))]
|
||||
fn send() {
|
||||
let conn = Connection::new(buf_empty(), Vec::new());
|
||||
assert!(conn.send(PRIVMSG("test".to_owned(), "Testing!".to_owned())).is_ok());
|
||||
let data = String::from_utf8(conn.writer().to_vec()).unwrap();
|
||||
let conn = MockConnection::empty();
|
||||
assert!(send_to(&conn, PRIVMSG("test".to_owned(), "Testing!".to_owned())).is_ok());
|
||||
let data = conn.written().unwrap();
|
||||
assert_eq!(&data[..], "PRIVMSG test :Testing!\r\n");
|
||||
}
|
||||
|
||||
|
@ -331,18 +367,18 @@ mod test {
|
|||
#[cfg(not(feature = "encode"))]
|
||||
fn send_str() {
|
||||
let exp = "PRIVMSG test :Testing!\r\n";
|
||||
let conn = Connection::new(buf_empty(), Vec::new());
|
||||
assert!(conn.send(exp).is_ok());
|
||||
let data = String::from_utf8(conn.writer().to_vec()).unwrap();
|
||||
let conn = MockConnection::empty();
|
||||
assert!(send_to(&conn, exp).is_ok());
|
||||
let data = conn.written().unwrap();
|
||||
assert_eq!(&data[..], exp);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "encode")]
|
||||
fn send_utf8() {
|
||||
let conn = Connection::new(buf_empty(), Vec::new());
|
||||
assert!(conn.send(PRIVMSG("test".to_owned(), "€ŠšŽžŒœŸ".to_owned()), "UTF-8").is_ok());
|
||||
let data = UTF_8.decode(&conn.writer(), DecoderTrap::Strict).unwrap();
|
||||
let conn = MockConnection::empty();
|
||||
assert!(send_to(&conn, PRIVMSG("test".to_owned(), "€ŠšŽžŒœŸ".to_owned()), "UTF-8").is_ok());
|
||||
let data = conn.written("UTF-8").unwrap();
|
||||
assert_eq!(&data[..], "PRIVMSG test :€ŠšŽžŒœŸ\r\n");
|
||||
}
|
||||
|
||||
|
@ -350,18 +386,18 @@ mod test {
|
|||
#[cfg(feature = "encode")]
|
||||
fn send_utf8_str() {
|
||||
let exp = "PRIVMSG test :€ŠšŽžŒœŸ\r\n";
|
||||
let conn = Connection::new(buf_empty(), Vec::new());
|
||||
assert!(conn.send(exp, "UTF-8").is_ok());
|
||||
let data = UTF_8.decode(&conn.writer(), DecoderTrap::Strict).unwrap();
|
||||
let conn = MockConnection::empty();
|
||||
assert!(send_to(&conn, exp, "UTF-8").is_ok());
|
||||
let data = conn.written("UTF-8").unwrap();
|
||||
assert_eq!(&data[..], exp);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "encode")]
|
||||
fn send_iso885915() {
|
||||
let conn = Connection::new(buf_empty(), Vec::new());
|
||||
assert!(conn.send(PRIVMSG("test".to_owned(), "€ŠšŽžŒœŸ".to_owned()), "l9").is_ok());
|
||||
let data = ISO_8859_15.decode(&conn.writer(), DecoderTrap::Strict).unwrap();
|
||||
let conn = MockConnection::empty();
|
||||
assert!(send_to(&conn, PRIVMSG("test".to_owned(), "€ŠšŽžŒœŸ".to_owned()), "l9").is_ok());
|
||||
let data = conn.written("l9").unwrap();
|
||||
assert_eq!(&data[..], "PRIVMSG test :€ŠšŽžŒœŸ\r\n");
|
||||
}
|
||||
|
||||
|
@ -369,27 +405,23 @@ mod test {
|
|||
#[cfg(feature = "encode")]
|
||||
fn send_iso885915_str() {
|
||||
let exp = "PRIVMSG test :€ŠšŽžŒœŸ\r\n";
|
||||
let conn = Connection::new(buf_empty(), Vec::new());
|
||||
assert!(conn.send(exp, "l9").is_ok());
|
||||
let data = ISO_8859_15.decode(&conn.writer(), DecoderTrap::Strict).unwrap();
|
||||
let conn = MockConnection::empty();
|
||||
assert!(send_to(&conn, exp, "l9").is_ok());
|
||||
let data = conn.written("l9").unwrap();
|
||||
assert_eq!(&data[..], exp);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(feature = "encode"))]
|
||||
fn recv() {
|
||||
let conn = Connection::new(
|
||||
Cursor::new("PRIVMSG test :Testing!\r\n".as_bytes().to_vec()), sink()
|
||||
);
|
||||
let conn = MockConnection::new("PRIVMSG test :Testing!\r\n");
|
||||
assert_eq!(&conn.recv().unwrap()[..], "PRIVMSG test :Testing!\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "encode")]
|
||||
fn recv_utf8() {
|
||||
let conn = Connection::new(
|
||||
Cursor::new(b"PRIVMSG test :Testing!\r\n".to_vec()), sink()
|
||||
);
|
||||
let conn = MockConnection::new("PRIVMSG test :Testing!\r\n");
|
||||
assert_eq!(&conn.recv("UTF-8").unwrap()[..], "PRIVMSG test :Testing!\r\n");
|
||||
}
|
||||
|
||||
|
@ -397,13 +429,13 @@ mod test {
|
|||
#[cfg(feature = "encode")]
|
||||
fn recv_iso885915() {
|
||||
let data = [0xA4, 0xA6, 0xA8, 0xB4, 0xB8, 0xBC, 0xBD, 0xBE];
|
||||
let conn = Connection::new(Cursor::new({
|
||||
let conn = MockConnection::from_byte_vec({
|
||||
let mut vec = Vec::new();
|
||||
vec.extend("PRIVMSG test :".as_bytes());
|
||||
vec.extend(data.iter());
|
||||
vec.extend("\r\n".as_bytes());
|
||||
vec.into_iter().collect::<Vec<_>>()
|
||||
}), sink());
|
||||
});
|
||||
assert_eq!(&conn.recv("l9").unwrap()[..], "PRIVMSG test :€ŠšŽžŒœŸ\r\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,3 @@ pub mod prelude {
|
|||
pub use client::data::{Capability, Command, Config, Message, NegotiationVersion, Response};
|
||||
pub use client::data::kinds::{IrcRead, IrcWrite};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod test {
|
||||
use std::io::{BufReader, Empty, empty};
|
||||
|
||||
pub fn buf_empty() -> BufReader<Empty> {
|
||||
BufReader::new(empty())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -413,6 +413,22 @@ impl IrcServer {
|
|||
fn handle_ctcp(&self, _: &str, _: Vec<&str>) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Waits for the completion of all writes for messages in this server's write queue. This
|
||||
/// function may cause unusual behavior when called on a server with operations being performed
|
||||
/// on other threads. This function is destructive, and is primarily intended for writing unit
|
||||
/// tests. Use it with care.
|
||||
pub fn await_writing(&mut self) {
|
||||
let _ = self.state.tx.lock().unwrap().take();
|
||||
// This is a terrible hack to get the real channel to drop.
|
||||
// Otherwise, joining would never finish.
|
||||
let (tx, _) = channel();
|
||||
self.tx = tx;
|
||||
let mut guard = self.state.write_handle.lock().unwrap();
|
||||
if let Some(handle) = guard.take() {
|
||||
handle.join().unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An Iterator over an IrcServer's incoming Messages.
|
||||
|
@ -470,13 +486,10 @@ impl<'a> Iterator for ServerIterator<'a> {
|
|||
mod test {
|
||||
use super::{IrcServer, Server};
|
||||
use std::default::Default;
|
||||
use std::io::{Cursor, sink};
|
||||
use client::conn::{Connection, Reconnect};
|
||||
use client::conn::MockConnection;
|
||||
use client::data::Config;
|
||||
#[cfg(not(feature = "nochanlists"))] use client::data::User;
|
||||
use client::data::command::Command::PRIVMSG;
|
||||
use client::data::kinds::IrcRead;
|
||||
use client::test::buf_empty;
|
||||
|
||||
pub fn test_config() -> Config {
|
||||
Config {
|
||||
|
@ -490,18 +503,23 @@ mod test {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_server_value<T: IrcRead>(server: IrcServer<T, Vec<u8>>) -> String
|
||||
where Connection<T, Vec<u8>>: Reconnect {
|
||||
String::from_utf8(server.extract_writer()).unwrap()
|
||||
#[cfg(feature = "encode")]
|
||||
pub fn get_server_value(mut server: IrcServer) -> String {
|
||||
server.await_writing();
|
||||
server.conn().written(server.config().encoding()).unwrap()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "encode"))]
|
||||
pub fn get_server_value(mut server: IrcServer) -> String {
|
||||
server.await_writing();
|
||||
server.conn().written().unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn iterator() {
|
||||
let exp = "PRIVMSG test :Hi!\r\nPRIVMSG test :This is a test!\r\n\
|
||||
:test!test@test JOIN #test\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(exp.as_bytes().to_vec()), sink()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(exp));
|
||||
let mut messages = String::new();
|
||||
for message in server.iter() {
|
||||
messages.push_str(&message.unwrap().into_string());
|
||||
|
@ -512,9 +530,7 @@ mod test {
|
|||
#[test]
|
||||
fn handle_message() {
|
||||
let value = "PING :irc.test.net\r\n:irc.test.net 376 test :End of /MOTD command.\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -529,9 +545,7 @@ mod test {
|
|||
nick_password: Some(format!("password")),
|
||||
channels: Some(vec![format!("#test"), format!("#test2")]),
|
||||
.. Default::default()
|
||||
}, Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
}, MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -550,9 +564,7 @@ mod test {
|
|||
channels: Some(vec![format!("#test"), format!("#test2")]),
|
||||
should_ghost: Some(true),
|
||||
.. Default::default()
|
||||
}, Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
}, MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -572,9 +584,7 @@ mod test {
|
|||
should_ghost: Some(true),
|
||||
ghost_sequence: Some(vec![format!("RECOVER"), format!("RELEASE")]),
|
||||
.. Default::default()
|
||||
}, Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
}, MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -590,9 +600,7 @@ mod test {
|
|||
umodes: Some(format!("+B")),
|
||||
channels: Some(vec![format!("#test"), format!("#test2")]),
|
||||
.. Default::default()
|
||||
}, Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
}, MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -603,9 +611,7 @@ mod test {
|
|||
#[test]
|
||||
fn nickname_in_use() {
|
||||
let value = ":irc.pdgn.co 433 * test :Nickname is already in use.";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -617,9 +623,7 @@ mod test {
|
|||
fn ran_out_of_nicknames() {
|
||||
let value = ":irc.pdgn.co 433 * test :Nickname is already in use.\r\n\
|
||||
:irc.pdgn.co 433 * test2 :Nickname is already in use.\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -627,9 +631,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn send() {
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
buf_empty(), Vec::new()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
assert!(server.send(PRIVMSG(format!("#test"), format!("Hi there!"))).is_ok());
|
||||
assert_eq!(&get_server_value(server)[..], "PRIVMSG #test :Hi there!\r\n");
|
||||
}
|
||||
|
@ -638,9 +640,7 @@ mod test {
|
|||
#[cfg(not(feature = "nochanlists"))]
|
||||
fn user_tracking_names() {
|
||||
let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), sink()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -653,9 +653,7 @@ mod test {
|
|||
fn user_tracking_names_join() {
|
||||
let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n\
|
||||
:test2!test@test JOIN #test\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), sink()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -668,9 +666,7 @@ mod test {
|
|||
fn user_tracking_names_part() {
|
||||
let value = ":irc.test.net 353 test = #test :test ~owner &admin\r\n\
|
||||
:owner!test@test PART #test\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), sink()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -683,9 +679,7 @@ mod test {
|
|||
fn user_tracking_names_mode() {
|
||||
let value = ":irc.test.net 353 test = #test :+test ~owner &admin\r\n\
|
||||
:test!test@test MODE #test +o test\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), sink()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -706,9 +700,7 @@ mod test {
|
|||
#[cfg(feature = "nochanlists")]
|
||||
fn no_user_tracking() {
|
||||
let value = ":irc.test.net 353 test = #test :test ~owner &admin";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), sink()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -719,9 +711,7 @@ mod test {
|
|||
#[cfg(feature = "ctcp")]
|
||||
fn finger_response() {
|
||||
let value = ":test!test@test PRIVMSG test :\u{001}FINGER\u{001}\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -733,9 +723,7 @@ mod test {
|
|||
#[cfg(feature = "ctcp")]
|
||||
fn version_response() {
|
||||
let value = ":test!test@test PRIVMSG test :\u{001}VERSION\u{001}\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -747,9 +735,7 @@ mod test {
|
|||
#[cfg(feature = "ctcp")]
|
||||
fn source_response() {
|
||||
let value = ":test!test@test PRIVMSG test :\u{001}SOURCE\u{001}\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -762,9 +748,7 @@ mod test {
|
|||
#[cfg(feature = "ctcp")]
|
||||
fn ctcp_ping_response() {
|
||||
let value = ":test!test@test PRIVMSG test :\u{001}PING test\u{001}\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -775,9 +759,7 @@ mod test {
|
|||
#[cfg(feature = "ctcp")]
|
||||
fn time_response() {
|
||||
let value = ":test!test@test PRIVMSG test :\u{001}TIME\u{001}\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
@ -790,9 +772,7 @@ mod test {
|
|||
#[cfg(feature = "ctcp")]
|
||||
fn user_info_response() {
|
||||
let value = ":test!test@test PRIVMSG test :\u{001}USERINFO\u{001}\r\n";
|
||||
let server = IrcServer::from_connection(test_config(), Connection::new(
|
||||
Cursor::new(value.as_bytes().to_vec()), Vec::new()
|
||||
));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::new(value));
|
||||
for message in server.iter() {
|
||||
println!("{:?}", message);
|
||||
}
|
||||
|
|
|
@ -224,16 +224,14 @@ impl<S> ServerExt for S where S: Server {}
|
|||
mod test {
|
||||
use super::ServerExt;
|
||||
use std::default::Default;
|
||||
use client::conn::Connection;
|
||||
use client::conn::MockConnection;
|
||||
use client::data::Config;
|
||||
use client::server::IrcServer;
|
||||
use client::server::test::{get_server_value, test_config};
|
||||
use client::test::buf_empty;
|
||||
|
||||
#[test]
|
||||
fn identify() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.identify().unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "CAP END\r\nNICK :test\r\n\
|
||||
USER test 0 * :test\r\n");
|
||||
|
@ -245,7 +243,7 @@ mod test {
|
|||
nickname: Some(format!("test")),
|
||||
password: Some(format!("password")),
|
||||
.. Default::default()
|
||||
}, Connection::new(buf_empty(), Vec::new()));
|
||||
}, MockConnection::empty());
|
||||
server.identify().unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "CAP END\r\nPASS :password\r\nNICK :test\r\n\
|
||||
USER test 0 * :test\r\n");
|
||||
|
@ -253,128 +251,112 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn send_pong() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_pong("irc.test.net").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "PONG :irc.test.net\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_join() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_join("#test,#test2,#test3").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "JOIN #test,#test2,#test3\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_oper() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_oper("test", "test").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "OPER test :test\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_privmsg() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_privmsg("#test", "Hi, everybody!").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "PRIVMSG #test :Hi, everybody!\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_notice() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_notice("#test", "Hi, everybody!").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "NOTICE #test :Hi, everybody!\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_topic_no_topic() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_topic("#test", "").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "TOPIC #test\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_topic() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_topic("#test", "Testing stuff.").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "TOPIC #test :Testing stuff.\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_kill() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_kill("test", "Testing kills.").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "KILL test :Testing kills.\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_kick_no_message() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_kick("#test", "test", "").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "KICK #test test\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_kick() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_kick("#test", "test", "Testing kicks.").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "KICK #test test :Testing kicks.\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_mode_no_modeparams() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_mode("#test", "+i", "").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "MODE #test +i\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_mode() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_mode("#test", "+o", "test").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "MODE #test +o test\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_samode_no_modeparams() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_samode("#test", "+i", "").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "SAMODE #test +i\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_samode() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_samode("#test", "+o", "test").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "SAMODE #test +o test\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_sanick() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_sanick("test", "test2").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "SANICK test test2\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn send_invite() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_invite("test", "#test").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "INVITE test #test\r\n");
|
||||
}
|
||||
|
@ -382,8 +364,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_ctcp() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_ctcp("test", "MESSAGE").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "PRIVMSG test :\u{001}MESSAGE\u{001}\r\n");
|
||||
}
|
||||
|
@ -391,8 +372,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_action() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_action("test", "tests.").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "PRIVMSG test :\u{001}ACTION tests.\u{001}\r\n");
|
||||
}
|
||||
|
@ -400,8 +380,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_finger() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_finger("test").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "PRIVMSG test :\u{001}FINGER\u{001}\r\n");
|
||||
}
|
||||
|
@ -409,8 +388,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_version() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_version("test").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "PRIVMSG test :\u{001}VERSION\u{001}\r\n");
|
||||
}
|
||||
|
@ -418,8 +396,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_source() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_source("test").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "PRIVMSG test :\u{001}SOURCE\u{001}\r\n");
|
||||
}
|
||||
|
@ -427,8 +404,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_user_info() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_user_info("test").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "PRIVMSG test :\u{001}USERINFO\u{001}\r\n");
|
||||
}
|
||||
|
@ -436,8 +412,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_ctcp_ping() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_ctcp_ping("test").unwrap();
|
||||
let val = get_server_value(server);
|
||||
println!("{}", val);
|
||||
|
@ -448,8 +423,7 @@ mod test {
|
|||
#[test]
|
||||
#[cfg(feature = "ctcp")]
|
||||
fn send_time() {
|
||||
let server = IrcServer::from_connection(test_config(),
|
||||
Connection::new(buf_empty(), Vec::new()));
|
||||
let server = IrcServer::from_connection(test_config(), MockConnection::empty());
|
||||
server.send_time("test").unwrap();
|
||||
assert_eq!(&get_server_value(server)[..], "PRIVMSG test :\u{001}TIME\u{001}\r\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue