1 #include "gmock/gmock.h"
2 #include "gtest/gtest.h"
3
4 #include "ZipAlign.h"
5
6 #include <stdio.h>
7 #include <string>
8
9 #include <android-base/file.h>
10
11 using namespace android;
12
GetTestPath(const std::string & filename)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
TEST(Align,Unaligned)18 TEST(Align, Unaligned) {
19 const std::string src = GetTestPath("unaligned.zip");
20 const std::string dst = GetTestPath("unaligned_out.zip");
21
22 int processed = process(src.c_str(), dst.c_str(), 4, true, false, 4096);
23 ASSERT_EQ(0, processed);
24
25 int verified = verify(dst.c_str(), 4, true, false);
26 ASSERT_EQ(0, verified);
27 }
28
29 // Align a zip featuring a hole at the beginning. The
30 // hole in the archive is a delete entry in the Central
31 // Directory.
TEST(Align,Holes)32 TEST(Align, Holes) {
33 const std::string src = GetTestPath("holes.zip");
34 const std::string dst = GetTestPath("holes_out.zip");
35
36 int processed = process(src.c_str(), dst.c_str(), 4, true, false, 4096);
37 ASSERT_EQ(0, processed);
38
39 int verified = verify(dst.c_str(), 4, false, true);
40 ASSERT_EQ(0, verified);
41 }
42
43 // Align a zip where LFH order and CD entries differ.
TEST(Align,DifferenteOrders)44 TEST(Align, DifferenteOrders) {
45 const std::string src = GetTestPath("diffOrders.zip");
46 const std::string dst = GetTestPath("diffOrders_out.zip");
47
48 int processed = process(src.c_str(), dst.c_str(), 4, true, false, 4096);
49 ASSERT_EQ(0, processed);
50
51 int verified = verify(dst.c_str(), 4, false, true);
52 ASSERT_EQ(0, verified);
53 }
54