xref: /aosp_15_r20/external/libgav1/src/c_version_test.c (revision 095378508e87ed692bf8dfeb34008b65b3735891)
1*09537850SAkhilesh Sanikop /*
2*09537850SAkhilesh Sanikop  * Copyright 2021 The libgav1 Authors
3*09537850SAkhilesh Sanikop  *
4*09537850SAkhilesh Sanikop  * Licensed under the Apache License, Version 2.0 (the "License");
5*09537850SAkhilesh Sanikop  * you may not use this file except in compliance with the License.
6*09537850SAkhilesh Sanikop  * You may obtain a copy of the License at
7*09537850SAkhilesh Sanikop  *
8*09537850SAkhilesh Sanikop  *      http://www.apache.org/licenses/LICENSE-2.0
9*09537850SAkhilesh Sanikop  *
10*09537850SAkhilesh Sanikop  * Unless required by applicable law or agreed to in writing, software
11*09537850SAkhilesh Sanikop  * distributed under the License is distributed on an "AS IS" BASIS,
12*09537850SAkhilesh Sanikop  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*09537850SAkhilesh Sanikop  * See the License for the specific language governing permissions and
14*09537850SAkhilesh Sanikop  * limitations under the License.
15*09537850SAkhilesh Sanikop  */
16*09537850SAkhilesh Sanikop 
17*09537850SAkhilesh Sanikop #ifdef __cplusplus
18*09537850SAkhilesh Sanikop #error Do not compile this file with a C++ compiler
19*09537850SAkhilesh Sanikop #endif
20*09537850SAkhilesh Sanikop 
21*09537850SAkhilesh Sanikop // clang-format off
22*09537850SAkhilesh Sanikop #include "src/gav1/version.h"
23*09537850SAkhilesh Sanikop // clang-format on
24*09537850SAkhilesh Sanikop 
25*09537850SAkhilesh Sanikop #include <stddef.h>
26*09537850SAkhilesh Sanikop #include <stdio.h>
27*09537850SAkhilesh Sanikop #include <stdlib.h>
28*09537850SAkhilesh Sanikop 
29*09537850SAkhilesh Sanikop #define ASSERT_EQ(a, b)                                                      \
30*09537850SAkhilesh Sanikop   do {                                                                       \
31*09537850SAkhilesh Sanikop     if ((a) != (b)) {                                                        \
32*09537850SAkhilesh Sanikop       fprintf(stderr, "Assertion failure: (%s) == (%s), at %s:%d\n", #a, #b, \
33*09537850SAkhilesh Sanikop               __FILE__, __LINE__);                                           \
34*09537850SAkhilesh Sanikop       fprintf(stderr, "C VersionTest failed\n");                             \
35*09537850SAkhilesh Sanikop       exit(1);                                                               \
36*09537850SAkhilesh Sanikop     }                                                                        \
37*09537850SAkhilesh Sanikop   } while (0)
38*09537850SAkhilesh Sanikop 
39*09537850SAkhilesh Sanikop #define ASSERT_NE(a, b)                                                      \
40*09537850SAkhilesh Sanikop   do {                                                                       \
41*09537850SAkhilesh Sanikop     if ((a) == (b)) {                                                        \
42*09537850SAkhilesh Sanikop       fprintf(stderr, "Assertion failure: (%s) != (%s), at %s:%d\n", #a, #b, \
43*09537850SAkhilesh Sanikop               __FILE__, __LINE__);                                           \
44*09537850SAkhilesh Sanikop       fprintf(stderr, "C VersionTest failed\n");                             \
45*09537850SAkhilesh Sanikop       exit(1);                                                               \
46*09537850SAkhilesh Sanikop     }                                                                        \
47*09537850SAkhilesh Sanikop   } while (0)
48*09537850SAkhilesh Sanikop 
49*09537850SAkhilesh Sanikop #define ASSERT_TRUE(a)                                                   \
50*09537850SAkhilesh Sanikop   do {                                                                   \
51*09537850SAkhilesh Sanikop     if (!(a)) {                                                          \
52*09537850SAkhilesh Sanikop       fprintf(stderr, "Assertion failure: %s, at %s:%d\n", #a, __FILE__, \
53*09537850SAkhilesh Sanikop               __LINE__);                                                 \
54*09537850SAkhilesh Sanikop       fprintf(stderr, "C VersionTest failed\n");                         \
55*09537850SAkhilesh Sanikop       exit(1);                                                           \
56*09537850SAkhilesh Sanikop     }                                                                    \
57*09537850SAkhilesh Sanikop   } while (0)
58*09537850SAkhilesh Sanikop 
59*09537850SAkhilesh Sanikop #define ASSERT_FALSE(a)                                                     \
60*09537850SAkhilesh Sanikop   do {                                                                      \
61*09537850SAkhilesh Sanikop     if (a) {                                                                \
62*09537850SAkhilesh Sanikop       fprintf(stderr, "Assertion failure: !(%s), at %s:%d\n", #a, __FILE__, \
63*09537850SAkhilesh Sanikop               __LINE__);                                                    \
64*09537850SAkhilesh Sanikop       fprintf(stderr, "C VersionTest failed\n");                            \
65*09537850SAkhilesh Sanikop       exit(1);                                                              \
66*09537850SAkhilesh Sanikop     }                                                                       \
67*09537850SAkhilesh Sanikop   } while (0)
68*09537850SAkhilesh Sanikop 
VersionTestGetVersion(void)69*09537850SAkhilesh Sanikop static void VersionTestGetVersion(void) {
70*09537850SAkhilesh Sanikop   const int library_version = Libgav1GetVersion();
71*09537850SAkhilesh Sanikop   ASSERT_EQ((library_version >> 24) & 0xff, 0);
72*09537850SAkhilesh Sanikop   // Note if we link against a shared object there's potential for a mismatch
73*09537850SAkhilesh Sanikop   // if a different library is loaded at runtime.
74*09537850SAkhilesh Sanikop   ASSERT_EQ((library_version >> 16) & 0xff, LIBGAV1_MAJOR_VERSION);
75*09537850SAkhilesh Sanikop   ASSERT_EQ((library_version >> 8) & 0xff, LIBGAV1_MINOR_VERSION);
76*09537850SAkhilesh Sanikop   ASSERT_EQ(library_version & 0xff, LIBGAV1_PATCH_VERSION);
77*09537850SAkhilesh Sanikop 
78*09537850SAkhilesh Sanikop   const int header_version = LIBGAV1_VERSION;
79*09537850SAkhilesh Sanikop   ASSERT_EQ((header_version >> 24) & 0xff, 0);
80*09537850SAkhilesh Sanikop   ASSERT_EQ((header_version >> 16) & 0xff, LIBGAV1_MAJOR_VERSION);
81*09537850SAkhilesh Sanikop   ASSERT_EQ((header_version >> 8) & 0xff, LIBGAV1_MINOR_VERSION);
82*09537850SAkhilesh Sanikop   ASSERT_EQ(header_version & 0xff, LIBGAV1_PATCH_VERSION);
83*09537850SAkhilesh Sanikop }
84*09537850SAkhilesh Sanikop 
VersionTestGetVersionString(void)85*09537850SAkhilesh Sanikop static void VersionTestGetVersionString(void) {
86*09537850SAkhilesh Sanikop   const char* version = Libgav1GetVersionString();
87*09537850SAkhilesh Sanikop   ASSERT_NE(version, NULL);
88*09537850SAkhilesh Sanikop }
89*09537850SAkhilesh Sanikop 
VersionTestGetBuildConfiguration(void)90*09537850SAkhilesh Sanikop static void VersionTestGetBuildConfiguration(void) {
91*09537850SAkhilesh Sanikop   const char* config = Libgav1GetBuildConfiguration();
92*09537850SAkhilesh Sanikop   ASSERT_NE(config, NULL);
93*09537850SAkhilesh Sanikop }
94*09537850SAkhilesh Sanikop 
main(void)95*09537850SAkhilesh Sanikop int main(void) {
96*09537850SAkhilesh Sanikop   fprintf(stderr, "C VersionTest started\n");
97*09537850SAkhilesh Sanikop   VersionTestGetVersion();
98*09537850SAkhilesh Sanikop   VersionTestGetVersionString();
99*09537850SAkhilesh Sanikop   VersionTestGetBuildConfiguration();
100*09537850SAkhilesh Sanikop   fprintf(stderr, "C VersionTest passed\n");
101*09537850SAkhilesh Sanikop   return 0;
102*09537850SAkhilesh Sanikop }
103