reference_table_test.cc revision 00f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abac
12faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes/*
22faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Copyright (C) 2011 The Android Open Source Project
32faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
42faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
52faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * you may not use this file except in compliance with the License.
62faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * You may obtain a copy of the License at
72faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
82faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
92faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes *
102faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * Unless required by applicable law or agreed to in writing, software
112faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
122faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * See the License for the specific language governing permissions and
142faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes * limitations under the License.
152faa5f1271587cda765f26bcf2951065300a01ffElliott Hughes */
1611e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes
1711e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes#include "common_test.h"
1811e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes
1911e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes#include "reference_table.h"
2011e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes
2111e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughesnamespace art {
2211e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes
23f734cf55d510976f4862b15e35fc86eae2a3daf8Brian Carlstromclass ReferenceTableTest : public CommonTest {
2411e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes};
2511e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes
2611e45077acba2e757799a00b3be9d63fec36a7ccElliott HughesTEST_F(ReferenceTableTest, Basics) {
2700f7d0eaa6bd93d33bf0c1429bf4ba0b3f28abacIan Rogers  ScopedObjectAccess soa(Thread::Current());
28bfaadc83460726b049614a8616effbb03a247552Elliott Hughes  Object* o1 = String::AllocFromModifiedUtf8("hello");
2911e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  Object* o2 = ShortArray::Alloc(0);
3011e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes
3111e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  ReferenceTable rt("test", 0, 4);
3273e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  std::ostringstream oss1;
3373e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  rt.Dump(oss1);
3473e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  EXPECT_TRUE(oss1.str().find("(empty)") != std::string::npos) << oss1.str();
3511e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  EXPECT_EQ(0U, rt.Size());
3611e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  rt.Remove(NULL);
3711e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  EXPECT_EQ(0U, rt.Size());
3811e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  rt.Remove(o1);
3911e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  EXPECT_EQ(0U, rt.Size());
4011e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  rt.Add(o1);
4111e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  EXPECT_EQ(1U, rt.Size());
4211e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  rt.Add(o2);
4311e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  EXPECT_EQ(2U, rt.Size());
4473e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  rt.Add(o2);
4573e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  EXPECT_EQ(3U, rt.Size());
4673e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  std::ostringstream oss2;
4773e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  rt.Dump(oss2);
4873e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  EXPECT_TRUE(oss2.str().find("Last 3 entries (of 3):") != std::string::npos) << oss2.str();
4973e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  EXPECT_TRUE(oss2.str().find("1 of java.lang.String") != std::string::npos) << oss2.str();
5073e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  EXPECT_TRUE(oss2.str().find("2 of short[] (1 unique instances)") != std::string::npos) << oss2.str();
5111e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  rt.Remove(o1);
5273e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  EXPECT_EQ(2U, rt.Size());
5373e66f73f5093b64f2b023ebbb85916a13d5c937Elliott Hughes  rt.Remove(o2);
5411e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  EXPECT_EQ(1U, rt.Size());
5511e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  rt.Remove(o2);
5611e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes  EXPECT_EQ(0U, rt.Size());
5711e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes}
5811e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes
5911e45077acba2e757799a00b3be9d63fec36a7ccElliott Hughes}  // namespace art
60