|
1 | 1 | //! Port of the pty project's `tests/protocol.test.ts`. |
2 | 2 |
|
3 | 3 | use pty_core::protocol::{ |
4 | | - MAX_PACKET_LENGTH, MessageType, PacketReader, decode_exit, decode_geometry, decode_size, |
5 | | - encode_attach, encode_data, encode_detach, encode_exit, encode_geometry, encode_packet, |
6 | | - encode_resize, encode_screen, encode_status, encode_status_response, |
| 4 | + MAX_PACKET_LENGTH, MessageType, PacketReader, decode_cell, decode_exit, decode_geometry, |
| 5 | + decode_size, encode_attach, encode_attach_with_cell, encode_data, encode_detach, encode_exit, |
| 6 | + encode_geometry, encode_packet, encode_resize, encode_resize_with_cell, encode_screen, |
| 7 | + encode_status, encode_status_response, |
7 | 8 | }; |
8 | 9 | use pty_core::stats::{ClientStats, ConnectionStats, Constrains, StatsResult}; |
9 | 10 |
|
@@ -36,6 +37,50 @@ fn attach_byte_identical_to_hand_built_packet() { |
36 | 37 | ); |
37 | 38 | } |
38 | 39 |
|
| 40 | +/// The cell pixel size is an optional suffix on a size payload: a reader that |
| 41 | +/// does not know about it takes the same rows and cols it always did, which |
| 42 | +/// is what makes this safe to send to any daemon. |
| 43 | +#[test] |
| 44 | +fn attach_can_declare_a_cell_size_without_changing_the_size_it_carries() { |
| 45 | + let with_cell = encode_attach_with_cell(24, 80, 9, 18); |
| 46 | + assert_eq!( |
| 47 | + with_cell, |
| 48 | + encode_packet(MessageType::Attach, &[0, 24, 0, 80, 0, 9, 0, 18]) |
| 49 | + ); |
| 50 | + |
| 51 | + let mut reader = PacketReader::new(); |
| 52 | + let packets = reader.feed(&with_cell).unwrap(); |
| 53 | + assert_eq!(packets[0].type_, MessageType::Attach); |
| 54 | + assert_eq!( |
| 55 | + decode_size(&packets[0].payload), |
| 56 | + (24, 80), |
| 57 | + "the size is where it always was" |
| 58 | + ); |
| 59 | + assert_eq!(decode_cell(&packets[0].payload), Some((9, 18))); |
| 60 | +} |
| 61 | + |
| 62 | +#[test] |
| 63 | +fn resize_can_declare_a_cell_size() { |
| 64 | + let mut reader = PacketReader::new(); |
| 65 | + let packets = reader.feed(&encode_resize_with_cell(30, 100, 7, 15)).unwrap(); |
| 66 | + assert_eq!(packets[0].type_, MessageType::Resize); |
| 67 | + assert_eq!(decode_size(&packets[0].payload), (30, 100)); |
| 68 | + assert_eq!(decode_cell(&packets[0].payload), Some((7, 15))); |
| 69 | +} |
| 70 | + |
| 71 | +/// No declaration is the normal case, and it must not be mistaken for one. |
| 72 | +#[test] |
| 73 | +fn a_plain_size_payload_declares_no_cell() { |
| 74 | + assert_eq!(decode_cell(&encode_attach(24, 80)[5..]), None); |
| 75 | + assert_eq!(decode_cell(&encode_resize(24, 80)[5..]), None); |
| 76 | + assert_eq!(decode_cell(&[]), None); |
| 77 | + assert_eq!( |
| 78 | + decode_cell(&[0, 24, 0, 80, 0, 0, 0, 0]), |
| 79 | + None, |
| 80 | + "a zero cell is no cell" |
| 81 | + ); |
| 82 | +} |
| 83 | + |
39 | 84 | /// node: tests/protocol.test.ts:288-297 |
40 | 85 | #[test] |
41 | 86 | fn round_trips_geometry() { |
|
0 commit comments