blob: 5c23e9fb79fa7910663358fd7b6e6e3312040d0b [file] [log] [blame]
Ian Rogers776ac1f2012-04-13 23:36:36 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdio.h>
18
19#include "UniquePtr.h"
20#include "class_linker.h"
21#include "common_test.h"
22#include "dex_file.h"
23#include "method_verifier.h"
24
25namespace art {
26namespace verifier {
27
28class MethodVerifierTest : public CommonTest {
29 protected:
30 void VerifyClass(const std::string& descriptor) {
31 ASSERT_TRUE(descriptor != NULL);
32 Class* klass = class_linker_->FindSystemClass(descriptor.c_str());
33
34 // Verify the class
35 std::string error_msg;
jeffhaof1e6b7c2012-06-05 18:33:30 -070036 ASSERT_TRUE(MethodVerifier::VerifyClass(klass, error_msg) == MethodVerifier::kNoFailure) << error_msg;
Ian Rogers776ac1f2012-04-13 23:36:36 -070037 }
38
39 void VerifyDexFile(const DexFile* dex) {
40 ASSERT_TRUE(dex != NULL);
41
42 // Verify all the classes defined in this file
43 for (size_t i = 0; i < dex->NumClassDefs(); i++) {
44 const DexFile::ClassDef& class_def = dex->GetClassDef(i);
45 const char* descriptor = dex->GetClassDescriptor(class_def);
46 VerifyClass(descriptor);
47 }
48 }
49};
50
51TEST_F(MethodVerifierTest, LibCore) {
52 VerifyDexFile(java_lang_dex_file_);
53}
54
55TEST_F(MethodVerifierTest, IntMath) {
56 SirtRef<ClassLoader> class_loader(LoadDex("IntMath"));
57 Class* klass = class_linker_->FindClass("LIntMath;", class_loader.get());
58 std::string error_msg;
jeffhaof1e6b7c2012-06-05 18:33:30 -070059 ASSERT_TRUE(MethodVerifier::VerifyClass(klass, error_msg) == MethodVerifier::kNoFailure) << error_msg;
Ian Rogers776ac1f2012-04-13 23:36:36 -070060}
61
62} // namespace verifier
63} // namespace art