• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
23 namespace art {
24 
TEST(AppInfoTest,RegisterAppInfo)25 TEST(AppInfoTest, RegisterAppInfo) {
26   AppInfo app_info;
27   EXPECT_FALSE(app_info.HasRegisteredAppInfo());
28   EXPECT_EQ(app_info.GetRegisteredCodeType("code_location"), AppInfo::CodeType::kUnknown);
29 
30   app_info.RegisterAppInfo(
31       "package_name",
32       std::vector<std::string>({"code_location"}),
33       "",
34       "",
35       AppInfo::CodeType::kPrimaryApk);
36   EXPECT_TRUE(app_info.HasRegisteredAppInfo());
37   EXPECT_EQ(app_info.GetRegisteredCodeType("code_location"), AppInfo::CodeType::kPrimaryApk);
38 
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 
TEST(AppInfoTest,RegisterAppInfoWithOdexStatus)48 TEST(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);
56   EXPECT_EQ(app_info.GetRegisteredCodeType("code_location"), AppInfo::CodeType::kPrimaryApk);
57   app_info.RegisterOdexStatus(
58       "code_location",
59       "filter",
60       "reason",
61       "odex_status");
62   EXPECT_EQ(app_info.GetRegisteredCodeType("code_location"), AppInfo::CodeType::kPrimaryApk);
63 
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 
TEST(AppInfoTest,RegisterAppInfoWithOdexStatusMultiplePrimary)72 TEST(AppInfoTest, RegisterAppInfoWithOdexStatusMultiplePrimary) {
73   AppInfo app_info;
74   app_info.RegisterOdexStatus(
75       "code_location",
76       "filter",
77       "reason",
78       "odex_status");
79   EXPECT_FALSE(app_info.HasRegisteredAppInfo());
80   app_info.RegisterOdexStatus(
81       "code_location2",
82       "filter2",
83       "reason2",
84       "odex_status");
85   EXPECT_FALSE(app_info.HasRegisteredAppInfo());
86   app_info.RegisterAppInfo(
87       "package_name",
88       std::vector<std::string>({"code_location"}),
89       "",
90       "",
91       AppInfo::CodeType::kPrimaryApk);
92   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);
95 
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 
TEST(AppInfoTest,RegisterAppInfoWithOdexStatusNoPrimary)105 TEST(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");
125   EXPECT_EQ(app_info.GetRegisteredCodeType("code_location"), AppInfo::CodeType::kSplitApk);
126 
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
134