diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /third_party/rust/neqo-http3/src/frames/tests/mod.rs | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/neqo-http3/src/frames/tests/mod.rs')
-rw-r--r-- | third_party/rust/neqo-http3/src/frames/tests/mod.rs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/third_party/rust/neqo-http3/src/frames/tests/mod.rs b/third_party/rust/neqo-http3/src/frames/tests/mod.rs new file mode 100644 index 0000000000..33eea5497a --- /dev/null +++ b/third_party/rust/neqo-http3/src/frames/tests/mod.rs @@ -0,0 +1,84 @@ +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::mem; + +use neqo_common::Encoder; +use neqo_crypto::AuthenticationStatus; +use neqo_transport::StreamType; +use test_fixture::{default_client, default_server, now}; + +use crate::frames::{ + reader::FrameDecoder, FrameReader, HFrame, StreamReaderConnectionWrapper, WebTransportFrame, +}; + +#[allow(clippy::many_single_char_names)] +pub(crate) fn enc_dec<T: FrameDecoder<T>>(d: &Encoder, st: &str, remaining: usize) -> T { + // For data, headers and push_promise we do not read all bytes from the buffer + let d2 = Encoder::from_hex(st); + assert_eq!(d.as_ref(), &d2.as_ref()[..d.as_ref().len()]); + + let mut conn_c = default_client(); + let mut conn_s = default_server(); + let out = conn_c.process(None, now()); + let out = conn_s.process(out.as_dgram_ref(), now()); + let out = conn_c.process(out.as_dgram_ref(), now()); + mem::drop(conn_s.process(out.as_dgram_ref(), now())); + conn_c.authenticated(AuthenticationStatus::Ok, now()); + let out = conn_c.process(None, now()); + mem::drop(conn_s.process(out.as_dgram_ref(), now())); + + // create a stream + let stream_id = conn_s.stream_create(StreamType::BiDi).unwrap(); + + let mut fr: FrameReader = FrameReader::new(); + + // conver string into u8 vector + let buf = Encoder::from_hex(st); + conn_s.stream_send(stream_id, buf.as_ref()).unwrap(); + let out = conn_s.process(None, now()); + mem::drop(conn_c.process(out.as_dgram_ref(), now())); + + let (frame, fin) = fr + .receive::<T>(&mut StreamReaderConnectionWrapper::new( + &mut conn_c, + stream_id, + )) + .unwrap(); + assert!(!fin); + assert!(frame.is_some()); + + // Check remaining data. + let mut buf = [0_u8; 100]; + let (amount, _) = conn_c.stream_recv(stream_id, &mut buf).unwrap(); + assert_eq!(amount, remaining); + + frame.unwrap() +} + +pub fn enc_dec_hframe(f: &HFrame, st: &str, remaining: usize) { + let mut d = Encoder::default(); + + f.encode(&mut d); + + let frame = enc_dec::<HFrame>(&d, st, remaining); + + assert_eq!(*f, frame); +} + +pub fn enc_dec_wtframe(f: &WebTransportFrame, st: &str, remaining: usize) { + let mut d = Encoder::default(); + + f.encode(&mut d); + + let frame = enc_dec::<WebTransportFrame>(&d, st, remaining); + + assert_eq!(*f, frame); +} + +mod hframe; +mod reader; +mod wtframe; |