summaryrefslogtreecommitdiffstats
path: root/third_party/rust/podio/tests/io.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/podio/tests/io.rs
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/podio/tests/io.rs')
-rw-r--r--third_party/rust/podio/tests/io.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/third_party/rust/podio/tests/io.rs b/third_party/rust/podio/tests/io.rs
new file mode 100644
index 0000000000..fba75625a4
--- /dev/null
+++ b/third_party/rust/podio/tests/io.rs
@@ -0,0 +1,57 @@
+extern crate podio;
+
+use std::io::{self, Read};
+use podio::ReadPodExt;
+
+struct TestReader {
+ state: Option<io::Result<usize>>,
+}
+
+impl TestReader {
+ fn new(first_return: io::Result<usize>) -> TestReader {
+ TestReader { state: Some(first_return) }
+ }
+
+ fn get(&mut self) -> io::Result<u32> {
+ self.read_u32::<podio::LittleEndian>()
+ }
+
+ fn test(first_return: io::Result<usize>) -> io::Result<u32> {
+ TestReader::new(first_return).get()
+ }
+}
+
+impl Read for TestReader {
+ fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
+ match self.state.take().unwrap_or(Ok(1)) {
+ Ok(n) => {
+ for i in buf.iter_mut().take(n) {
+ *i = 0xA5;
+ }
+ Ok(n)
+ },
+ e @ Err(..) => e,
+ }
+ }
+}
+
+#[test]
+fn interrupted() {
+ // Getting an io::ErrorKind::Interrupted should be retried, and thus succeed
+ let first_read = Err(io::Error::new(io::ErrorKind::Interrupted, "Interrupted"));
+ assert_eq!(TestReader::test(first_read).unwrap(), 0xA5A5A5A5);
+}
+
+#[test]
+fn eof() {
+ // Getting a Ok(0) implies an unexpected EOF
+ let first_read = Ok(0);
+ assert!(TestReader::test(first_read).is_err());
+}
+
+#[test]
+fn err() {
+ // Getting any other error is still an error
+ let first_read = Err(io::Error::new(io::ErrorKind::Other, "Other"));
+ assert!(TestReader::test(first_read).is_err());
+}