blob: 4c1e67fb111b0dd40ded4df6d300ece25eee3d4e [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 */
Elliott Hughes11e45072011-08-16 17:40:46 -070016
17#include "common_test.h"
18
19#include "reference_table.h"
20
Elliott Hughes11e45072011-08-16 17:40:46 -070021namespace art {
22
Brian Carlstromf734cf52011-08-17 16:28:14 -070023class ReferenceTableTest : public CommonTest {
Elliott Hughes11e45072011-08-16 17:40:46 -070024};
25
26TEST_F(ReferenceTableTest, Basics) {
Elliott Hughesbfaadc82011-08-18 17:36:58 -070027 Object* o1 = String::AllocFromModifiedUtf8("hello");
Elliott Hughes11e45072011-08-16 17:40:46 -070028 Object* o2 = ShortArray::Alloc(0);
29
30 // TODO: rewrite Dump to take a std::ostream& so we can test it better.
31
32 ReferenceTable rt("test", 0, 4);
33 rt.Dump();
34 EXPECT_EQ(0U, rt.Size());
35 rt.Remove(NULL);
36 EXPECT_EQ(0U, rt.Size());
37 rt.Remove(o1);
38 EXPECT_EQ(0U, rt.Size());
39 rt.Add(o1);
40 EXPECT_EQ(1U, rt.Size());
41 rt.Add(o2);
42 EXPECT_EQ(2U, rt.Size());
43 rt.Dump();
44 rt.Remove(o1);
45 EXPECT_EQ(1U, rt.Size());
46 rt.Remove(o2);
47 EXPECT_EQ(0U, rt.Size());
48}
49
50} // namespace art