summaryrefslogtreecommitdiffstats
path: root/third_party/rust/tokio/tests/io_split.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/tokio/tests/io_split.rs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/tokio/tests/io_split.rs')
-rw-r--r--third_party/rust/tokio/tests/io_split.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/third_party/rust/tokio/tests/io_split.rs b/third_party/rust/tokio/tests/io_split.rs
new file mode 100644
index 0000000000..a0121667f7
--- /dev/null
+++ b/third_party/rust/tokio/tests/io_split.rs
@@ -0,0 +1,79 @@
+#![warn(rust_2018_idioms)]
+#![cfg(feature = "full")]
+
+use tokio::io::{split, AsyncRead, AsyncWrite, ReadBuf, ReadHalf, WriteHalf};
+
+use std::io;
+use std::pin::Pin;
+use std::task::{Context, Poll};
+
+struct RW;
+
+impl AsyncRead for RW {
+ fn poll_read(
+ self: Pin<&mut Self>,
+ _cx: &mut Context<'_>,
+ buf: &mut ReadBuf<'_>,
+ ) -> Poll<io::Result<()>> {
+ buf.put_slice(&[b'z']);
+ Poll::Ready(Ok(()))
+ }
+}
+
+impl AsyncWrite for RW {
+ fn poll_write(
+ self: Pin<&mut Self>,
+ _cx: &mut Context<'_>,
+ _buf: &[u8],
+ ) -> Poll<Result<usize, io::Error>> {
+ Poll::Ready(Ok(1))
+ }
+
+ fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
+ Poll::Ready(Ok(()))
+ }
+
+ fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
+ Poll::Ready(Ok(()))
+ }
+}
+
+#[test]
+fn is_send_and_sync() {
+ fn assert_bound<T: Send + Sync>() {}
+
+ assert_bound::<ReadHalf<RW>>();
+ assert_bound::<WriteHalf<RW>>();
+}
+
+#[test]
+fn split_stream_id() {
+ let (r1, w1) = split(RW);
+ let (r2, w2) = split(RW);
+ assert!(r1.is_pair_of(&w1));
+ assert!(!r1.is_pair_of(&w2));
+ assert!(r2.is_pair_of(&w2));
+ assert!(!r2.is_pair_of(&w1));
+}
+
+#[test]
+fn unsplit_ok() {
+ let (r, w) = split(RW);
+ r.unsplit(w);
+}
+
+#[test]
+#[should_panic]
+fn unsplit_err1() {
+ let (r, _) = split(RW);
+ let (_, w) = split(RW);
+ r.unsplit(w);
+}
+
+#[test]
+#[should_panic]
+fn unsplit_err2() {
+ let (_, w) = split(RW);
+ let (r, _) = split(RW);
+ r.unsplit(w);
+}