summaryrefslogtreecommitdiffstats
path: root/third_party/rust/neqo-http3/src/frames/tests/hframe.rs
blob: 54b7c94c8e3d7de1bedd4df7b996878ae466dc07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// 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 super::enc_dec_hframe;
use crate::{
    frames::HFrame,
    settings::{HSetting, HSettingType, HSettings},
    Priority,
};
use neqo_common::{Decoder, Encoder};
use neqo_transport::StreamId;
use test_fixture::fixture_init;

#[test]
fn test_data_frame() {
    let f = HFrame::Data { len: 3 };
    enc_dec_hframe(&f, "0003010203", 3);
}

#[test]
fn test_headers_frame() {
    let f = HFrame::Headers {
        header_block: vec![0x01, 0x02, 0x03],
    };
    enc_dec_hframe(&f, "0103010203", 0);
}

#[test]
fn test_cancel_push_frame4() {
    let f = HFrame::CancelPush { push_id: 5 };
    enc_dec_hframe(&f, "030105", 0);
}

#[test]
fn test_settings_frame4() {
    let f = HFrame::Settings {
        settings: HSettings::new(&[HSetting::new(HSettingType::MaxHeaderListSize, 4)]),
    };
    enc_dec_hframe(&f, "04020604", 0);
}

#[test]
fn test_push_promise_frame4() {
    let f = HFrame::PushPromise {
        push_id: 4,
        header_block: vec![0x61, 0x62, 0x63, 0x64],
    };
    enc_dec_hframe(&f, "05050461626364", 0);
}

#[test]
fn test_goaway_frame4() {
    let f = HFrame::Goaway {
        stream_id: StreamId::new(5),
    };
    enc_dec_hframe(&f, "070105", 0);
}

#[test]
fn grease() {
    fn make_grease() -> u64 {
        let mut enc = Encoder::default();
        HFrame::Grease.encode(&mut enc);
        let mut dec = Decoder::from(&enc);
        let ft = dec.decode_varint().unwrap();
        assert_eq!((ft - 0x21) % 0x1f, 0);
        let body = dec.decode_vvec().unwrap();
        assert!(body.len() <= 7);
        ft
    }

    fixture_init();
    let t1 = make_grease();
    let t2 = make_grease();
    assert_ne!(t1, t2);
}

#[test]
fn test_priority_update_request_default() {
    let f = HFrame::PriorityUpdateRequest {
        element_id: 6,
        priority: Priority::default(),
    };
    enc_dec_hframe(&f, "800f07000106", 0);
}

#[test]
fn test_priority_update_request_incremental_default() {
    let f = HFrame::PriorityUpdateRequest {
        element_id: 7,
        priority: Priority::new(6, false),
    };
    enc_dec_hframe(&f, "800f07000407753d36", 0); // "u=6"
}

#[test]
fn test_priority_update_request_urgency_default() {
    let f = HFrame::PriorityUpdateRequest {
        element_id: 8,
        priority: Priority::new(3, true),
    };
    enc_dec_hframe(&f, "800f0700020869", 0); // "i"
}

#[test]
fn test_priority_update_push_default() {
    let f = HFrame::PriorityUpdatePush {
        element_id: 10,
        priority: Priority::default(),
    };
    enc_dec_hframe(&f, "800f0701010a", 0);
}