Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame^] | 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 | */ |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 16 | |
| 17 | #include "common_test.h" |
| 18 | |
| 19 | #include "reference_table.h" |
| 20 | |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 21 | namespace art { |
| 22 | |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 23 | class ReferenceTableTest : public CommonTest { |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | TEST_F(ReferenceTableTest, Basics) { |
Elliott Hughes | bfaadc8 | 2011-08-18 17:36:58 -0700 | [diff] [blame] | 27 | Object* o1 = String::AllocFromModifiedUtf8("hello"); |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 28 | 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 |