blob: 1f065e6fde271e7e35f1d15a3067bf82564b2eb6 [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
Brian Carlstromf734cf52011-08-17 16:28:14 -070011class ReferenceTableTest : public CommonTest {
Elliott Hughes11e45072011-08-16 17:40:46 -070012};
13
14TEST_F(ReferenceTableTest, Basics) {
Elliott Hughesbfaadc82011-08-18 17:36:58 -070015 Object* o1 = String::AllocFromModifiedUtf8("hello");
Elliott Hughes11e45072011-08-16 17:40:46 -070016 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