1 // Copyright 2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 use crabby_avif::*;
16 
17 #[cfg(test)]
get_test_file(filename: &str) -> String18 pub fn get_test_file(filename: &str) -> String {
19     let base_path = if cfg!(google3) {
20         format!(
21             "{}/google3/third_party/crabbyavif/",
22             std::env::var("TEST_SRCDIR").expect("TEST_SRCDIR is not defined")
23         )
24     } else {
25         "".to_string()
26     };
27     String::from(format!("{base_path}tests/data/{filename}"))
28 }
29 
30 #[cfg(test)]
get_decoder(filename: &str) -> decoder::Decoder31 pub fn get_decoder(filename: &str) -> decoder::Decoder {
32     let abs_filename = get_test_file(filename);
33     let mut decoder = decoder::Decoder::default();
34     let _ = decoder
35         .set_io_file(&abs_filename)
36         .expect("Failed to set IO");
37     decoder
38 }
39 
40 #[cfg(test)]
41 #[allow(dead_code)]
42 pub const HAS_DECODER: bool = if cfg!(any(
43     feature = "dav1d",
44     feature = "libgav1",
45     feature = "android_mediacodec"
46 )) {
47     true
48 } else {
49     false
50 };
51