blob: 3d753e1e151e7871b3549473231db1f85e0f858e [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
17#include "class_linker.h"
18#include "common_test.h"
19#include "dex_cache.h"
20#include "heap.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "mirror/object_array-inl.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070022#include "mirror/object-inl.h"
Ian Rogers1f539342012-10-03 21:09:42 -070023#include "sirt_ref.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070024
25#include <stdio.h>
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070026
27namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028namespace mirror {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070029
Brian Carlstromf734cf52011-08-17 16:28:14 -070030class DexCacheTest : public CommonTest {};
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070031
32TEST_F(DexCacheTest, Open) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070033 ScopedObjectAccess soa(Thread::Current());
Ian Rogers50b35e22012-10-04 10:09:15 -070034 SirtRef<DexCache> dex_cache(soa.Self(), class_linker_->AllocDexCache(soa.Self(),
35 *java_lang_dex_file_));
Brian Carlstrom40381fb2011-10-19 14:13:40 -070036 ASSERT_TRUE(dex_cache.get() != NULL);
Brian Carlstromc4fa2c02011-08-21 03:00:12 -070037
Brian Carlstroma663ea52011-08-19 23:33:41 -070038 EXPECT_EQ(java_lang_dex_file_->NumStringIds(), dex_cache->NumStrings());
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070039 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());
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070042 EXPECT_EQ(java_lang_dex_file_->NumTypeIds(), dex_cache->NumInitializedStaticStorage());
Brian Carlstromc4fa2c02011-08-21 03:00:12 -070043
44 EXPECT_LE(0, dex_cache->GetStrings()->GetLength());
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070045 EXPECT_LE(0, dex_cache->GetResolvedTypes()->GetLength());
46 EXPECT_LE(0, dex_cache->GetResolvedMethods()->GetLength());
47 EXPECT_LE(0, dex_cache->GetResolvedFields()->GetLength());
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070048 EXPECT_LE(0, dex_cache->GetInitializedStaticStorage()->GetLength());
Brian Carlstromc4fa2c02011-08-21 03:00:12 -070049
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(),
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070053 static_cast<uint32_t>(dex_cache->GetResolvedTypes()->GetLength()));
Brian Carlstromc4fa2c02011-08-21 03:00:12 -070054 EXPECT_EQ(java_lang_dex_file_->NumMethodIds(),
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070055 static_cast<uint32_t>(dex_cache->GetResolvedMethods()->GetLength()));
Brian Carlstromc4fa2c02011-08-21 03:00:12 -070056 EXPECT_EQ(java_lang_dex_file_->NumFieldIds(),
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070057 static_cast<uint32_t>(dex_cache->GetResolvedFields()->GetLength()));
Brian Carlstrom1caa2c22011-08-28 13:02:33 -070058 EXPECT_EQ(java_lang_dex_file_->NumTypeIds(),
59 static_cast<uint32_t>(dex_cache->GetInitializedStaticStorage()->GetLength()));
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070060}
61
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080062} // namespace mirror
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070063} // namespace art