| Mohammad Samiul Islam | 24a8279 | 2021-02-12 16:52:36 +0000 | [diff] [blame] | 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 <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 |  | 
|  | 26 | using android::base::EndsWith; | 
|  | 27 |  | 
|  | 28 | namespace chromeos_update_engine { | 
|  | 29 |  | 
|  | 30 | namespace fs = std::filesystem; | 
|  | 31 |  | 
| Mohammad Samiul Islam | b0ab865 | 2021-02-26 14:04:17 +0000 | [diff] [blame] | 32 | ApexInfo 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 Islam | 24a8279 | 2021-02-12 16:52:36 +0000 | [diff] [blame] | 42 | } | 
|  | 43 |  | 
| Mohammad Samiul Islam | b0ab865 | 2021-02-26 14:04:17 +0000 | [diff] [blame] | 44 | TEST(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 Islam | 24a8279 | 2021-02-12 16:52:36 +0000 | [diff] [blame] | 57 |  | 
| Mohammad Samiul Islam | b0ab865 | 2021-02-26 14:04:17 +0000 | [diff] [blame] | 58 | TEST(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 Islam | 24a8279 | 2021-02-12 16:52:36 +0000 | [diff] [blame] | 68 |  | 
| Mohammad Samiul Islam | b0ab865 | 2021-02-26 14:04:17 +0000 | [diff] [blame] | 69 | // Should be able to pass empty list | 
|  | 70 | EXPECT_TRUE(apex_handler.AllocateSpace({})); | 
| Mohammad Samiul Islam | 24a8279 | 2021-02-12 16:52:36 +0000 | [diff] [blame] | 71 | } | 
|  | 72 |  | 
|  | 73 | }  // namespace chromeos_update_engine |