1 #include <cmath>
2 #include <cstddef>
3 #include <cstring>
4 #include "api/zimg.h"
5
6 #include "gtest/gtest.h"
7
TEST(APITest,test_api_2_0_compat)8 TEST(APITest, test_api_2_0_compat)
9 {
10 const unsigned API_2_0 = ZIMG_MAKE_API_VERSION(2, 0);
11 const size_t extra_off = offsetof(zimg_image_format, active_region);
12 const size_t extra_len = sizeof(zimg_image_format) - extra_off;
13
14 zimg_image_format format;
15 std::memset(reinterpret_cast<unsigned char *>(&format) + extra_off, 0xCC, extra_len);
16
17 zimg_image_format_default(&format, API_2_0);
18 EXPECT_EQ(API_2_0, format.version);
19 for (size_t i = extra_off; i < extra_len; ++i) {
20 EXPECT_EQ(0xCC, *(reinterpret_cast<unsigned char *>(&format) + i));
21 }
22
23 format.width = 640;
24 format.height = 480;
25 format.pixel_type = ZIMG_PIXEL_BYTE;
26
27 // Should trigger error in API 2.1+.
28 format.active_region.left = 0;
29 format.active_region.top = 0;
30 format.active_region.width = -INFINITY;
31 format.active_region.height = -INFINITY;
32
33 zimg_graph_builder_params params;
34 zimg_graph_builder_params_default(¶ms, API_2_0);
35 EXPECT_EQ(API_2_0, params.version);
36
37 zimg_filter_graph *graph = zimg_filter_graph_build(&format, &format, ¶ms);
38 EXPECT_TRUE(graph);
39 zimg_filter_graph_free(graph);
40 }
41
TEST(APITest,test_api_2_1_compat)42 TEST(APITest, test_api_2_1_compat)
43 {
44 const unsigned API_2_1 = ZIMG_MAKE_API_VERSION(2, 1);
45 const size_t extra_off = offsetof(zimg_graph_builder_params, nominal_peak_luminance);
46 const size_t extra_len = sizeof(zimg_graph_builder_params) - extra_off;
47
48 zimg_graph_builder_params params;
49 std::memset(reinterpret_cast<unsigned char *>(¶ms) + extra_off, 0xCC, extra_len);
50
51 zimg_graph_builder_params_default(¶ms, API_2_1);
52 EXPECT_EQ(API_2_1, params.version);
53 for (size_t i = extra_off; i < extra_len; ++i) {
54 EXPECT_EQ(0xCC, *(reinterpret_cast<unsigned char *>(¶ms) + i));
55 }
56 }
57
TEST(APITest,test_api_2_3_compat)58 TEST(APITest, test_api_2_3_compat)
59 {
60 const unsigned API_2_3 = ZIMG_MAKE_API_VERSION(2, 3);
61 const size_t extra_off = offsetof(zimg_image_format, alpha);
62 const size_t extra_len = sizeof(zimg_image_format) - extra_off;
63
64 zimg_image_format format;
65 std::memset(reinterpret_cast<unsigned char *>(&format) + extra_off, 0xCC, extra_len);
66
67 zimg_image_format_default(&format, API_2_3);
68 EXPECT_EQ(API_2_3, format.version);
69 for (size_t i = extra_off; i < extra_len; ++i) {
70 EXPECT_EQ(0xCC, *(reinterpret_cast<unsigned char *>(&format) + i));
71 }
72 }
73