Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

test(libfluxcore): remove rust unit tests

Hampus546636a76920
diff --git a/fluxer_app/rust/libfluxcore/src/formats.rs b/fluxer_app/rust/libfluxcore/src/formats.rs
index 296b77e7e..48953d37b 100644
--- a/fluxer_app/rust/libfluxcore/src/formats.rs
+++ b/fluxer_app/rust/libfluxcore/src/formats.rs
@@ -219,30 +219,3 @@ fn read_u32_be(input: &[u8], offset: usize) -> Option<u32> {
let bytes = input.get(offset..offset + 4)?;
Some(u32::from_be_bytes(bytes.try_into().ok()?))
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- fn png_with_chunks(chunks: &[(&[u8; 4], &[u8])]) -> Vec<u8> {
- let mut out = b"\x89PNG\r\n\x1a\n".to_vec();
- for (chunk_type, payload) in chunks {
- out.extend_from_slice(&(payload.len() as u32).to_be_bytes());
- out.extend_from_slice(*chunk_type);
- out.extend_from_slice(payload);
- out.extend_from_slice(&0u32.to_be_bytes());
- }
- out
- }
-
- #[test]
- fn rejects_truncated_chunks_without_panicking() {
- assert!(!is_animated_image_bytes(
- b"\x89PNG\r\n\x1a\n\xff\xff\xff\xffbad!"
- ));
- let mut png = png_with_chunks(&[(b"bad!", &[0; 8])]);
- png[8..12].copy_from_slice(&u32::MAX.to_be_bytes());
- assert!(!is_animated_image_bytes(&png));
- assert!(!is_animated_image_bytes(b"RIFF\xff\xff\xff\xffWEBPbad!"));
- }
-}
diff --git a/fluxer_app/rust/libfluxcore/src/rgba.rs b/fluxer_app/rust/libfluxcore/src/rgba.rs
index d67658f56..d99524367 100644
--- a/fluxer_app/rust/libfluxcore/src/rgba.rs
+++ b/fluxer_app/rust/libfluxcore/src/rgba.rs
@@ -341,87 +341,3 @@ fn copy_pixel(input: &[u8], dst: &mut [u8], layout: PixelLayout, src: Point, tar
dst[dst_offset..dst_offset + RGBA_BYTES_PER_PIXEL]
.copy_from_slice(&input[src_offset..src_offset + RGBA_BYTES_PER_PIXEL]);
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- fn request(src_width: u32, src_height: u32) -> TransformRequest {
- TransformRequest {
- src_width,
- src_height,
- x: 0,
- y: 0,
- width: src_width,
- height: src_height,
- rotation_deg: 0,
- resize_width: NULL_U32,
- resize_height: NULL_U32,
- }
- }
-
- fn rgba(values: &[u8]) -> Vec<u8> {
- values
- .iter()
- .flat_map(|value| [*value, 0, 0, 255])
- .collect()
- }
-
- fn transformed(
- input: &[u8],
- request: TransformRequest,
- ) -> Result<((u32, u32), Vec<u8>), TransformError> {
- let geometry = output_geometry(request)?;
- let mut output = vec![0; rgba_byte_len(geometry.target_width, geometry.target_height)?];
- crop_rotate_rgba_into(input, &mut output, request)?;
- Ok(((geometry.target_width, geometry.target_height), output))
- }
-
- #[test]
- fn clamps_crop_to_source_bounds() {
- let mut transform = request(3, 2);
- transform.x = 2;
- transform.y = 1;
- transform.width = 99;
- transform.height = 99;
- let (size, pixels) = transformed(&rgba(&[1, 2, 3, 4, 5, 6]), transform).unwrap();
- assert_eq!(size, (1, 1));
- assert_eq!(pixels, rgba(&[6]));
- }
-
- #[test]
- fn rejects_invalid_source_shape() {
- assert_eq!(
- transformed(&[], request(0, 1)).unwrap_err(),
- TransformError::InvalidDimensions
- );
- assert_eq!(
- transformed(&[0, 0, 0, 0], request(2, 1)).unwrap_err(),
- TransformError::InvalidRgbaLength
- );
- }
-
- #[test]
- fn rejects_empty_crop_and_target() {
- let mut empty_crop = request(2, 2);
- empty_crop.x = 2;
- assert_eq!(
- transformed(&rgba(&[1, 2, 3, 4]), empty_crop).unwrap_err(),
- TransformError::EmptyCrop
- );
-
- let mut empty_target = request(2, 2);
- empty_target.resize_width = 0;
- empty_target.resize_height = 1;
- assert!(transformed(&rgba(&[1, 2, 3, 4]), empty_target).is_ok());
- }
-
- #[test]
- fn into_rejects_an_output_of_the_wrong_length() {
- let mut output = vec![0; 3 * RGBA_BYTES_PER_PIXEL];
- assert_eq!(
- crop_rotate_rgba_into(&rgba(&[1, 2, 3, 4]), &mut output, request(2, 2)).unwrap_err(),
- TransformError::InvalidOutputLength
- );
- }
-}
diff --git a/fluxer_app/rust/libfluxcore/src/zstd_stream.rs b/fluxer_app/rust/libfluxcore/src/zstd_stream.rs
index 33442601b..4e3c8e57b 100644
--- a/fluxer_app/rust/libfluxcore/src/zstd_stream.rs
+++ b/fluxer_app/rust/libfluxcore/src/zstd_stream.rs
@@ -130,58 +130,3 @@ fn append_output(output: &mut Vec<u8>, bytes: &[u8]) -> Result<(), ZstdError> {
output.extend_from_slice(bytes);
Ok(())
}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn keeps_partial_frame_state_between_chunks() {
- let compressed = zstd::stream::encode_all(&b"hello stream"[..], 1).unwrap();
- let split_at = compressed.len() / 2;
- let mut decoder = ZstdStreamDecoder::new().unwrap();
-
- let first = decoder.decompress_chunk(&compressed[..split_at]).unwrap();
- let second = decoder.decompress_chunk(&compressed[split_at..]).unwrap();
-
- assert_eq!([first, second].concat(), b"hello stream");
- }
-
- #[test]
- fn encoder_handles_a_payload_larger_than_the_buffer() {
- let mut encoder = ZstdStreamEncoder::new(3).unwrap();
- let mut decoder = ZstdStreamDecoder::new().unwrap();
- let payload = vec![b'a'; READ_BUFFER_BYTES * 8 + 123];
-
- let compressed = encoder.compress_chunk(&payload).unwrap();
- assert_eq!(decoder.decompress_chunk(&compressed).unwrap(), payload);
- }
-
- #[test]
- fn rejects_invalid_zstd() {
- let mut decoder = ZstdStreamDecoder::new().unwrap();
- assert!(matches!(
- decoder.decompress_chunk(b"not zstd"),
- Err(ZstdError::Decode)
- ));
- }
-
- #[test]
- fn accepts_the_decompressed_limit() {
- let input = vec![b'x'; MAX_DECOMPRESSED_BYTES];
- let compressed = zstd::stream::encode_all(input.as_slice(), 1).unwrap();
- let mut decoder = ZstdStreamDecoder::new().unwrap();
- assert_eq!(decoder.decompress_chunk(&compressed).unwrap(), input);
- }
-
- #[test]
- fn rejects_frames_over_the_decompressed_limit() {
- let input = vec![b'x'; MAX_DECOMPRESSED_BYTES + 1];
- let compressed = zstd::stream::encode_all(input.as_slice(), 1).unwrap();
- let mut decoder = ZstdStreamDecoder::new().unwrap();
- assert!(matches!(
- decoder.decompress_chunk(&compressed),
- Err(ZstdError::DecompressedSizeTooLarge)
- ));
- }
-}