Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/plugin/InstancesTest.cpp

Issue 29333107: Issue #1652, #3456 - Replace 's_asyncWebBrowser2' with thread-safe facilities
Patch Set: Created Dec. 29, 2015, 5:54 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/plugin/PluginClass.cpp ('K') | « src/plugin/PluginClass.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
+}
« src/plugin/PluginClass.cpp ('K') | « src/plugin/PluginClass.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld