LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 #include <gtest/gtest.h> | 17 #include <gtest/gtest.h> |
18 #include "../../src/plugin/Instances.h" | 18 #include "../../src/plugin/Instances.h" |
19 | 19 |
20 typedef SyncMap<int, int, 0> SyncMapOne; | 20 typedef SyncMap<int, int, 0> SyncMapOne; |
21 | 21 |
22 TEST(SyncMap, Instantiate) | 22 TEST(SyncMap, Instantiate) |
23 { | 23 { |
24 SyncMapOne s; | 24 SyncMapOne s; |
25 } | 25 } |
26 | 26 |
27 TEST(SyncMap, OrdinaryAdded) | 27 TEST(SyncMap, OrdinaryAdded) |
28 { | 28 { |
29 SyncMapOne s; | 29 SyncMapOne s; |
30 ASSERT_TRUE(s.AddIfAbsent(1, 11)); | 30 ASSERT_TRUE(s.AddIfAbsent(1, 11)); |
31 ASSERT_TRUE(s.Locate(1) == 11); | 31 ASSERT_TRUE(s.Locate(1) == 11); |
32 ASSERT_TRUE(s.RemoveAndCheck(1)); | 32 ASSERT_TRUE(s.RemoveIfPresent(1)); |
33 } | 33 } |
34 | 34 |
35 TEST(SyncMap, OrdinaryNotAdded1) | 35 TEST(SyncMap, OrdinaryNotAdded1) |
36 { | 36 { |
37 SyncMapOne s; | 37 SyncMapOne s; |
38 ASSERT_TRUE(s.Locate(1) == 0); | 38 ASSERT_TRUE(s.Locate(1) == 0); |
39 } | 39 } |
40 | 40 |
41 TEST(SyncMap, OrdinaryNotAdded2) | 41 TEST(SyncMap, OrdinaryNotAdded2) |
42 { | 42 { |
43 SyncMapOne s; | 43 SyncMapOne s; |
44 ASSERT_TRUE(s.AddIfAbsent(1, 11)); | 44 ASSERT_TRUE(s.AddIfAbsent(1, 11)); |
45 ASSERT_TRUE(s.AddIfAbsent(2, 22)); | 45 ASSERT_TRUE(s.AddIfAbsent(2, 22)); |
46 ASSERT_TRUE(s.Locate(7) == 0); | 46 ASSERT_TRUE(s.Locate(7) == 0); |
47 } | 47 } |
48 | 48 |
49 TEST(SyncMap, WrongAddedTwice) | 49 TEST(SyncMap, WrongAddedTwice) |
50 { | 50 { |
51 SyncMapOne s; | 51 SyncMapOne s; |
52 ASSERT_TRUE(s.AddIfAbsent(3, 11)); | 52 ASSERT_TRUE(s.AddIfAbsent(3, 11)); |
53 ASSERT_FALSE(s.AddIfAbsent(3, 22)); | 53 ASSERT_FALSE(s.AddIfAbsent(3, 22)); |
54 } | 54 } |
55 | 55 |
56 TEST(SyncMap, AcceptableAddedRemovedAddedAgain) | 56 TEST(SyncMap, AcceptableAddedRemovedAddedAgain) |
57 { | 57 { |
58 SyncMapOne s; | 58 SyncMapOne s; |
59 ASSERT_TRUE(s.AddIfAbsent(1, 11)); | 59 ASSERT_TRUE(s.AddIfAbsent(1, 11)); |
60 ASSERT_TRUE(s.RemoveAndCheck(1)); | 60 ASSERT_TRUE(s.RemoveIfPresent(1)); |
61 ASSERT_TRUE(s.AddIfAbsent(1, 22)); | 61 ASSERT_TRUE(s.AddIfAbsent(1, 22)); |
62 } | 62 } |
63 | 63 |
64 TEST(SyncMap, WrongRemovedButNotAdded) | 64 TEST(SyncMap, WrongRemovedButNotAdded) |
65 { | 65 { |
66 SyncMapOne s; | 66 SyncMapOne s; |
67 ASSERT_FALSE(s.RemoveAndCheck(3)); | 67 ASSERT_FALSE(s.RemoveIfPresent(3)); |
68 } | 68 } |
69 | 69 |
LEFT | RIGHT |