Merge pull request #831 from ethcore/test-socket-devtools
Test socket to common test code (ethcore-devtools)
This commit is contained in:
commit
785e9d1be6
@ -20,5 +20,7 @@
|
|||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
|
||||||
pub mod random_path;
|
pub mod random_path;
|
||||||
|
pub mod test_socket;
|
||||||
|
|
||||||
pub use random_path::*;
|
pub use random_path::*;
|
||||||
|
pub use test_socket::*;
|
||||||
|
@ -11,6 +11,7 @@ path = "run.rs"
|
|||||||
"ethcore-ipc" = { path = "../rpc" }
|
"ethcore-ipc" = { path = "../rpc" }
|
||||||
bincode = "*"
|
bincode = "*"
|
||||||
serde = "0.7.0"
|
serde = "0.7.0"
|
||||||
|
ethcore-devtools = { path = "../../devtools" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
syntex = "0.30.0"
|
syntex = "0.30.0"
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::super::socket::*;
|
|
||||||
use super::super::service::*;
|
use super::super::service::*;
|
||||||
use ipc::*;
|
use ipc::*;
|
||||||
|
use devtools::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn call_service() {
|
fn call_service() {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
extern crate bincode;
|
extern crate bincode;
|
||||||
extern crate ethcore_ipc as ipc;
|
extern crate ethcore_ipc as ipc;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
extern crate ethcore_devtools as devtools;
|
||||||
|
|
||||||
pub mod socket;
|
|
||||||
pub mod service;
|
pub mod service;
|
||||||
mod examples;
|
mod examples;
|
||||||
|
@ -501,77 +501,10 @@ mod tests {
|
|||||||
use std::sync::*;
|
use std::sync::*;
|
||||||
use super::super::stats::*;
|
use super::super::stats::*;
|
||||||
use std::io::{Read, Write, Error, Cursor, ErrorKind};
|
use std::io::{Read, Write, Error, Cursor, ErrorKind};
|
||||||
use std::cmp;
|
|
||||||
use mio::{EventSet};
|
use mio::{EventSet};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use bytes::*;
|
use bytes::*;
|
||||||
|
use devtools::*;
|
||||||
struct TestSocket {
|
|
||||||
read_buffer: Vec<u8>,
|
|
||||||
write_buffer: Vec<u8>,
|
|
||||||
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<usize, Error> {
|
|
||||||
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<usize, Error> {
|
|
||||||
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!();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GenericSocket for TestSocket {}
|
impl GenericSocket for TestSocket {}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user