diff --git a/libziparchive/Android.bp b/libziparchive/Android.bp index ed1b9bc24..6c0661822 100644 --- a/libziparchive/Android.bp +++ b/libziparchive/Android.bp @@ -93,6 +93,10 @@ cc_test { host_supported: true, defaults: ["libziparchive_flags"], + data: [ + "testdata/**/*", + ], + srcs: [ "entry_name_utils_test.cc", "zip_archive_test.cc", diff --git a/libziparchive/zip_archive_test.cc b/libziparchive/zip_archive_test.cc index ad673dc7c..377479f1c 100644 --- a/libziparchive/zip_archive_test.cc +++ b/libziparchive/zip_archive_test.cc @@ -34,7 +34,7 @@ #include #include -static std::string test_data_dir; +static std::string test_data_dir = android::base::GetExecutableDirectory() + "/testdata"; static const std::string kMissingZip = "missing.zip"; static const std::string kValidZip = "valid.zip"; @@ -729,41 +729,3 @@ TEST(ziparchive, Inflate) { ASSERT_EQ(0u, writer.GetOutput().size()); } } - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - - static struct option options[] = {{"test_data_dir", required_argument, nullptr, 't'}, - {nullptr, 0, nullptr, 0}}; - - while (true) { - int option_index; - const int c = getopt_long_only(argc, argv, "", options, &option_index); - if (c == -1) { - break; - } - - if (c == 't') { - test_data_dir = optarg; - } - } - - if (test_data_dir.size() == 0) { - printf("Test data flag (--test_data_dir) required\n\n"); - return -1; - } - - if (test_data_dir[0] != '/') { - std::vector cwd_buffer(1024); - const char* cwd = getcwd(cwd_buffer.data(), cwd_buffer.size() - 1); - if (cwd == nullptr) { - printf("Cannot get current working directory, use an absolute path instead, was %s\n\n", - test_data_dir.c_str()); - return -2; - } - test_data_dir = '/' + test_data_dir; - test_data_dir = cwd + test_data_dir; - } - - return RUN_ALL_TESTS(); -}