aboutsummaryrefslogtreecommitdiff
path: root/tests/tests.rs
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2020-12-07 17:32:55 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-12-07 17:32:55 +0000
commit850c55d12c61a71b08420cc31429f937e3474a54 (patch)
tree30b3efa938d801f0479e5ea2c6c647c74e60afa1 /tests/tests.rs
parent8ecf69645e5dc06b2d864b8228d1b5b19cefaaf6 (diff)
parent64b7afd4a649f7fcfe117c341f44805c77daa9ab (diff)
downloaduntrusted-850c55d12c61a71b08420cc31429f937e3474a54.tar.gz
untrusted crate v0.7.1 am: 10c89c5856 am: 64b7afd4a6
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/untrusted/+/1517419 Change-Id: Ia98722fefdff15d845f35f777af112c9baf0b216
Diffstat (limited to 'tests/tests.rs')
-rw-r--r--tests/tests.rs98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/tests.rs b/tests/tests.rs
new file mode 100644
index 0000000..087e963
--- /dev/null
+++ b/tests/tests.rs
@@ -0,0 +1,98 @@
+// Copyright 2015-2019 Brian Smith.
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
+// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+#[test]
+fn test_input_from() { let _ = untrusted::Input::from(b"foo"); }
+
+#[test]
+fn test_input_is_empty() {
+ let input = untrusted::Input::from(b"");
+ assert!(input.is_empty());
+ let input = untrusted::Input::from(b"foo");
+ assert!(!input.is_empty());
+}
+
+#[test]
+fn test_input_len() {
+ let input = untrusted::Input::from(b"foo");
+ assert_eq!(input.len(), 3);
+}
+
+#[test]
+fn test_input_read_all() {
+ let input = untrusted::Input::from(b"foo");
+ let result = input.read_all(untrusted::EndOfInput, |input| {
+ assert_eq!(b'f', input.read_byte()?);
+ assert_eq!(b'o', input.read_byte()?);
+ assert_eq!(b'o', input.read_byte()?);
+ assert!(input.at_end());
+ Ok(())
+ });
+ assert_eq!(result, Ok(()));
+}
+
+#[test]
+fn test_input_read_all_unconsume() {
+ let input = untrusted::Input::from(b"foo");
+ let result = input.read_all(untrusted::EndOfInput, |input| {
+ assert_eq!(b'f', input.read_byte()?);
+ assert!(!input.at_end());
+ Ok(())
+ });
+ assert_eq!(result, Err(untrusted::EndOfInput));
+}
+
+#[test]
+fn test_input_as_slice_less_safe() {
+ let slice = b"foo";
+ let input = untrusted::Input::from(slice);
+ assert_eq!(input.as_slice_less_safe(), slice);
+}
+
+#[test]
+fn using_reader_after_skip_and_get_error_returns_error_must_not_panic() {
+ let input = untrusted::Input::from(&[]);
+ let r = input.read_all(untrusted::EndOfInput, |input| {
+ let r = input.read_bytes(1);
+ assert_eq!(r, Err(untrusted::EndOfInput));
+ Ok(input.read_bytes_to_end())
+ });
+ let _ = r; // "Use" r. The value of `r` is undefined here.
+}
+
+#[test]
+fn size_assumptions() {
+ // Assume that a pointer can address any point in the address space, and
+ // infer that this implies that a byte slice will never be
+ // `core::usize::MAX` bytes long.
+ assert_eq!(core::mem::size_of::<*const u8>(), core::mem::size_of::<usize>());
+}
+
+#[test]
+fn const_fn() {
+ const _INPUT: untrusted::Input<'static> = untrusted::Input::from(&[]);
+}
+
+#[test]
+fn test_vec_into() {
+ extern crate std;
+ let vec = vec![0u8; 0];
+ let _x: untrusted::Input = (&vec[..]).into();
+}
+
+#[test]
+fn test_from_slice() {
+ let slice: &[u8] = &[0u8];
+ let _x: untrusted::Input = slice.into();
+} \ No newline at end of file