From c2ffb6c255bf0533f80a3b6cbad066977b812da7 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Sat, 26 Mar 2016 19:04:12 +0300 Subject: [PATCH 1/3] test socket to common test tools --- ipc/tests/socket.rs => devtools/src/test_socket.rs | 0 ipc/tests/Cargo.toml | 1 + ipc/tests/examples.rs | 2 +- ipc/tests/run.rs | 2 +- 4 files changed, 3 insertions(+), 2 deletions(-) rename ipc/tests/socket.rs => devtools/src/test_socket.rs (100%) diff --git a/ipc/tests/socket.rs b/devtools/src/test_socket.rs similarity index 100% rename from ipc/tests/socket.rs rename to devtools/src/test_socket.rs diff --git a/ipc/tests/Cargo.toml b/ipc/tests/Cargo.toml index a4d07ae57..1d2bc35b4 100644 --- a/ipc/tests/Cargo.toml +++ b/ipc/tests/Cargo.toml @@ -11,6 +11,7 @@ path = "run.rs" "ethcore-ipc" = { path = "../rpc" } bincode = "*" serde = "0.7.0" +ethcore-devtools = { path = "../../devtools" } [build-dependencies] syntex = "0.30.0" diff --git a/ipc/tests/examples.rs b/ipc/tests/examples.rs index 5a6fc69bf..280e25d08 100644 --- a/ipc/tests/examples.rs +++ b/ipc/tests/examples.rs @@ -17,9 +17,9 @@ #[cfg(test)] mod tests { - use super::super::socket::*; use super::super::service::*; use ipc::*; + use devtools::*; #[test] fn call_service() { diff --git a/ipc/tests/run.rs b/ipc/tests/run.rs index 187b52d9d..7aac809ed 100644 --- a/ipc/tests/run.rs +++ b/ipc/tests/run.rs @@ -17,7 +17,7 @@ extern crate bincode; extern crate ethcore_ipc as ipc; extern crate serde; +extern crate ethcore_devtools as devtools; -pub mod socket; pub mod service; mod examples; From 579d41b17434a0e83c9e4c6fd9d3bd8080a56622 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Sat, 26 Mar 2016 19:04:42 +0300 Subject: [PATCH 2/3] fix lib --- devtools/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/devtools/src/lib.rs b/devtools/src/lib.rs index f310cca30..3ab585d93 100644 --- a/devtools/src/lib.rs +++ b/devtools/src/lib.rs @@ -20,5 +20,7 @@ extern crate rand; pub mod random_path; +pub mod test_socket; pub use random_path::*; +pub use test_socket::*; From f9c0e0c1523ffb47ec25378c2d07dc306714bb3e Mon Sep 17 00:00:00 2001 From: NikVolf Date: Sat, 26 Mar 2016 19:08:06 +0300 Subject: [PATCH 3/3] removed from util --- util/src/network/connection.rs | 69 +--------------------------------- 1 file changed, 1 insertion(+), 68 deletions(-) diff --git a/util/src/network/connection.rs b/util/src/network/connection.rs index a560c1a91..02c0e2cde 100644 --- a/util/src/network/connection.rs +++ b/util/src/network/connection.rs @@ -501,77 +501,10 @@ mod tests { use std::sync::*; use super::super::stats::*; use std::io::{Read, Write, Error, Cursor, ErrorKind}; - use std::cmp; use mio::{EventSet}; use std::collections::VecDeque; use bytes::*; - - struct TestSocket { - read_buffer: Vec, - write_buffer: Vec, - cursor: usize, - buf_size: usize, - } - - impl Default for TestSocket { - fn default() -> Self { - TestSocket::new() - } - } - - impl TestSocket { - fn new() -> Self { - TestSocket { - read_buffer: vec![], - write_buffer: vec![], - cursor: 0, - buf_size: 0, - } - } - - fn new_buf(buf_size: usize) -> TestSocket { - TestSocket { - read_buffer: vec![], - write_buffer: vec![], - cursor: 0, - buf_size: buf_size, - } - } - } - - impl Read for TestSocket { - fn read(&mut self, buf: &mut [u8]) -> Result { - let end_position = cmp::min(self.read_buffer.len(), self.cursor+buf.len()); - let len = cmp::max(end_position - self.cursor, 0); - match len { - 0 => Ok(0), - _ => { - for i in self.cursor..end_position { - buf[i-self.cursor] = self.read_buffer[i]; - } - self.cursor = self.cursor + buf.len(); - Ok(len) - } - } - } - } - - impl Write for TestSocket { - fn write(&mut self, buf: &[u8]) -> Result { - if self.buf_size == 0 || buf.len() < self.buf_size { - self.write_buffer.extend(buf.iter().cloned()); - Ok(buf.len()) - } - else { - self.write_buffer.extend(buf.iter().take(self.buf_size).cloned()); - Ok(self.buf_size) - } - } - - fn flush(&mut self) -> Result<(), Error> { - unimplemented!(); - } - } + use devtools::*; impl GenericSocket for TestSocket {}