blob: 73ec87becaa253858999ebeeb76b0837eabff64b [file] [log] [blame]
Elliott Hughes11e45072011-08-16 17:40:46 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#include "common_test.h"
4
5#include "reference_table.h"
6
Elliott Hughes11e45072011-08-16 17:40:46 -07007namespace art {
8
Brian Carlstromf734cf52011-08-17 16:28:14 -07009class ReferenceTableTest : public CommonTest {
Elliott Hughes11e45072011-08-16 17:40:46 -070010};
11
12TEST_F(ReferenceTableTest, Basics) {
Elliott Hughesbfaadc82011-08-18 17:36:58 -070013 Object* o1 = String::AllocFromModifiedUtf8("hello");
Elliott Hughes11e45072011-08-16 17:40:46 -070014 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