Add dex file writer to dexlayout tool.

All sections are being written out properly.
There is one small difference:
  - unindexed string data is not written out

Bug: 29921113
Test: mm test-art-host-gtest-dexlayout_test
Change-Id: I3872327526a350f33f0f851516a389622c1a54ae
diff --git a/dexlayout/dexlayout_test.cc b/dexlayout/dexlayout_test.cc
index 42b64c3..63dc972 100644
--- a/dexlayout/dexlayout_test.cc
+++ b/dexlayout/dexlayout_test.cc
@@ -36,8 +36,8 @@
     dex_file_ = GetLibCoreDexFileNames()[0];
   }
 
-  // Runs test with given arguments.
-  bool Exec(std::string* error_msg) {
+  // Runs FullPlainOutput test.
+  bool FullPlainOutputExec(std::string* error_msg) {
     // TODO: dexdump2 -> dexdump ?
     ScratchFile dexdump_output;
     std::string dexdump_filename = dexdump_output.GetFilename();
@@ -67,6 +67,41 @@
     return true;
   }
 
+  // Runs FullPlainOutput test.
+  bool DexFileOutputExec(std::string* error_msg) {
+    ScratchFile dexlayout_output;
+    std::string dexlayout_filename = dexlayout_output.GetFilename();
+    std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
+    EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
+    std::vector<std::string> dexlayout_exec_argv =
+        { dexlayout, "-d", "-f", "-h", "-l", "plain", "-w", "-o", dexlayout_filename, dex_file_ };
+
+    if (!::art::Exec(dexlayout_exec_argv, error_msg)) {
+      return false;
+    }
+
+    size_t last_slash = dexlayout_filename.rfind("/");
+    std::string scratch_directory = dexlayout_filename.substr(0, last_slash + 1);
+    std::vector<std::string> unzip_exec_argv =
+        { "/usr/bin/unzip", dex_file_, "classes.dex", "-d", scratch_directory};
+    if (!::art::Exec(unzip_exec_argv, error_msg)) {
+      return false;
+    }
+
+    std::vector<std::string> diff_exec_argv =
+        { "/usr/bin/diff", scratch_directory + "classes.dex" , dex_file_ + ".out" };
+    if (!::art::Exec(diff_exec_argv, error_msg)) {
+      return false;
+    }
+
+    std::vector<std::string> rm_exec_argv = { "/bin/rm", scratch_directory + "classes.dex" };
+    if (!::art::Exec(rm_exec_argv, error_msg)) {
+      return false;
+    }
+
+    return true;
+  }
+
   std::string dex_file_;
 };
 
@@ -75,7 +110,14 @@
   // Disable test on target.
   TEST_DISABLED_FOR_TARGET();
   std::string error_msg;
-  ASSERT_TRUE(Exec(&error_msg)) << error_msg;
+  ASSERT_TRUE(FullPlainOutputExec(&error_msg)) << error_msg;
+}
+
+TEST_F(DexLayoutTest, DexFileOutput) {
+  // Disable test on target.
+  TEST_DISABLED_FOR_TARGET();
+  std::string error_msg;
+  ASSERT_TRUE(DexFileOutputExec(&error_msg)) << error_msg;
 }
 
 }  // namespace art