1 /*
2  * Copyright (C) 2018 The Android Open Source Project
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 #include "chre/pal/version.h"
18 #include "gtest/gtest.h"
19 
TEST(PalVersionTest,CreateApiVersion)20 TEST(PalVersionTest, CreateApiVersion) {
21   constexpr uint32_t version = CHRE_PAL_CREATE_API_VERSION(3, 6);
22   EXPECT_EQ(version, 0x03060000u);
23   EXPECT_EQ(CHRE_PAL_GET_API_MAJOR_VERSION(version), 3u);
24 }
25 
TEST(PalVersionTest,CompatibilityCheck)26 TEST(PalVersionTest, CompatibilityCheck) {
27   constexpr uint32_t pal_version = CHRE_PAL_CREATE_API_VERSION(2, 8);
28 
29   uint32_t requested_version = CHRE_PAL_CREATE_API_VERSION(3, 6);
30   EXPECT_FALSE(
31       CHRE_PAL_VERSIONS_ARE_COMPATIBLE(pal_version, requested_version));
32 
33   requested_version = CHRE_PAL_CREATE_API_VERSION(1, 5);
34   EXPECT_FALSE(
35       CHRE_PAL_VERSIONS_ARE_COMPATIBLE(pal_version, requested_version));
36 
37   requested_version = CHRE_PAL_CREATE_API_VERSION(2, 7);
38   EXPECT_TRUE(CHRE_PAL_VERSIONS_ARE_COMPATIBLE(pal_version, requested_version));
39 
40   requested_version = CHRE_PAL_CREATE_API_VERSION(2, 4);
41   EXPECT_TRUE(CHRE_PAL_VERSIONS_ARE_COMPATIBLE(pal_version, requested_version));
42 
43   requested_version = CHRE_PAL_CREATE_API_VERSION(2, 9);
44   EXPECT_TRUE(CHRE_PAL_VERSIONS_ARE_COMPATIBLE(pal_version, requested_version));
45 }
46