|
| 1 | +// |
| 2 | +// Copyright (C) 2026 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 | +#include "cuttlefish/host/libs/zip/libzip_cc/archive.h" |
| 17 | + |
| 18 | +#include <string> |
| 19 | +#include <utility> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +#include <gmock/gmock.h> |
| 23 | +#include <gtest/gtest.h> |
| 24 | + |
| 25 | +#include "cuttlefish/host/libs/zip/libzip_cc/writable_source.h" |
| 26 | +#include "cuttlefish/host/libs/zip/zip_string.h" |
| 27 | +#include "cuttlefish/result/result.h" |
| 28 | +#include "cuttlefish/result/result_matchers.h" |
| 29 | + |
| 30 | +namespace cuttlefish { |
| 31 | +namespace { |
| 32 | + |
| 33 | +TEST(ReadableZipTest, ListDirectory) { |
| 34 | + std::string data(4096, '\0'); |
| 35 | + auto source_result = WritableZipSource::BorrowData(data.data(), data.size()); |
| 36 | + ASSERT_THAT(source_result, IsOk()); |
| 37 | + WritableZipSource source = std::move(*source_result); |
| 38 | + |
| 39 | + auto zip_result = WritableZip::FromSource(std::move(source)); |
| 40 | + ASSERT_THAT(zip_result, IsOk()); |
| 41 | + WritableZip zip = std::move(*zip_result); |
| 42 | + |
| 43 | + ASSERT_THAT(AddStringAt(zip, "abc", "dir/file1"), IsOk()); |
| 44 | + ASSERT_THAT(AddStringAt(zip, "def", "dir/file2"), IsOk()); |
| 45 | + |
| 46 | + auto source_result2 = WritableZipSource::FromZip(std::move(zip)); |
| 47 | + ASSERT_THAT(source_result2, IsOk()); |
| 48 | + source = std::move(*source_result2); |
| 49 | + |
| 50 | + auto readable_zip_result = ReadableZip::FromSource(std::move(source)); |
| 51 | + ASSERT_THAT(readable_zip_result, IsOk()); |
| 52 | + ReadableZip readable_zip = std::move(*readable_zip_result); |
| 53 | + |
| 54 | + Result<std::vector<std::string>> entries = readable_zip.ListDirectory("dir"); |
| 55 | + ASSERT_THAT(entries, IsOk()); |
| 56 | + EXPECT_THAT(*entries, testing::UnorderedElementsAre("file1", "file2")); |
| 57 | +} |
| 58 | + |
| 59 | +} // namespace |
| 60 | +} // namespace cuttlefish |
0 commit comments