From bde0ec9e00e92b602251e4015120046668b1a51f Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 25 Apr 2018 12:49:19 -0700 Subject: [PATCH] Make ziparchive-tests run standalone. We need to (a) tell soong to copy our data and (b) automatically find our data relative to our executable. The real point of this is to be able to run these tests in APCT and presubmit. Bug: N/A Test: ran tests on host and device, from a variety of directories Change-Id: I4c0be1ac60f03953fdd5ba6e3d15b1aaa37ed019 --- libziparchive/Android.bp | 4 ++++ libziparchive/zip_archive_test.cc | 40 +------------------------------ 2 files changed, 5 insertions(+), 39 deletions(-) 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(); -}