Make libdexfile tests independent of runtime

Remove dependencies on common_runtime_test and related so that
libdexfile's tests can be run independently of the runtime directory.

Bug: 22322814
Test: make -j 50 test-art-host-gtest
Change-Id: If306c1995e87cbfc944e11fb13c927bc287014ad
diff --git a/runtime/dex/dex_file_verifier_test.cc b/runtime/dex/dex_file_verifier_test.cc
index d73a7fb..1cd4b2c 100644
--- a/runtime/dex/dex_file_verifier_test.cc
+++ b/runtime/dex/dex_file_verifier_test.cc
@@ -16,28 +16,26 @@
 
 #include "dex_file_verifier.h"
 
-#include <sys/mman.h>
 #include <zlib.h>
 
 #include <functional>
 #include <memory>
 
-#include "art_dex_file_loader.h"
 #include "base/bit_utils.h"
 #include "base/macros.h"
-#include "base/unix_file/fd_file.h"
-#include "common_runtime_test.h"
+#include "base64_test_util.h"
 #include "descriptors_names.h"
 #include "dex_file-inl.h"
 #include "dex_file_loader.h"
 #include "dex_file_types.h"
+#include "gtest/gtest.h"
 #include "leb128.h"
-#include "scoped_thread_state_change-inl.h"
 #include "standard_dex_file.h"
-#include "thread-current-inl.h"
 
 namespace art {
 
+static constexpr char kLocationString[] = "dex_file_location";
+
 // Make the Dex file version 37.
 static void MakeDexVersion37(DexFile* dex_file) {
   size_t offset = OFFSETOF_MEMBER(DexFile::Header, magic_) + 6;
@@ -55,7 +53,7 @@
   header->checksum_ = adler_checksum;
 }
 
-class DexFileVerifierTest : public CommonRuntimeTest {
+class DexFileVerifierTest : public testing::Test {
  protected:
   DexFile* GetDexFile(const uint8_t* dex_bytes, size_t length) {
     return new StandardDexFile(dex_bytes, length, "tmp", 0, nullptr, nullptr);
@@ -101,28 +99,19 @@
   std::unique_ptr<uint8_t[]> dex_bytes(DecodeBase64(base64, &length));
   CHECK(dex_bytes.get() != nullptr);
 
-  // write to provided file
-  std::unique_ptr<File> file(OS::CreateEmptyFile(location));
-  CHECK(file.get() != nullptr);
-  if (!file->WriteFully(dex_bytes.get(), length)) {
-    PLOG(FATAL) << "Failed to write base64 as dex file";
-  }
-  if (file->FlushCloseOrErase() != 0) {
-    PLOG(FATAL) << "Could not flush and close test file.";
-  }
-  file.reset();
-
-  // read dex file
-  ScopedObjectAccess soa(Thread::Current());
+  // read dex
   std::vector<std::unique_ptr<const DexFile>> tmp;
-  const ArtDexFileLoader dex_file_loader;
-  bool success = dex_file_loader.Open(
-      location, location, /* verify */ true, /* verify_checksum */ true, error_msg, &tmp);
+  const DexFileLoader dex_file_loader;
+  bool success = dex_file_loader.OpenAll(dex_bytes.get(),
+                                         length,
+                                         location,
+                                         /* verify */ true,
+                                         /* verify_checksum */ true,
+                                         error_msg,
+                                         &tmp);
   CHECK(success) << *error_msg;
   EXPECT_EQ(1U, tmp.size());
   std::unique_ptr<const DexFile> dex_file = std::move(tmp[0]);
-  EXPECT_EQ(PROT_READ, dex_file->GetPermissions());
-  EXPECT_TRUE(dex_file->IsReadOnly());
   return dex_file;
 }
 
@@ -148,9 +137,9 @@
     "AAIgAAANAAAAWgEAAAMgAAACAAAA6AEAAAAgAAABAAAA8wEAAAAQAAABAAAABAIAAA==";
 
 TEST_F(DexFileVerifierTest, GoodDex) {
-  ScratchFile tmp;
   std::string error_msg;
-  std::unique_ptr<const DexFile> raw(OpenDexFileBase64(kGoodTestDex, tmp.GetFilename().c_str(),
+  std::unique_ptr<const DexFile> raw(OpenDexFileBase64(kGoodTestDex,
+                                                       kLocationString,
                                                        &error_msg));
   ASSERT_TRUE(raw.get() != nullptr) << error_msg;
 }
@@ -1311,10 +1300,9 @@
 TEST_F(DexFileVerifierTest, DebugInfoTypeIdxTest) {
   {
     // The input dex file should be good before modification.
-    ScratchFile tmp;
     std::string error_msg;
     std::unique_ptr<const DexFile> raw(OpenDexFileBase64(kDebugInfoTestDex,
-                                                         tmp.GetFilename().c_str(),
+                                                         kLocationString,
                                                          &error_msg));
     ASSERT_TRUE(raw.get() != nullptr) << error_msg;
   }
@@ -1333,10 +1321,9 @@
   {
     // The input dex file should be good before modification. Any file is fine, as long as it
     // uses all sections.
-    ScratchFile tmp;
     std::string error_msg;
     std::unique_ptr<const DexFile> raw(OpenDexFileBase64(kGoodTestDex,
-                                                         tmp.GetFilename().c_str(),
+                                                         kLocationString,
                                                          &error_msg));
     ASSERT_TRUE(raw.get() != nullptr) << error_msg;
   }
@@ -1417,10 +1404,9 @@
 TEST_F(DexFileVerifierTest, ProtoOrdering) {
   {
     // The input dex file should be good before modification.
-    ScratchFile tmp;
     std::string error_msg;
     std::unique_ptr<const DexFile> raw(OpenDexFileBase64(kProtoOrderingTestDex,
-                                                         tmp.GetFilename().c_str(),
+                                                         kLocationString,
                                                          &error_msg));
     ASSERT_TRUE(raw.get() != nullptr) << error_msg;
   }