blob: 1d6846b6c47f03773d62905f50a108d4bc337c27 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 */
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070016
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070017#include "dex_cache.h"
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080018
19#include <stdio.h>
20
21#include "class_linker.h"
22#include "common_runtime_test.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070023#include "gc/heap.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080024#include "mirror/object_array-inl.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070025#include "mirror/object-inl.h"
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070026#include "handle_scope-inl.h"
Ian Rogerse63db272014-07-15 15:36:11 -070027#include "scoped_thread_state_change.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070028
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070029namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030namespace mirror {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070031
Brian Carlstroma1ce1fe2014-02-24 23:23:58 -080032class DexCacheTest : public CommonRuntimeTest {};
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070033
34TEST_F(DexCacheTest, Open) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070035 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070036 StackHandleScope<1> hs(soa.Self());
Richard Uhlerfbef44d2014-12-23 09:48:51 -080037 ASSERT_TRUE(java_lang_dex_file_ != NULL);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070038 Handle<DexCache> dex_cache(
39 hs.NewHandle(class_linker_->AllocDexCache(soa.Self(), *java_lang_dex_file_)));
40 ASSERT_TRUE(dex_cache.Get() != NULL);
Brian Carlstromc4fa2c02011-08-21 03:00:12 -070041
Brian Carlstroma663ea52011-08-19 23:33:41 -070042 EXPECT_EQ(java_lang_dex_file_->NumStringIds(), dex_cache->NumStrings());
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070043 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());
Brian Carlstromc4fa2c02011-08-21 03:00:12 -070046
47 EXPECT_LE(0, dex_cache->GetStrings()->GetLength());
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070048 EXPECT_LE(0, dex_cache->GetResolvedTypes()->GetLength());
49 EXPECT_LE(0, dex_cache->GetResolvedMethods()->GetLength());
Mathieu Chartierc7853442015-03-27 14:35:38 -070050 EXPECT_LE(0u, dex_cache->NumResolvedFields());
Brian Carlstromc4fa2c02011-08-21 03:00:12 -070051
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(),
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070055 static_cast<uint32_t>(dex_cache->GetResolvedTypes()->GetLength()));
Brian Carlstromc4fa2c02011-08-21 03:00:12 -070056 EXPECT_EQ(java_lang_dex_file_->NumMethodIds(),
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070057 static_cast<uint32_t>(dex_cache->GetResolvedMethods()->GetLength()));
Mathieu Chartierc7853442015-03-27 14:35:38 -070058 EXPECT_EQ(java_lang_dex_file_->NumFieldIds(), dex_cache->NumResolvedFields());
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070059}
60
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080061} // namespace mirror
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070062} // namespace art