dex_cache_test.cc revision 00f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abac
12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/*
22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project
32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License.
62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at
72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software
112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and
142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License.
152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */
167e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom
177e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom#include "class_linker.h"
187e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom#include "common_test.h"
197e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom#include "dex_cache.h"
207e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom#include "heap.h"
217e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom#include "object.h"
227e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom
237e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom#include <stdio.h>
247e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom
257e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstromnamespace art {
267e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom
27f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstromclass DexCacheTest : public CommonTest {};
287e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom
297e49dca262933bc30cbc8b9f07cfc8cce2343389Brian CarlstromTEST_F(DexCacheTest, Open) {
3000f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  ScopedObjectAccess soa(Thread::Current());
31a004aa933a58428489e42d77f707c2b063b73747Brian Carlstrom  SirtRef<DexCache> dex_cache(class_linker_->AllocDexCache(*java_lang_dex_file_));
3240381fb9dc4b4cf274f1e58b2cdf4396202c6189Brian Carlstrom  ASSERT_TRUE(dex_cache.get() != NULL);
33c4fa2c0c6302d3d9979e8d8a4030499c10d6b68bBrian Carlstrom
34a663ea5de4c9ab6b1510fdebd6d8eca77ba699aeBrian Carlstrom  EXPECT_EQ(java_lang_dex_file_->NumStringIds(), dex_cache->NumStrings());
351caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_EQ(java_lang_dex_file_->NumTypeIds(),   dex_cache->NumResolvedTypes());
361caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_EQ(java_lang_dex_file_->NumMethodIds(), dex_cache->NumResolvedMethods());
371caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_EQ(java_lang_dex_file_->NumFieldIds(),  dex_cache->NumResolvedFields());
381caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_EQ(java_lang_dex_file_->NumTypeIds(),   dex_cache->NumInitializedStaticStorage());
39c4fa2c0c6302d3d9979e8d8a4030499c10d6b68bBrian Carlstrom
40c4fa2c0c6302d3d9979e8d8a4030499c10d6b68bBrian Carlstrom  EXPECT_LE(0, dex_cache->GetStrings()->GetLength());
411caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_LE(0, dex_cache->GetResolvedTypes()->GetLength());
421caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_LE(0, dex_cache->GetResolvedMethods()->GetLength());
431caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_LE(0, dex_cache->GetResolvedFields()->GetLength());
441caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_LE(0, dex_cache->GetInitializedStaticStorage()->GetLength());
45c4fa2c0c6302d3d9979e8d8a4030499c10d6b68bBrian Carlstrom
46c4fa2c0c6302d3d9979e8d8a4030499c10d6b68bBrian Carlstrom  EXPECT_EQ(java_lang_dex_file_->NumStringIds(),
47c4fa2c0c6302d3d9979e8d8a4030499c10d6b68bBrian Carlstrom            static_cast<uint32_t>(dex_cache->GetStrings()->GetLength()));
48c4fa2c0c6302d3d9979e8d8a4030499c10d6b68bBrian Carlstrom  EXPECT_EQ(java_lang_dex_file_->NumTypeIds(),
491caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom            static_cast<uint32_t>(dex_cache->GetResolvedTypes()->GetLength()));
50c4fa2c0c6302d3d9979e8d8a4030499c10d6b68bBrian Carlstrom  EXPECT_EQ(java_lang_dex_file_->NumMethodIds(),
511caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom            static_cast<uint32_t>(dex_cache->GetResolvedMethods()->GetLength()));
52c4fa2c0c6302d3d9979e8d8a4030499c10d6b68bBrian Carlstrom  EXPECT_EQ(java_lang_dex_file_->NumFieldIds(),
531caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom            static_cast<uint32_t>(dex_cache->GetResolvedFields()->GetLength()));
541caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom  EXPECT_EQ(java_lang_dex_file_->NumTypeIds(),
551caa2c205e51dda670207828f25451fb7623cea6Brian Carlstrom            static_cast<uint32_t>(dex_cache->GetInitializedStaticStorage()->GetLength()));
567e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom}
577e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom
587e49dca262933bc30cbc8b9f07cfc8cce2343389Brian Carlstrom}  // namespace art
59