blob: c61e3c99c3855ab88ccecfc2de438fe1bbf968bd [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
7#include "gtest/gtest.h"
8
9namespace art {
10
11class ReferenceTableTest : public RuntimeTest {
12};
13
14TEST_F(ReferenceTableTest, Basics) {
15 Object* o1 = String::AllocFromModifiedUtf8(0, "hello");
16 Object* o2 = ShortArray::Alloc(0);
17
18 // TODO: rewrite Dump to take a std::ostream& so we can test it better.
19
20 ReferenceTable rt("test", 0, 4);
21 rt.Dump();
22 EXPECT_EQ(0U, rt.Size());
23 rt.Remove(NULL);
24 EXPECT_EQ(0U, rt.Size());
25 rt.Remove(o1);
26 EXPECT_EQ(0U, rt.Size());
27 rt.Add(o1);
28 EXPECT_EQ(1U, rt.Size());
29 rt.Add(o2);
30 EXPECT_EQ(2U, rt.Size());
31 rt.Dump();
32 rt.Remove(o1);
33 EXPECT_EQ(1U, rt.Size());
34 rt.Remove(o2);
35 EXPECT_EQ(0U, rt.Size());
36}
37
38} // namespace art