/src/h2/tests/h2-support/src/assert.rs
Line | Count | Source |
1 | | #[macro_export] |
2 | | macro_rules! assert_closed { |
3 | | ($transport:expr) => {{ |
4 | | use futures::StreamExt; |
5 | | |
6 | | assert!($transport.next().await.is_none()); |
7 | | }}; |
8 | | } |
9 | | |
10 | | #[macro_export] |
11 | | macro_rules! assert_headers { |
12 | | ($frame:expr) => {{ |
13 | | match $frame { |
14 | | h2::frame::Frame::Headers(v) => v, |
15 | | f => panic!("expected HEADERS; actual={:?}", f), |
16 | | } |
17 | | }}; |
18 | | } |
19 | | |
20 | | #[macro_export] |
21 | | macro_rules! assert_data { |
22 | | ($frame:expr) => {{ |
23 | | match $frame { |
24 | | h2::frame::Frame::Data(v) => v, |
25 | | f => panic!("expected DATA; actual={:?}", f), |
26 | | } |
27 | | }}; |
28 | | } |
29 | | |
30 | | #[macro_export] |
31 | | macro_rules! assert_ping { |
32 | | ($frame:expr) => {{ |
33 | | match $frame { |
34 | | h2::frame::Frame::Ping(v) => v, |
35 | | f => panic!("expected PING; actual={:?}", f), |
36 | | } |
37 | | }}; |
38 | | } |
39 | | |
40 | | #[macro_export] |
41 | | macro_rules! assert_settings { |
42 | | ($frame:expr) => {{ |
43 | | match $frame { |
44 | | h2::frame::Frame::Settings(v) => v, |
45 | | f => panic!("expected SETTINGS; actual={:?}", f), |
46 | | } |
47 | | }}; |
48 | | } |
49 | | |
50 | | #[macro_export] |
51 | | macro_rules! assert_go_away { |
52 | | ($frame:expr) => {{ |
53 | | match $frame { |
54 | | h2::frame::Frame::GoAway(v) => v, |
55 | | f => panic!("expected GO_AWAY; actual={:?}", f), |
56 | | } |
57 | | }}; |
58 | | } |
59 | | |
60 | | #[macro_export] |
61 | | macro_rules! poll_err { |
62 | | ($transport:expr) => {{ |
63 | | use futures::StreamExt; |
64 | | match $transport.next().await { |
65 | | Some(Err(e)) => e, |
66 | | frame => panic!("expected error; actual={:?}", frame), |
67 | | } |
68 | | }}; |
69 | | } |
70 | | |
71 | | #[macro_export] |
72 | | macro_rules! poll_frame { |
73 | | ($type: ident, $transport:expr) => {{ |
74 | | use futures::StreamExt; |
75 | | use h2::frame::Frame; |
76 | | |
77 | | match $transport.next().await { |
78 | | Some(Ok(Frame::$type(frame))) => frame, |
79 | | frame => panic!("unexpected frame; actual={:?}", frame), |
80 | | } |
81 | | }}; |
82 | | } |
83 | | |
84 | | #[macro_export] |
85 | | macro_rules! assert_default_settings { |
86 | | ($settings: expr) => {{ |
87 | | assert_frame_eq($settings, frame::Settings::default()); |
88 | | }}; |
89 | | } |
90 | | |
91 | | use h2::frame::Frame; |
92 | | |
93 | | #[track_caller] |
94 | 0 | pub fn assert_frame_eq<T: Into<Frame>, U: Into<Frame>>(t: T, u: U) { |
95 | 0 | let actual: Frame = t.into(); |
96 | 0 | let expected: Frame = u.into(); |
97 | 0 | match (actual, expected) { |
98 | 0 | (Frame::Data(a), Frame::Data(b)) => { |
99 | 0 | assert_eq!( |
100 | 0 | a.payload().len(), |
101 | 0 | b.payload().len(), |
102 | 0 | "assert_frame_eq data payload len" |
103 | | ); |
104 | 0 | assert_eq!(a, b, "assert_frame_eq"); |
105 | | } |
106 | 0 | (a, b) => { |
107 | 0 | assert_eq!(a, b, "assert_frame_eq"); |
108 | | } |
109 | | } |
110 | 0 | } |