• 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   app_info.RegisterAppInfo(
28       "package_name",
29       std::vector<std::string>({"code_location"}),
30       "",
31       "",
32       AppInfo::CodeType::kPrimaryApk);
33 
34   std::string filter;
35   std::string reason;
36   app_info.GetPrimaryApkOptimizationStatus(&filter, &reason);
37 
38   // Odex status was not registered.
39   ASSERT_EQ(filter, "unknown");
40   ASSERT_EQ(reason, "unknown");
41 }
42 
TEST(AppInfoTest,RegisterAppInfoWithOdexStatus)43 TEST(AppInfoTest, RegisterAppInfoWithOdexStatus) {
44   AppInfo app_info;
45   app_info.RegisterAppInfo(
46       "package_name",
47       std::vector<std::string>({"code_location"}),
48       "",
49       "",
50       AppInfo::CodeType::kPrimaryApk);
51   app_info.RegisterOdexStatus(
52       "code_location",
53       "filter",
54       "reason",
55       "odex_status");
56 
57   std::string filter;
58   std::string reason;
59   app_info.GetPrimaryApkOptimizationStatus(&filter, &reason);
60 
61   ASSERT_EQ(filter, "filter");
62   ASSERT_EQ(reason, "reason");
63 }
64 
TEST(AppInfoTest,RegisterAppInfoWithOdexStatusMultiplePrimary)65 TEST(AppInfoTest, RegisterAppInfoWithOdexStatusMultiplePrimary) {
66   AppInfo app_info;
67   app_info.RegisterOdexStatus(
68       "code_location",
69       "filter",
70       "reason",
71       "odex_status");
72   app_info.RegisterOdexStatus(
73       "code_location2",
74       "filter2",
75       "reason2",
76       "odex_status");
77   app_info.RegisterAppInfo(
78       "package_name",
79       std::vector<std::string>({"code_location"}),
80       "",
81       "",
82       AppInfo::CodeType::kPrimaryApk);
83 
84   std::string filter;
85   std::string reason;
86   app_info.GetPrimaryApkOptimizationStatus(&filter, &reason);
87 
88   // The optimization status should be the one of the first apk.
89   ASSERT_EQ(filter, "filter");
90   ASSERT_EQ(reason, "reason");
91 }
92 
TEST(AppInfoTest,RegisterAppInfoWithOdexStatusNoPrimary)93 TEST(AppInfoTest, RegisterAppInfoWithOdexStatusNoPrimary) {
94   AppInfo app_info;
95 
96   // Check that the status is not known in an empty app_info.
97   std::string filter;
98   std::string reason;
99   app_info.GetPrimaryApkOptimizationStatus(&filter, &reason);
100 
101   // Register a split.s
102   app_info.RegisterAppInfo(
103       "package_name",
104       std::vector<std::string>({"code_location"}),
105       "",
106       "",
107       AppInfo::CodeType::kSplitApk);
108   app_info.RegisterOdexStatus(
109       "code_location",
110       "filter",
111       "reason",
112       "odex_status");
113 
114 
115   // The optimization status is unknown since we don't have primary apks.
116   app_info.GetPrimaryApkOptimizationStatus(&filter, &reason);
117   ASSERT_EQ(filter, "unknown");
118   ASSERT_EQ(reason, "unknown");
119 }
120 
121 }  // namespace art
122