Tao Bao | 1d86605 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 agree 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 <stdio.h> |
| 18 | |
| 19 | #include <android-base/test_utils.h> |
| 20 | #include <gtest/gtest.h> |
| 21 | #include <ziparchive/zip_archive.h> |
| 22 | #include <ziparchive/zip_writer.h> |
| 23 | |
| 24 | #include "install.h" |
| 25 | |
| 26 | TEST(InstallTest, verify_package_compatibility_no_entry) { |
| 27 | TemporaryFile temp_file; |
| 28 | FILE* zip_file = fdopen(temp_file.fd, "w"); |
| 29 | ZipWriter writer(zip_file); |
| 30 | // The archive must have something to be opened correctly. |
| 31 | ASSERT_EQ(0, writer.StartEntry("dummy_entry", 0)); |
| 32 | ASSERT_EQ(0, writer.FinishEntry()); |
| 33 | ASSERT_EQ(0, writer.Finish()); |
| 34 | ASSERT_EQ(0, fclose(zip_file)); |
| 35 | |
| 36 | // Doesn't contain compatibility zip entry. |
| 37 | ZipArchiveHandle zip; |
| 38 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
| 39 | ASSERT_TRUE(verify_package_compatibility(zip)); |
| 40 | CloseArchive(zip); |
| 41 | } |
| 42 | |
| 43 | TEST(InstallTest, verify_package_compatibility_invalid_entry) { |
| 44 | TemporaryFile temp_file; |
| 45 | FILE* zip_file = fdopen(temp_file.fd, "w"); |
| 46 | ZipWriter writer(zip_file); |
| 47 | ASSERT_EQ(0, writer.StartEntry("compatibility.zip", 0)); |
| 48 | ASSERT_EQ(0, writer.FinishEntry()); |
| 49 | ASSERT_EQ(0, writer.Finish()); |
| 50 | ASSERT_EQ(0, fclose(zip_file)); |
| 51 | |
| 52 | // Empty compatibility zip entry. |
| 53 | ZipArchiveHandle zip; |
| 54 | ASSERT_EQ(0, OpenArchive(temp_file.path, &zip)); |
| 55 | ASSERT_FALSE(verify_package_compatibility(zip)); |
| 56 | CloseArchive(zip); |
| 57 | } |