Fix OatHeader.isValid
Change-Id: I4371b9e7082a5131622680fea472da9d7e24f750
diff --git a/src/oat_test.cc b/src/oat_test.cc
index 3df831c..64c502d 100644
--- a/src/oat_test.cc
+++ b/src/oat_test.cc
@@ -89,6 +89,7 @@
OatFile::kRelocNone));
ASSERT_TRUE(oat_file.get() != NULL);
const OatHeader& oat_header = oat_file->GetOatHeader();
+ ASSERT_TRUE(oat_header.IsValid());
ASSERT_EQ(1U, oat_header.GetDexFileCount());
ASSERT_EQ(42U, oat_header.GetImageFileLocationOatChecksum());
ASSERT_EQ(4096U, oat_header.GetImageFileLocationOatBegin());
@@ -135,4 +136,24 @@
#endif
}
+TEST_F(OatTest, OatHeaderIsValid) {
+ InstructionSet instruction_set = kX86;
+ std::vector<const DexFile*> dex_files;
+ uint32_t image_file_location_oat_checksum = 0;
+ uint32_t image_file_location_oat_begin = 0;
+ const std::string image_file_location;
+ OatHeader oat_header(instruction_set,
+ &dex_files,
+ image_file_location_oat_checksum,
+ image_file_location_oat_begin,
+ image_file_location);
+ ASSERT_TRUE(oat_header.IsValid());
+
+ char* magic = const_cast<char*>(oat_header.GetMagic());
+ strcpy(magic, ""); // bad magic
+ ASSERT_FALSE(oat_header.IsValid());
+ strcpy(magic, "oat\n000"); // bad version
+ ASSERT_FALSE(oat_header.IsValid());
+}
+
} // namespace art