| 1 | // Copyright (c) 2022 Harry [Majored] [[email protected]] |
| 2 | // MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE) |
| 3 | |
| 4 | #[test] |
| 5 | fn search_one_byte_test() { |
| 6 | let buffer: &[u8] = &[0x0, 0x0, 0x0, 0x0, 0x0, 0x0]; |
| 7 | let signature: &[u8] = &[0x1]; |
| 8 | |
| 9 | let matched = crate::base::read::io::locator::reverse_search_buffer(buffer, signature); |
| 10 | assert!(matched.is_none()); |
| 11 | |
| 12 | let buffer: &[u8] = &[0x2, 0x1, 0x0, 0x0, 0x0, 0x0]; |
| 13 | let signature: &[u8] = &[0x1]; |
| 14 | |
| 15 | let matched = crate::base::read::io::locator::reverse_search_buffer(buffer, signature); |
| 16 | assert!(matched.is_some()); |
| 17 | assert_eq!(1, matched.unwrap()); |
| 18 | } |
| 19 | |
| 20 | #[test] |
| 21 | fn search_two_byte_test() { |
| 22 | let buffer: &[u8] = &[0x2, 0x1, 0x0, 0x0, 0x0, 0x0]; |
| 23 | let signature: &[u8] = &[0x2, 0x1]; |
| 24 | |
| 25 | let matched = crate::base::read::io::locator::reverse_search_buffer(buffer, signature); |
| 26 | assert!(matched.is_some()); |
| 27 | assert_eq!(1, matched.unwrap()); |
| 28 | } |
| 29 | |
| 30 | #[tokio::test] |
| 31 | async fn locator_empty_test() { |
| 32 | use futures_lite::io::Cursor; |
| 33 | |
| 34 | let data = &include_bytes!("empty.zip"); |
| 35 | let mut cursor = Cursor::new(data); |
| 36 | let eocdr = crate::base::read::io::locator::eocdr(&mut cursor).await; |
| 37 | |
| 38 | assert!(eocdr.is_ok()); |
| 39 | assert_eq!(eocdr.unwrap(), 4); |
| 40 | } |
| 41 | |
| 42 | #[tokio::test] |
| 43 | async fn locator_empty_max_comment_test() { |
| 44 | use futures_lite::io::Cursor; |
| 45 | |
| 46 | let data = &include_bytes!("empty-with-max-comment.zip"); |
| 47 | let mut cursor = Cursor::new(data); |
| 48 | let eocdr = crate::base::read::io::locator::eocdr(&mut cursor).await; |
| 49 | |
| 50 | assert!(eocdr.is_ok()); |
| 51 | assert_eq!(eocdr.unwrap(), 4); |
| 52 | } |
| 53 | |
| 54 | #[tokio::test] |
| 55 | async fn locator_buffer_boundary_test() { |
| 56 | use futures_lite::io::Cursor; |
| 57 | |
| 58 | let data = &include_bytes!("empty-buffer-boundary.zip"); |
| 59 | let mut cursor = Cursor::new(data); |
| 60 | let eocdr = crate::base::read::io::locator::eocdr(&mut cursor).await; |
| 61 | |
| 62 | assert!(eocdr.is_ok()); |
| 63 | assert_eq!(eocdr.unwrap(), 4); |
| 64 | } |