mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Auto merge of #8503 - craftytrickster:8406/limit-suppported-format, r=mbrubeck
Adding method to detect if image formats should be supported by servo https://github.com/servo/servo/issues/8406 Please let me know if I need to make any changes. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8503) <!-- Reviewable:end -->
This commit is contained in:
commit
f17f89059a
6 changed files with 131 additions and 46 deletions
12
tests/unit/net_traits/Cargo.toml
Normal file
12
tests/unit/net_traits/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "net_traits_tests"
|
||||
version = "0.0.1"
|
||||
authors = ["The Servo Project Developers"]
|
||||
|
||||
[lib]
|
||||
name = "net_traits_tests"
|
||||
path = "lib.rs"
|
||||
doctest = false
|
||||
|
||||
[dependencies.net_traits]
|
||||
path = "../../../components/net_traits"
|
24
tests/unit/net_traits/image.rs
Normal file
24
tests/unit/net_traits/image.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use net_traits::image::base::detect_image_format;
|
||||
|
||||
#[test]
|
||||
fn test_supported_images() {
|
||||
let gif1 = [b'G', b'I', b'F', b'8', b'7', b'a'];
|
||||
let gif2 = [b'G', b'I', b'F', b'8', b'9', b'a'];
|
||||
let jpeg = [0xff, 0xd8, 0xff];
|
||||
let png = [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A];
|
||||
let bmp = [0x42, 0x4D];
|
||||
let ico = [0x00, 0x00, 0x01, 0x00];
|
||||
let junk_format = [0x01, 0x02, 0x03, 0x04, 0x05];
|
||||
|
||||
assert!(detect_image_format(&gif1).is_ok());
|
||||
assert!(detect_image_format(&gif2).is_ok());
|
||||
assert!(detect_image_format(&jpeg).is_ok());
|
||||
assert!(detect_image_format(&png).is_ok());
|
||||
assert!(detect_image_format(&bmp).is_ok());
|
||||
assert!(detect_image_format(&ico).is_ok());
|
||||
assert!(detect_image_format(&junk_format).is_err());
|
||||
}
|
7
tests/unit/net_traits/lib.rs
Normal file
7
tests/unit/net_traits/lib.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
extern crate net_traits;
|
||||
|
||||
#[cfg(test)] mod image;
|
Loading…
Add table
Add a link
Reference in a new issue