blob: 981ae9dd230d6c2aac6788fa8f04216464e7e46c [file] [log] [blame]
Mohammad Samiul Islam24a82792021-02-12 16:52:36 +00001//
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 <utility>
18#include <filesystem>
19
20#include "update_engine/aosp/apex_handler_android.h"
21
22#include <android-base/file.h>
23#include <android-base/strings.h>
24#include <gtest/gtest.h>
25
26using android::base::EndsWith;
27
28namespace chromeos_update_engine {
29
30namespace fs = std::filesystem;
31
Mohammad Samiul Islamb0ab8652021-02-26 14:04:17 +000032ApexInfo CreateApexInfo(const std::string& package_name,
33 int version,
34 bool is_compressed,
35 int decompressed_size) {
36 ApexInfo result;
37 result.set_package_name(package_name);
38 result.set_version(version);
39 result.set_is_compressed(is_compressed);
40 result.set_decompressed_size(decompressed_size);
41 return std::move(result);
Mohammad Samiul Islam24a82792021-02-12 16:52:36 +000042}
43
Mohammad Samiul Islamb0ab8652021-02-26 14:04:17 +000044TEST(ApexHandlerAndroidTest, CalculateSize) {
45 ApexHandlerAndroid apex_handler;
46 std::vector<ApexInfo> apex_infos;
47 ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1);
48 ApexInfo compressed_apex_2 = CreateApexInfo("sample2", 2, true, 2);
49 ApexInfo uncompressed_apex = CreateApexInfo("uncompressed", 1, false, 4);
50 apex_infos.push_back(compressed_apex_1);
51 apex_infos.push_back(compressed_apex_2);
52 apex_infos.push_back(uncompressed_apex);
53 auto result = apex_handler.CalculateSize(apex_infos);
54 ASSERT_TRUE(result.ok());
55 EXPECT_EQ(*result, 3u);
56}
Mohammad Samiul Islam24a82792021-02-12 16:52:36 +000057
Mohammad Samiul Islamb0ab8652021-02-26 14:04:17 +000058TEST(ApexHandlerAndroidTest, AllocateSpace) {
59 ApexHandlerAndroid apex_handler;
60 std::vector<ApexInfo> apex_infos;
61 ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1);
62 ApexInfo compressed_apex_2 = CreateApexInfo("sample2", 2, true, 2);
63 ApexInfo uncompressed_apex = CreateApexInfo("uncompressed", 1, false, 4);
64 apex_infos.push_back(compressed_apex_1);
65 apex_infos.push_back(compressed_apex_2);
66 apex_infos.push_back(uncompressed_apex);
67 EXPECT_TRUE(apex_handler.AllocateSpace(apex_infos));
Mohammad Samiul Islam24a82792021-02-12 16:52:36 +000068
Mohammad Samiul Islamb0ab8652021-02-26 14:04:17 +000069 // Should be able to pass empty list
70 EXPECT_TRUE(apex_handler.AllocateSpace({}));
Mohammad Samiul Islam24a82792021-02-12 16:52:36 +000071}
72
73} // namespace chromeos_update_engine