1 // Copyright 2022 Google LLC
2 // SPDX-License-Identifier: BSD-2-Clause
3 
4 #include "avif/avif.h"
5 #include "aviftest_helpers.h"
6 #include "gtest/gtest.h"
7 
8 namespace avif {
9 namespace {
10 
11 // Used to pass the data folder path to the GoogleTest suites.
12 const char* data_path = nullptr;
13 
TEST(ClliTest,Simple)14 TEST(ClliTest, Simple) {
15   struct Params {
16     const char* file_name;
17     uint32_t maxCLL;
18     uint32_t maxPALL;
19   };
20   Params params[9] = {
21     {"clli/clli_0_0.avif", 0, 0},
22     {"clli/clli_0_1.avif", 0, 1},
23     {"clli/clli_0_65535.avif", 0, 65535},
24     {"clli/clli_1_0.avif", 1, 0},
25     {"clli/clli_1_1.avif", 1, 1},
26     {"clli/clli_1_65535.avif", 1, 65535},
27     {"clli/clli_65535_0.avif", 65535, 0},
28     {"clli/clli_65535_1.avif", 65535, 1},
29     {"clli/clli_65535_65535.avif", 65535, 65535},
30   };
31   for (const auto& param : params) {
32     DecoderPtr decoder(avifDecoderCreate());
33     ASSERT_NE(decoder, nullptr);
34     decoder->allowProgressive = true;
35     ASSERT_EQ(avifDecoderSetIOFile(decoder.get(),
36                                    (std::string(data_path) + param.file_name).c_str()),
37               AVIF_RESULT_OK);
38     ASSERT_EQ(avifDecoderParse(decoder.get()), AVIF_RESULT_OK);
39     EXPECT_EQ(decoder->compressionFormat, COMPRESSION_FORMAT_AVIF);
40     avifImage* decoded = decoder->image;
41     ASSERT_NE(decoded, nullptr);
42     ASSERT_EQ(decoded->clli.maxCLL, param.maxCLL);
43     ASSERT_EQ(decoded->clli.maxPALL, param.maxPALL);
44   }
45 }
46 
47 }  // namespace
48 }  // namespace avif
49 
main(int argc,char ** argv)50 int main(int argc, char** argv) {
51   ::testing::InitGoogleTest(&argc, argv);
52   if (argc != 2) {
53     std::cerr << "There must be exactly one argument containing the path to "
54                  "the test data folder"
55               << std::endl;
56     return 1;
57   }
58   avif::data_path = argv[1];
59   return RUN_ALL_TESTS();
60 }
61