Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #include "common_test.h" |
| 4 | |
| 5 | #include "reference_table.h" |
| 6 | |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 7 | namespace art { |
| 8 | |
Brian Carlstrom | f734cf5 | 2011-08-17 16:28:14 -0700 | [diff] [blame] | 9 | class ReferenceTableTest : public CommonTest { |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 10 | }; |
| 11 | |
| 12 | TEST_F(ReferenceTableTest, Basics) { |
Elliott Hughes | bfaadc8 | 2011-08-18 17:36:58 -0700 | [diff] [blame] | 13 | Object* o1 = String::AllocFromModifiedUtf8("hello"); |
Elliott Hughes | 11e4507 | 2011-08-16 17:40:46 -0700 | [diff] [blame] | 14 | Object* o2 = ShortArray::Alloc(0); |
| 15 | |
| 16 | // TODO: rewrite Dump to take a std::ostream& so we can test it better. |
| 17 | |
| 18 | ReferenceTable rt("test", 0, 4); |
| 19 | rt.Dump(); |
| 20 | EXPECT_EQ(0U, rt.Size()); |
| 21 | rt.Remove(NULL); |
| 22 | EXPECT_EQ(0U, rt.Size()); |
| 23 | rt.Remove(o1); |
| 24 | EXPECT_EQ(0U, rt.Size()); |
| 25 | rt.Add(o1); |
| 26 | EXPECT_EQ(1U, rt.Size()); |
| 27 | rt.Add(o2); |
| 28 | EXPECT_EQ(2U, rt.Size()); |
| 29 | rt.Dump(); |
| 30 | rt.Remove(o1); |
| 31 | EXPECT_EQ(1U, rt.Size()); |
| 32 | rt.Remove(o2); |
| 33 | EXPECT_EQ(0U, rt.Size()); |
| 34 | } |
| 35 | |
| 36 | } // namespace art |