1 /* 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 "dex_cache.h" 18 19 #include <stdio.h> 20 21 #include "class_linker.h" 22 #include "common_runtime_test.h" 23 #include "gc/heap.h" 24 #include "mirror/object_array-inl.h" 25 #include "mirror/object-inl.h" 26 #include "handle_scope-inl.h" 27 #include "scoped_thread_state_change.h" 28 29 namespace art { 30 namespace mirror { 31 32 class DexCacheTest : public CommonRuntimeTest {}; 33 34 TEST_F(DexCacheTest, Open) { 35 ScopedObjectAccess soa(Thread::Current()); 36 StackHandleScope<1> hs(soa.Self()); 37 Handle<DexCache> dex_cache( 38 hs.NewHandle(class_linker_->AllocDexCache(soa.Self(), *java_lang_dex_file_))); 39 ASSERT_TRUE(dex_cache.Get() != NULL); 40 41 EXPECT_EQ(java_lang_dex_file_->NumStringIds(), dex_cache->NumStrings()); 42 EXPECT_EQ(java_lang_dex_file_->NumTypeIds(), dex_cache->NumResolvedTypes()); 43 EXPECT_EQ(java_lang_dex_file_->NumMethodIds(), dex_cache->NumResolvedMethods()); 44 EXPECT_EQ(java_lang_dex_file_->NumFieldIds(), dex_cache->NumResolvedFields()); 45 46 EXPECT_LE(0, dex_cache->GetStrings()->GetLength()); 47 EXPECT_LE(0, dex_cache->GetResolvedTypes()->GetLength()); 48 EXPECT_LE(0, dex_cache->GetResolvedMethods()->GetLength()); 49 EXPECT_LE(0, dex_cache->GetResolvedFields()->GetLength()); 50 51 EXPECT_EQ(java_lang_dex_file_->NumStringIds(), 52 static_cast<uint32_t>(dex_cache->GetStrings()->GetLength())); 53 EXPECT_EQ(java_lang_dex_file_->NumTypeIds(), 54 static_cast<uint32_t>(dex_cache->GetResolvedTypes()->GetLength())); 55 EXPECT_EQ(java_lang_dex_file_->NumMethodIds(), 56 static_cast<uint32_t>(dex_cache->GetResolvedMethods()->GetLength())); 57 EXPECT_EQ(java_lang_dex_file_->NumFieldIds(), 58 static_cast<uint32_t>(dex_cache->GetResolvedFields()->GetLength())); 59 } 60 61 } // namespace mirror 62 } // namespace art 63