| Index: test/plugin/InstancesTest.cpp |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/test/plugin/InstancesTest.cpp |
| @@ -0,0 +1,74 @@ |
| +/* |
| + * This file is part of Adblock Plus <https://adblockplus.org/>, |
| + * Copyright (C) 2006-2016 Eyeo GmbH |
| + * |
| + * Adblock Plus is free software: you can redistribute it and/or modify |
| + * it under the terms of the GNU General Public License version 3 as |
| + * published by the Free Software Foundation. |
| + * |
| + * Adblock Plus is distributed in the hope that it will be useful, |
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| + * GNU General Public License for more details. |
| + * |
| + * You should have received a copy of the GNU General Public License |
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| + */ |
| + |
| +#include <gtest/gtest.h> |
| +#include "../../src/plugin/Instances.h" |
| + |
| +typedef SyncSet<int, 0> SyncSetOne; |
| +bool IsFive(int x) |
| +{ |
| + return x == 5; |
| +} |
| + |
| +TEST(SyncSet, Instantiate) |
| +{ |
| + SyncSetOne s; |
| +} |
| + |
| +TEST(SyncSet, OrdinaryInserted) |
| +{ |
| + SyncSetOne s; |
| + ASSERT_TRUE(s.InsertIfAbsent(5)); |
| + EXPECT_EQ(5, s.LinearSearch(IsFive)); |
| + ASSERT_TRUE(s.EraseWithCheck(5)); |
| + EXPECT_EQ(0, s.LinearSearch(IsFive)); |
| +} |
| + |
| +TEST(SyncSet, OrdinaryNotInserted1) |
| +{ |
| + SyncSetOne s; |
| + ASSERT_EQ(0, s.LinearSearch(IsFive)); |
| +} |
| + |
| +TEST(SyncSet, OrdinaryNotInserted2) |
| +{ |
| + SyncSetOne s; |
| + ASSERT_TRUE(s.InsertIfAbsent(1)); |
| + ASSERT_TRUE(s.InsertIfAbsent(2)); |
| + ASSERT_EQ(0, s.LinearSearch(IsFive)); |
| +} |
| + |
| +TEST(SyncSet, WrongAddedTwice) |
| +{ |
| + SyncSetOne s; |
| + ASSERT_TRUE(s.InsertIfAbsent(3)); |
| + ASSERT_FALSE(s.InsertIfAbsent(3)); |
| +} |
| + |
| +TEST(SyncSet, AcceptableAddRemoveAddAgain) |
| +{ |
| + SyncSetOne s; |
| + ASSERT_TRUE(s.InsertIfAbsent(5)); |
| + ASSERT_TRUE(s.EraseWithCheck(5)); |
| + ASSERT_TRUE(s.InsertIfAbsent(5)); |
| +} |
| + |
| +TEST(SyncSet, WrongEraseWithoutInsert) |
| +{ |
| + SyncSetOne s; |
| + ASSERT_FALSE(s.EraseWithCheck(3)); |
| +} |