|
| 1 | +use lofty::id3::v2::util::synchsafe::{SynchsafeInteger, UnsynchronizedStream}; |
| 2 | +use std::io::Read; |
| 3 | + |
| 4 | +#[test] |
| 5 | +fn test1() { |
| 6 | + let v = u32::from_be_bytes([0, 0, 0, 127]); |
| 7 | + |
| 8 | + assert_eq!(v.unsynch(), 127); |
| 9 | + assert_eq!(127u32.synch().unwrap(), v); |
| 10 | +} |
| 11 | + |
| 12 | +#[test] |
| 13 | +fn test2() { |
| 14 | + let v = u32::from_be_bytes([0, 0, 1, 0]); |
| 15 | + |
| 16 | + assert_eq!(v.unsynch(), 128); |
| 17 | + assert_eq!(128u32.synch().unwrap(), v); |
| 18 | +} |
| 19 | + |
| 20 | +#[test] |
| 21 | +fn test3() { |
| 22 | + let v = u32::from_be_bytes([0, 0, 1, 1]); |
| 23 | + |
| 24 | + assert_eq!(v.unsynch(), 129); |
| 25 | + assert_eq!(129u32.synch().unwrap(), v); |
| 26 | +} |
| 27 | + |
| 28 | +#[test] |
| 29 | +#[ignore] |
| 30 | +fn test_to_uint_broken() { |
| 31 | + // Marker test, this behavior is not replicated in Lofty |
| 32 | +} |
| 33 | + |
| 34 | +#[test] |
| 35 | +#[ignore] |
| 36 | +fn test_to_uint_broken_and_too_large() { |
| 37 | + // Marker test, this behavior is not replicated in Lofty |
| 38 | +} |
| 39 | + |
| 40 | +#[test] |
| 41 | +fn test_decode1() { |
| 42 | + let a = [0xFFu8, 0x00u8, 0x00u8]; |
| 43 | + |
| 44 | + let mut a2 = Vec::new(); |
| 45 | + UnsynchronizedStream::new(&mut &a[..]) |
| 46 | + .read_to_end(&mut a2) |
| 47 | + .unwrap(); |
| 48 | + |
| 49 | + assert_eq!(a2.len(), 2); |
| 50 | + assert_eq!(a2, &[0xFF, 0x00]); |
| 51 | +} |
| 52 | + |
| 53 | +#[test] |
| 54 | +fn test_decode2() { |
| 55 | + let a = [0xFFu8, 0x44u8]; |
| 56 | + |
| 57 | + let mut a2 = Vec::new(); |
| 58 | + UnsynchronizedStream::new(&mut &a[..]) |
| 59 | + .read_to_end(&mut a2) |
| 60 | + .unwrap(); |
| 61 | + |
| 62 | + assert_eq!(a2.len(), 2); |
| 63 | + assert_eq!(a2, &[0xFF, 0x44]); |
| 64 | +} |
| 65 | + |
| 66 | +#[test] |
| 67 | +fn test_decode3() { |
| 68 | + let a = [0xFFu8, 0xFFu8, 0x00u8]; |
| 69 | + |
| 70 | + let mut a2 = Vec::new(); |
| 71 | + UnsynchronizedStream::new(&mut &a[..]) |
| 72 | + .read_to_end(&mut a2) |
| 73 | + .unwrap(); |
| 74 | + |
| 75 | + assert_eq!(a2.len(), 2); |
| 76 | + assert_eq!(a2, &[0xFFu8, 0xFFu8]); |
| 77 | +} |
| 78 | + |
| 79 | +#[test] |
| 80 | +fn test_decode4() { |
| 81 | + let a = [0xFFu8, 0xFFu8, 0xFFu8]; |
| 82 | + |
| 83 | + let mut a2 = Vec::new(); |
| 84 | + UnsynchronizedStream::new(&mut &a[..]) |
| 85 | + .read_to_end(&mut a2) |
| 86 | + .unwrap(); |
| 87 | + |
| 88 | + assert_eq!(a2.len(), 3); |
| 89 | + assert_eq!(a2, &[0xFFu8, 0xFFu8, 0xFFu8]); |
| 90 | +} |
0 commit comments