jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 3 | #include "dex_verifier.h" |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | #include "UniquePtr.h" |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 8 | #include "class_linker.h" |
| 9 | #include "common_test.h" |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 10 | #include "dex_file.h" |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 11 | |
| 12 | namespace art { |
| 13 | |
| 14 | class DexVerifierTest : public CommonTest { |
| 15 | protected: |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 16 | void VerifyClass(ClassLoader* class_loader, const std::string& descriptor) { |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 17 | ASSERT_TRUE(descriptor != NULL); |
| 18 | Class* klass = class_linker_->FindSystemClass(descriptor); |
| 19 | |
| 20 | // Verify the class |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 21 | ASSERT_TRUE(DexVerifier::VerifyClass(klass)); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | void VerifyDexFile(const DexFile* dex, ClassLoader* class_loader) { |
| 25 | ASSERT_TRUE(dex != NULL); |
| 26 | |
| 27 | // Verify all the classes defined in this file |
| 28 | for (size_t i = 0; i < dex->NumClassDefs(); i++) { |
| 29 | const DexFile::ClassDef& class_def = dex->GetClassDef(i); |
| 30 | const char* descriptor = dex->GetClassDescriptor(class_def); |
| 31 | VerifyClass(class_loader, descriptor); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | }; |
| 36 | |
| 37 | TEST_F(DexVerifierTest, LibCore) { |
| 38 | VerifyDexFile(java_lang_dex_file_.get(), NULL); |
| 39 | } |
| 40 | |
| 41 | TEST_F(DexVerifierTest, IntMath) { |
Brian Carlstrom | 9baa4ae | 2011-09-01 21:14:14 -0700 | [diff] [blame] | 42 | const ClassLoader* class_loader = LoadDex("IntMath"); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 43 | Class* klass = class_linker_->FindClass("LIntMath;", class_loader); |
jeffhao | bdb7651 | 2011-09-07 11:43:16 -0700 | [diff] [blame] | 44 | ASSERT_TRUE(DexVerifier::VerifyClass(klass)); |
jeffhao | ba5ebb9 | 2011-08-25 17:24:37 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | } // namespace art |