Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9f84214 authored by Elliott Hughes's avatar Elliott Hughes Committed by android-build-merger
Browse files

Merge "Make ziparchive-tests run standalone."

am: c8a8771b

Change-Id: Ideba391ab6a25aae34eeced8f445ae444a871ecb
parents 9f5aa032 c8a8771b
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -93,6 +93,10 @@ cc_test {
    host_supported: true,
    host_supported: true,
    defaults: ["libziparchive_flags"],
    defaults: ["libziparchive_flags"],


    data: [
        "testdata/**/*",
    ],

    srcs: [
    srcs: [
        "entry_name_utils_test.cc",
        "entry_name_utils_test.cc",
        "zip_archive_test.cc",
        "zip_archive_test.cc",
+1 −39
Original line number Original line Diff line number Diff line
@@ -34,7 +34,7 @@
#include <ziparchive/zip_archive.h>
#include <ziparchive/zip_archive.h>
#include <ziparchive/zip_archive_stream_entry.h>
#include <ziparchive/zip_archive_stream_entry.h>


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 kMissingZip = "missing.zip";
static const std::string kValidZip = "valid.zip";
static const std::string kValidZip = "valid.zip";
@@ -729,41 +729,3 @@ TEST(ziparchive, Inflate) {
    ASSERT_EQ(0u, writer.GetOutput().size());
    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<char> 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();
}