blob: 51dd42f6fb18bc27b0388e7bc32f8ba66708be41 [file] [log] [blame]
Calin Juravlec2753e62021-06-25 15:34:09 -07001/*
2 * Copyright (C) 2021 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 "app_info.h"
18
19#include <vector>
20
21#include "gtest/gtest.h"
22
23namespace art {
24
25TEST(AppInfoTest, RegisterAppInfo) {
26 AppInfo app_info;
Jared Duke761f31a2022-06-10 11:18:59 -070027 EXPECT_FALSE(app_info.HasRegisteredAppInfo());
28 EXPECT_EQ(app_info.GetRegisteredCodeType("code_location"), AppInfo::CodeType::kUnknown);
29
Calin Juravlec2753e62021-06-25 15:34:09 -070030 app_info.RegisterAppInfo(
31 "package_name",
32 std::vector<std::string>({"code_location"}),
33 "",
34 "",
35 AppInfo::CodeType::kPrimaryApk);
Jared Duke761f31a2022-06-10 11:18:59 -070036 EXPECT_TRUE(app_info.HasRegisteredAppInfo());
37 EXPECT_EQ(app_info.GetRegisteredCodeType("code_location"), AppInfo::CodeType::kPrimaryApk);
Calin Juravlec2753e62021-06-25 15:34:09 -070038
39 std::string filter;
40 std::string reason;
41 app_info.GetPrimaryApkOptimizationStatus(&filter, &reason);
42
43 // Odex status was not registered.
44 ASSERT_EQ(filter, "unknown");
45 ASSERT_EQ(reason, "unknown");
46}
47
48TEST(AppInfoTest, RegisterAppInfoWithOdexStatus) {
49 AppInfo app_info;
50 app_info.RegisterAppInfo(
51 "package_name",
52 std::vector<std::string>({"code_location"}),
53 "",
54 "",
55 AppInfo::CodeType::kPrimaryApk);
Jared Duke761f31a2022-06-10 11:18:59 -070056 EXPECT_EQ(app_info.GetRegisteredCodeType("code_location"), AppInfo::CodeType::kPrimaryApk);
Calin Juravlec2753e62021-06-25 15:34:09 -070057 app_info.RegisterOdexStatus(
58 "code_location",
59 "filter",
60 "reason",
61 "odex_status");
Jared Duke761f31a2022-06-10 11:18:59 -070062 EXPECT_EQ(app_info.GetRegisteredCodeType("code_location"), AppInfo::CodeType::kPrimaryApk);
Calin Juravlec2753e62021-06-25 15:34:09 -070063
64 std::string filter;
65 std::string reason;
66 app_info.GetPrimaryApkOptimizationStatus(&filter, &reason);
67
68 ASSERT_EQ(filter, "filter");
69 ASSERT_EQ(reason, "reason");
70}
71
72TEST(AppInfoTest, RegisterAppInfoWithOdexStatusMultiplePrimary) {
73 AppInfo app_info;
74 app_info.RegisterOdexStatus(
75 "code_location",
76 "filter",
77 "reason",
78 "odex_status");
Jared Duke761f31a2022-06-10 11:18:59 -070079 EXPECT_FALSE(app_info.HasRegisteredAppInfo());
Calin Juravlec2753e62021-06-25 15:34:09 -070080 app_info.RegisterOdexStatus(
81 "code_location2",
82 "filter2",
83 "reason2",
84 "odex_status");
Jared Duke761f31a2022-06-10 11:18:59 -070085 EXPECT_FALSE(app_info.HasRegisteredAppInfo());
Calin Juravlec2753e62021-06-25 15:34:09 -070086 app_info.RegisterAppInfo(
87 "package_name",
88 std::vector<std::string>({"code_location"}),
89 "",
90 "",
91 AppInfo::CodeType::kPrimaryApk);
Jared Duke761f31a2022-06-10 11:18:59 -070092 EXPECT_TRUE(app_info.HasRegisteredAppInfo());
93 EXPECT_EQ(app_info.GetRegisteredCodeType("code_location"), AppInfo::CodeType::kPrimaryApk);
94 EXPECT_EQ(app_info.GetRegisteredCodeType("code_location2"), AppInfo::CodeType::kUnknown);
Calin Juravlec2753e62021-06-25 15:34:09 -070095
96 std::string filter;
97 std::string reason;
98 app_info.GetPrimaryApkOptimizationStatus(&filter, &reason);
99
100 // The optimization status should be the one of the first apk.
101 ASSERT_EQ(filter, "filter");
102 ASSERT_EQ(reason, "reason");
103}
104
105TEST(AppInfoTest, RegisterAppInfoWithOdexStatusNoPrimary) {
106 AppInfo app_info;
107
108 // Check that the status is not known in an empty app_info.
109 std::string filter;
110 std::string reason;
111 app_info.GetPrimaryApkOptimizationStatus(&filter, &reason);
112
113 // Register a split.s
114 app_info.RegisterAppInfo(
115 "package_name",
116 std::vector<std::string>({"code_location"}),
117 "",
118 "",
119 AppInfo::CodeType::kSplitApk);
120 app_info.RegisterOdexStatus(
121 "code_location",
122 "filter",
123 "reason",
124 "odex_status");
Jared Duke761f31a2022-06-10 11:18:59 -0700125 EXPECT_EQ(app_info.GetRegisteredCodeType("code_location"), AppInfo::CodeType::kSplitApk);
Calin Juravlec2753e62021-06-25 15:34:09 -0700126
127 // The optimization status is unknown since we don't have primary apks.
128 app_info.GetPrimaryApkOptimizationStatus(&filter, &reason);
129 ASSERT_EQ(filter, "unknown");
130 ASSERT_EQ(reason, "unknown");
131}
132
133} // namespace art