xref: /aosp_15_r20/external/libgav1/src/version_test.cc (revision 095378508e87ed692bf8dfeb34008b65b3735891)
1*09537850SAkhilesh Sanikop // Copyright 2021 The libgav1 Authors
2*09537850SAkhilesh Sanikop //
3*09537850SAkhilesh Sanikop // Licensed under the Apache License, Version 2.0 (the "License");
4*09537850SAkhilesh Sanikop // you may not use this file except in compliance with the License.
5*09537850SAkhilesh Sanikop // You may obtain a copy of the License at
6*09537850SAkhilesh Sanikop //
7*09537850SAkhilesh Sanikop //      http://www.apache.org/licenses/LICENSE-2.0
8*09537850SAkhilesh Sanikop //
9*09537850SAkhilesh Sanikop // Unless required by applicable law or agreed to in writing, software
10*09537850SAkhilesh Sanikop // distributed under the License is distributed on an "AS IS" BASIS,
11*09537850SAkhilesh Sanikop // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*09537850SAkhilesh Sanikop // See the License for the specific language governing permissions and
13*09537850SAkhilesh Sanikop // limitations under the License.
14*09537850SAkhilesh Sanikop 
15*09537850SAkhilesh Sanikop #include "src/gav1/version.h"
16*09537850SAkhilesh Sanikop 
17*09537850SAkhilesh Sanikop #include <regex>  // NOLINT (unapproved c++11 header)
18*09537850SAkhilesh Sanikop 
19*09537850SAkhilesh Sanikop #include "gtest/gtest.h"
20*09537850SAkhilesh Sanikop 
21*09537850SAkhilesh Sanikop namespace libgav1 {
22*09537850SAkhilesh Sanikop namespace {
23*09537850SAkhilesh Sanikop 
TEST(VersionTest,GetVersion)24*09537850SAkhilesh Sanikop TEST(VersionTest, GetVersion) {
25*09537850SAkhilesh Sanikop   const int library_version = GetVersion();
26*09537850SAkhilesh Sanikop   EXPECT_EQ((library_version >> 24) & 0xff, 0);
27*09537850SAkhilesh Sanikop   // Note if we link against a shared object there's potential for a mismatch
28*09537850SAkhilesh Sanikop   // if a different library is loaded at runtime.
29*09537850SAkhilesh Sanikop   EXPECT_EQ((library_version >> 16) & 0xff, LIBGAV1_MAJOR_VERSION);
30*09537850SAkhilesh Sanikop   EXPECT_EQ((library_version >> 8) & 0xff, LIBGAV1_MINOR_VERSION);
31*09537850SAkhilesh Sanikop   EXPECT_EQ(library_version & 0xff, LIBGAV1_PATCH_VERSION);
32*09537850SAkhilesh Sanikop 
33*09537850SAkhilesh Sanikop   const int header_version = LIBGAV1_VERSION;
34*09537850SAkhilesh Sanikop   EXPECT_EQ((header_version >> 24) & 0xff, 0);
35*09537850SAkhilesh Sanikop   EXPECT_EQ((header_version >> 16) & 0xff, LIBGAV1_MAJOR_VERSION);
36*09537850SAkhilesh Sanikop   EXPECT_EQ((header_version >> 8) & 0xff, LIBGAV1_MINOR_VERSION);
37*09537850SAkhilesh Sanikop   EXPECT_EQ(header_version & 0xff, LIBGAV1_PATCH_VERSION);
38*09537850SAkhilesh Sanikop }
39*09537850SAkhilesh Sanikop 
TEST(VersionTest,GetVersionString)40*09537850SAkhilesh Sanikop TEST(VersionTest, GetVersionString) {
41*09537850SAkhilesh Sanikop   const char* version = GetVersionString();
42*09537850SAkhilesh Sanikop   ASSERT_NE(version, nullptr);
43*09537850SAkhilesh Sanikop   // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
44*09537850SAkhilesh Sanikop   const std::regex semver_regex(
45*09537850SAkhilesh Sanikop       R"(^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*))"
46*09537850SAkhilesh Sanikop       R"((?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))"
47*09537850SAkhilesh Sanikop       R"((?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?)"
48*09537850SAkhilesh Sanikop       R"((?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$)");
49*09537850SAkhilesh Sanikop 
50*09537850SAkhilesh Sanikop   EXPECT_TRUE(std::regex_match(version, semver_regex)) << version;
51*09537850SAkhilesh Sanikop   // Regex validation:
52*09537850SAkhilesh Sanikop   // It shouldn't accept a version starting with a non-digit.
53*09537850SAkhilesh Sanikop   version = "v1.2.3";
54*09537850SAkhilesh Sanikop   EXPECT_FALSE(std::regex_match(version, semver_regex)) << version;
55*09537850SAkhilesh Sanikop   // It shouldn't accept a version with spaces."
56*09537850SAkhilesh Sanikop   version = "1.2.3 alpha";
57*09537850SAkhilesh Sanikop   EXPECT_FALSE(std::regex_match(version, semver_regex)) << version;
58*09537850SAkhilesh Sanikop }
59*09537850SAkhilesh Sanikop 
TEST(VersionTest,GetBuildConfiguration)60*09537850SAkhilesh Sanikop TEST(VersionTest, GetBuildConfiguration) {
61*09537850SAkhilesh Sanikop   const char* config = GetBuildConfiguration();
62*09537850SAkhilesh Sanikop   ASSERT_NE(config, nullptr);
63*09537850SAkhilesh Sanikop }
64*09537850SAkhilesh Sanikop 
65*09537850SAkhilesh Sanikop }  // namespace
66*09537850SAkhilesh Sanikop }  // namespace libgav1
67