Expose Codec via an unstable flag (#49)

Exposes `Codec` using an unstable flag. This is useful for testing.
This commit is contained in:
Carl Lerche
2017-09-03 16:17:05 -07:00
committed by GitHub
parent c122e97127
commit 88d1de2da0
33 changed files with 222 additions and 85 deletions

17
tests/support/Cargo.toml Normal file
View File

@@ -0,0 +1,17 @@
[package]
name = "h2-test-support"
version = "0.1.0"
authors = ["Carl Lerche <me@carllerche.com>"]
[dependencies]
futures = "0.1"
tokio-io = "0.1"
bytes = "0.4"
http = { git = "https://github.com/carllerche/http", rev = "2dd15d9" }
env_logger = "0.4"
mock-io = { git = "https://github.com/carllerche/mock-io", branch = "experiments" }
[dependencies.h2]
path = "../.."
features = ["unstable"]

3
tests/support/README.md Normal file
View File

@@ -0,0 +1,3 @@
**This is not a real crate**
You should not use this crate, it only exists to work around cargo limitations.

View File

@@ -0,0 +1,64 @@
#[macro_export]
macro_rules! assert_closed {
($transport:expr) => {{
assert_eq!($transport.poll().unwrap(), None.into());
}}
}
#[macro_export]
macro_rules! poll_data {
($transport:expr) => {{
use h2::frame::Frame;
use futures::Async;
match $transport.poll() {
Ok(Async::Ready(Some(Frame::Data(frame)))) => frame,
frame => panic!("expected data frame; actual={:?}", frame),
}
}}
}
#[macro_export]
macro_rules! raw_codec {
(
$(
$fn:ident => [$($chunk:expr,)+];
)*
) => {{
let mut b = $crate::mock_io::Builder::new();
$({
let mut chunk = vec![];
$(
$crate::codec::Chunk::push(&$chunk, &mut chunk);
)+
b.$fn(&chunk[..]);
})*
$crate::Codec::new(b.build())
}}
}
pub trait Chunk {
fn push(&self, dst: &mut Vec<u8>);
}
impl Chunk for u8 {
fn push(&self, dst: &mut Vec<u8>) {
dst.push(*self);
}
}
impl<'a> Chunk for &'a [u8] {
fn push(&self, dst: &mut Vec<u8>) {
dst.extend(*self)
}
}
impl<'a> Chunk for &'a str {
fn push(&self, dst: &mut Vec<u8>) {
dst.extend(self.as_bytes())
}
}

View File

@@ -1,7 +1,5 @@
//! Utilities to support tests.
#![allow(unused_extern_crates)]
pub extern crate bytes;
pub extern crate h2;
pub extern crate http;
@@ -10,6 +8,9 @@ pub extern crate futures;
pub extern crate mock_io;
pub extern crate env_logger;
#[macro_use]
pub mod codec;
pub use self::futures::{
Future,
Sink,
@@ -27,8 +28,11 @@ pub use self::http::{
HeaderMap,
};
pub use self::h2::*;
pub use self::h2::client::{self, Client};
// pub use self::h2::server;
pub use self::h2::server::{self, Server};
pub type Codec<T> = h2::Codec<T, ::std::io::Cursor<::bytes::Bytes>>;
pub use self::bytes::{
Buf,