1 /*
2 * Copyright (C) 2022 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 "test_base.h"
18
19 #include <gtest/gtest.h>
20
21 #include "chre/core/event_loop_manager.h"
22 #include "chre/core/init.h"
23 #include "chre/platform/linux/platform_log.h"
24 #include "chre/util/time.h"
25 #include "chre_api/chre/version.h"
26 #include "inc/test_util.h"
27 #include "test_util.h"
28
29 namespace chre {
30
31 class InfoStructVersionTest : public TestBase {};
32
TEST_F(InfoStructVersionTest,InfoStructOldVersionCheckForAppPermission)33 TEST_F(InfoStructVersionTest, InfoStructOldVersionCheckForAppPermission) {
34 constexpr uint8_t kInfoStructVersionOld = 2;
35
36 constexpr uint64_t kAppId = 0x01234;
37 constexpr uint32_t kAppVersion = 0;
38 constexpr uint32_t kAppPerms = 0;
39
40 UniquePtr<Nanoapp> oldnanoapp = createStaticNanoapp(
41 kInfoStructVersionOld, "Test nanoapp", kAppId, kAppVersion, kAppPerms,
42 defaultNanoappStart, defaultNanoappHandleEvent, defaultNanoappEnd);
43
44 EXPECT_FALSE(oldnanoapp->supportsAppPermissions());
45 }
46
TEST_F(InfoStructVersionTest,InfoStructCurrentVersionCheckForAppPermission)47 TEST_F(InfoStructVersionTest, InfoStructCurrentVersionCheckForAppPermission) {
48 constexpr uint8_t kInfoStructVersionCurrent = 3;
49
50 constexpr uint64_t kAppId = 0x56789;
51 constexpr uint32_t kAppVersion = 0;
52 constexpr uint32_t kAppPerms = 0;
53
54 UniquePtr<Nanoapp> currentnanoapp = createStaticNanoapp(
55 kInfoStructVersionCurrent, "Test nanoapp", kAppId, kAppVersion, kAppPerms,
56 defaultNanoappStart, defaultNanoappHandleEvent, defaultNanoappEnd);
57
58 EXPECT_TRUE(currentnanoapp->supportsAppPermissions());
59 }
60
TEST_F(InfoStructVersionTest,InfoStructFutureVersionCheckForAppPermission)61 TEST_F(InfoStructVersionTest, InfoStructFutureVersionCheckForAppPermission) {
62 constexpr uint8_t kInfoStructVersionFuture = 4;
63
64 constexpr uint64_t kAppId = 0xabcde;
65 constexpr uint32_t kAppVersion = 0;
66 constexpr uint32_t kAppPerms = 0;
67
68 UniquePtr<Nanoapp> futurenanoapp = createStaticNanoapp(
69 kInfoStructVersionFuture, "Test nanoapp", kAppId, kAppVersion, kAppPerms,
70 defaultNanoappStart, defaultNanoappHandleEvent, defaultNanoappEnd);
71
72 EXPECT_TRUE(futurenanoapp->supportsAppPermissions());
73 }
74
75 } // namespace chre
76