summaryrefslogtreecommitdiffstats
path: root/third_party/rust/oneshot-uniffi/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:50 +0000
commitdef92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch)
tree2ef34b9ad8bb9a9220e05d60352558b15f513894 /third_party/rust/oneshot-uniffi/tests
parentAdding debian version 125.0.3-1. (diff)
downloadfirefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz
firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/oneshot-uniffi/tests')
-rw-r--r--third_party/rust/oneshot-uniffi/tests/raw.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/third_party/rust/oneshot-uniffi/tests/raw.rs b/third_party/rust/oneshot-uniffi/tests/raw.rs
new file mode 100644
index 0000000000..e38dc45c48
--- /dev/null
+++ b/third_party/rust/oneshot-uniffi/tests/raw.rs
@@ -0,0 +1,46 @@
+#![cfg(not(loom))]
+
+use oneshot::{channel, Receiver, Sender};
+
+#[test]
+fn test_raw_sender() {
+ let (sender, receiver) = channel::<u32>();
+ let raw = sender.into_raw();
+ let recreated = unsafe { Sender::<u32>::from_raw(raw) };
+ recreated
+ .send(100)
+ .unwrap_or_else(|e| panic!("error sending after into_raw/from_raw roundtrip: {e}"));
+ assert_eq!(receiver.try_recv(), Ok(100))
+}
+
+#[test]
+fn test_raw_receiver() {
+ let (sender, receiver) = channel::<u32>();
+ let raw = receiver.into_raw();
+ sender.send(100).unwrap();
+ let recreated = unsafe { Receiver::<u32>::from_raw(raw) };
+ assert_eq!(
+ recreated
+ .try_recv()
+ .unwrap_or_else(|e| panic!("error receiving after into_raw/from_raw roundtrip: {e}")),
+ 100
+ )
+}
+
+#[test]
+fn test_raw_sender_and_receiver() {
+ let (sender, receiver) = channel::<u32>();
+ let raw_receiver = receiver.into_raw();
+ let raw_sender = sender.into_raw();
+
+ let recreated_sender = unsafe { Sender::<u32>::from_raw(raw_sender) };
+ recreated_sender.send(100).unwrap();
+
+ let recreated_receiver = unsafe { Receiver::<u32>::from_raw(raw_receiver) };
+ assert_eq!(
+ recreated_receiver
+ .try_recv()
+ .unwrap_or_else(|e| panic!("error receiving after into_raw/from_raw roundtrip: {e}")),
+ 100
+ )
+}