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
TEST_F(DexCacheTest,Open)34 TEST_F(DexCacheTest, Open) {
35 ScopedObjectAccess soa(Thread::Current());
36 StackHandleScope<1> hs(soa.Self());
37 ASSERT_TRUE(java_lang_dex_file_ != nullptr);
38 Handle<DexCache> dex_cache(
39 hs.NewHandle(class_linker_->AllocDexCache(soa.Self(), *java_lang_dex_file_)));
40 ASSERT_TRUE(dex_cache.Get() != nullptr);
41
42 EXPECT_EQ(java_lang_dex_file_->NumStringIds(), dex_cache->NumStrings());
43 EXPECT_EQ(java_lang_dex_file_->NumTypeIds(), dex_cache->NumResolvedTypes());
44 EXPECT_EQ(java_lang_dex_file_->NumMethodIds(), dex_cache->NumResolvedMethods());
45 EXPECT_EQ(java_lang_dex_file_->NumFieldIds(), dex_cache->NumResolvedFields());
46
47 EXPECT_LE(0, dex_cache->GetStrings()->GetLength());
48 EXPECT_LE(0, dex_cache->GetResolvedTypes()->GetLength());
49 EXPECT_LE(0, dex_cache->GetResolvedMethods()->GetLength());
50 EXPECT_LE(0u, dex_cache->NumResolvedFields());
51
52 EXPECT_EQ(java_lang_dex_file_->NumStringIds(),
53 static_cast<uint32_t>(dex_cache->GetStrings()->GetLength()));
54 EXPECT_EQ(java_lang_dex_file_->NumTypeIds(),
55 static_cast<uint32_t>(dex_cache->GetResolvedTypes()->GetLength()));
56 EXPECT_EQ(java_lang_dex_file_->NumMethodIds(),
57 static_cast<uint32_t>(dex_cache->GetResolvedMethods()->GetLength()));
58 EXPECT_EQ(java_lang_dex_file_->NumFieldIds(), dex_cache->NumResolvedFields());
59 }
60
61 } // namespace mirror
62 } // namespace art
63