OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/values.h" | 6 #include "base/values.h" |
7 #include "extensions/common/value_counter.h" | 7 #include "extensions/common/value_counter.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 class ValueCounterUnittest : public testing::Test { | 10 using ValueCounterTest = testing::Test; |
11 }; | |
12 | 11 |
13 TEST_F(ValueCounterUnittest, TestAddingSameValue) { | 12 namespace extensions { |
14 extensions::ValueCounter vc; | 13 |
| 14 TEST_F(ValueCounterTest, TestAddingSameValue) { |
| 15 ValueCounter vc; |
15 base::ListValue value; | 16 base::ListValue value; |
16 ASSERT_EQ(1, vc.Add(value)); | 17 ASSERT_TRUE(vc.Add(value)); |
17 ASSERT_EQ(2, vc.Add(value)); | 18 ASSERT_FALSE(vc.Add(value)); |
18 } | 19 } |
19 | 20 |
20 TEST_F(ValueCounterUnittest, TestAddingDifferentValue) { | 21 TEST_F(ValueCounterTest, TestAddingDifferentValue) { |
21 extensions::ValueCounter vc; | 22 ValueCounter vc; |
22 base::ListValue value1; | 23 base::ListValue value1; |
23 base::DictionaryValue value2; | 24 base::DictionaryValue value2; |
24 ASSERT_EQ(1, vc.Add(value1)); | 25 ASSERT_TRUE(vc.Add(value1)); |
25 ASSERT_EQ(1, vc.Add(value2)); | 26 ASSERT_TRUE(vc.Add(value2)); |
26 } | 27 } |
27 | 28 |
28 TEST_F(ValueCounterUnittest, TestRemovingValue) { | 29 TEST_F(ValueCounterTest, TestRemovingSameValue) { |
29 extensions::ValueCounter vc; | 30 ValueCounter vc; |
30 base::ListValue value; | 31 base::ListValue value; |
31 ASSERT_EQ(1, vc.Add(value)); | 32 vc.Add(value); |
32 ASSERT_EQ(2, vc.Add(value)); | 33 vc.Add(value); |
33 ASSERT_EQ(1, vc.Remove(value)); | 34 ASSERT_FALSE(vc.Remove(value)); |
34 ASSERT_EQ(0, vc.Remove(value)); | 35 ASSERT_TRUE(vc.Remove(value)); |
| 36 ASSERT_FALSE(vc.Remove(value)); |
35 } | 37 } |
36 | 38 |
37 TEST_F(ValueCounterUnittest, TestAddIfMissing) { | 39 TEST_F(ValueCounterTest, TestReAddingSameValue) { |
38 extensions::ValueCounter vc; | 40 ValueCounter vc; |
39 base::ListValue value; | 41 base::ListValue value; |
40 ASSERT_EQ(1, vc.AddIfMissing(value)); | 42 ASSERT_FALSE(vc.Remove(value)); |
41 ASSERT_EQ(1, vc.AddIfMissing(value)); | 43 ASSERT_TRUE(vc.Add(value)); |
| 44 ASSERT_TRUE(vc.Remove(value)); |
| 45 ASSERT_TRUE(vc.Add(value)); |
| 46 ASSERT_TRUE(vc.Remove(value)); |
| 47 ASSERT_FALSE(vc.Remove(value)); |
42 } | 48 } |
| 49 |
| 50 TEST_F(ValueCounterTest, TestIsEmpty) { |
| 51 ValueCounter vc; |
| 52 base::ListValue value1; |
| 53 base::DictionaryValue value2; |
| 54 ASSERT_TRUE(vc.is_empty()); |
| 55 vc.Add(value1); |
| 56 ASSERT_FALSE(vc.is_empty()); |
| 57 vc.Remove(value1); |
| 58 ASSERT_TRUE(vc.is_empty()); |
| 59 vc.Add(value1); |
| 60 vc.Add(value2); |
| 61 ASSERT_FALSE(vc.is_empty()); |
| 62 vc.Remove(value1); |
| 63 ASSERT_FALSE(vc.is_empty()); |
| 64 vc.Remove(value2); |
| 65 ASSERT_TRUE(vc.is_empty()); |
| 66 } |
| 67 |
| 68 } // namespace extensions |
OLD | NEW |