Fabien Sanglard | 0f29f54 | 2020-10-22 17:58:12 -0700 | [diff] [blame] | 1 | #include "gmock/gmock.h" |
| 2 | #include "gtest/gtest.h" |
| 3 | |
| 4 | #include "ZipAlign.h" |
| 5 | |
| 6 | #include <stdio.h> |
Fabien Sanglard | 6dfc6fb | 2020-10-22 17:58:12 -0700 | [diff] [blame] | 7 | #include <string> |
| 8 | |
| 9 | #include <android-base/file.h> |
Fabien Sanglard | 0f29f54 | 2020-10-22 17:58:12 -0700 | [diff] [blame] | 10 | |
| 11 | using namespace android; |
| 12 | |
Fabien Sanglard | 6dfc6fb | 2020-10-22 17:58:12 -0700 | [diff] [blame] | 13 | static std::string GetTestPath(const std::string& filename) { |
| 14 | static std::string test_data_dir = android::base::GetExecutableDirectory() + "/tests/data/"; |
| 15 | return test_data_dir + filename; |
| 16 | } |
| 17 | |
Fabien Sanglard | 0f29f54 | 2020-10-22 17:58:12 -0700 | [diff] [blame] | 18 | TEST(Align, Unaligned) { |
Fabien Sanglard | 6dfc6fb | 2020-10-22 17:58:12 -0700 | [diff] [blame] | 19 | const std::string src = GetTestPath("unaligned.zip"); |
| 20 | const std::string dst = GetTestPath("unaligned_out.zip"); |
| 21 | |
| 22 | int result = process(src.c_str(), dst.c_str(), 4, true, false, 4096); |
Fabien Sanglard | 0f29f54 | 2020-10-22 17:58:12 -0700 | [diff] [blame] | 23 | ASSERT_EQ(0, result); |
| 24 | } |
Fabien Sanglard | a720635 | 2020-10-20 15:47:10 -0700 | [diff] [blame^] | 25 | |
| 26 | // Align a zip featuring a hole at the beginning. The |
| 27 | // hole in the archive is a delete entry in the Central |
| 28 | // Directory. |
| 29 | TEST(Align, Holes) { |
| 30 | const std::string src = GetTestPath("holes.zip"); |
| 31 | const std::string dst = GetTestPath("holes_out.zip"); |
| 32 | |
| 33 | int processed = process(src.c_str(), dst.c_str(), 4, true, false, 4096); |
| 34 | ASSERT_EQ(0, processed); |
| 35 | |
| 36 | int verified = verify(dst.c_str(), 4, false, true); |
| 37 | ASSERT_EQ(0, verified); |
| 38 | } |
| 39 | |
| 40 | // Align a zip where LFH order and CD entries differ. |
| 41 | TEST(Align, DifferenteOrders) { |
| 42 | const std::string src = GetTestPath("diffOrders.zip"); |
| 43 | const std::string dst = GetTestPath("diffOrders_out.zip"); |
| 44 | |
| 45 | int processed = process(src.c_str(), dst.c_str(), 4, true, false, 4096); |
| 46 | ASSERT_EQ(0, processed); |
| 47 | |
| 48 | int verified = verify(dst.c_str(), 4, false, true); |
| 49 | ASSERT_EQ(0, verified); |
| 50 | } |