Expose Codec via an unstable flag (#49)
Exposes `Codec` using an unstable flag. This is useful for testing.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[macro_use]
|
||||
pub mod support;
|
||||
use support::*;
|
||||
extern crate h2_test_support;
|
||||
use h2_test_support::*;
|
||||
|
||||
#[test]
|
||||
fn handshake() {
|
||||
|
||||
48
tests/codec_read.rs
Normal file
48
tests/codec_read.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
#[macro_use]
|
||||
extern crate h2_test_support;
|
||||
use h2_test_support::*;
|
||||
|
||||
#[test]
|
||||
fn read_none() {
|
||||
let mut codec = Codec::from(
|
||||
mock_io::Builder::new()
|
||||
.build());
|
||||
|
||||
assert_closed!(codec);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_data_no_padding() {
|
||||
let mut codec = raw_codec! {
|
||||
read => [
|
||||
0, 0, 5, 0, 0, 0, 0, 0, 1,
|
||||
"hello",
|
||||
];
|
||||
};
|
||||
|
||||
let data = poll_data!(codec);
|
||||
assert_eq!(data.stream_id(), 1);
|
||||
assert_eq!(data.payload(), &b"hello"[..]);
|
||||
assert!(!data.is_end_stream());
|
||||
|
||||
assert_closed!(codec);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn read_data_padding() {
|
||||
let mut codec = raw_codec! {
|
||||
read => [
|
||||
0, 0, 11, 0, 0x8, 0, 0, 0, 1,
|
||||
5, // Pad length
|
||||
"hello", // Data
|
||||
"world", // Padding
|
||||
];
|
||||
};
|
||||
|
||||
let data = poll_data!(codec);
|
||||
assert_eq!(data.stream_id(), 1);
|
||||
assert_eq!(data.payload(), &b"hello"[..]);
|
||||
assert!(!data.is_end_stream());
|
||||
|
||||
assert_closed!(codec);
|
||||
}
|
||||
0
tests/codec_write.rs
Normal file
0
tests/codec_write.rs
Normal file
@@ -1,5 +1,5 @@
|
||||
pub mod support;
|
||||
use support::*;
|
||||
extern crate h2_test_support;
|
||||
use h2_test_support::*;
|
||||
|
||||
// In this case, the stream & connection both have capacity, but capacity is not
|
||||
// explicitly requested.
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
pub mod support;
|
||||
use support::*;
|
||||
/*
|
||||
extern crate h2_test_support;
|
||||
use h2_test_support::*;
|
||||
*/
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod support;
|
||||
use support::*;
|
||||
extern crate h2_test_support;
|
||||
use h2_test_support::*;
|
||||
|
||||
#[test]
|
||||
fn single_stream_send_large_body() {
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
extern crate h2;
|
||||
extern crate http;
|
||||
extern crate futures;
|
||||
extern crate mock_io;
|
||||
extern crate env_logger;
|
||||
|
||||
use h2::server::Server;
|
||||
|
||||
use futures::*;
|
||||
extern crate h2_test_support;
|
||||
use h2_test_support::*;
|
||||
|
||||
const SETTINGS: &'static [u8] = &[0, 0, 0, 4, 0, 0, 0, 0, 0];
|
||||
const SETTINGS_ACK: &'static [u8] = &[0, 0, 0, 4, 1, 0, 0, 0, 0];
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[macro_use]
|
||||
pub mod support;
|
||||
use support::*;
|
||||
extern crate h2_test_support;
|
||||
use h2_test_support::*;
|
||||
|
||||
#[test]
|
||||
fn send_recv_headers_only() {
|
||||
|
||||
17
tests/support/Cargo.toml
Normal file
17
tests/support/Cargo.toml
Normal 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
3
tests/support/README.md
Normal 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.
|
||||
64
tests/support/src/codec.rs
Normal file
64
tests/support/src/codec.rs
Normal 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())
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
@@ -1,9 +1,8 @@
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[macro_use]
|
||||
pub mod support;
|
||||
use support::*;
|
||||
extern crate h2_test_support;
|
||||
use h2_test_support::*;
|
||||
|
||||
#[test]
|
||||
fn recv_trailers_only() {
|
||||
|
||||
Reference in New Issue
Block a user