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