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