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

Unified Diff: test/ReferrerMapping.cpp

Issue 6307944991817728: Issue 984 - port referrer mapping from Android (Closed)
Patch Set: Created July 16, 2014, 9:05 a.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/ReferrerMapping.cpp ('K') | « src/ReferrerMapping.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/ReferrerMapping.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/ReferrerMapping.cpp
@@ -0,0 +1,86 @@
+/*
+ * This file is part of Adblock Plus <http://adblockplus.org/>,
+ * Copyright (C) 2006-2014 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 <AdblockPlus.h>
+#include <gtest/gtest.h>
+
+TEST(ReferrerMappingTest, EmptyReferrerChain)
+{
+ AdblockPlus::ReferrerMapping referrerMapping;
+ std::vector<std::string> referrerChain =
+ referrerMapping.BuildReferrerChain("first");
+ ASSERT_EQ(1, referrerChain.size());
+ ASSERT_EQ("first", referrerChain[0]);
+}
+
+TEST(ReferrerMappingTest, TwoElementReferrerChain)
+{
+ AdblockPlus::ReferrerMapping referrerMapping;
+ referrerMapping.Add("second", "first");
+ std::vector<std::string> referrerChain =
+ referrerMapping.BuildReferrerChain("second");
+ ASSERT_EQ(2, referrerChain.size());
+ ASSERT_EQ("first", referrerChain[0]);
+ ASSERT_EQ("second", referrerChain[1]);
+}
+
+TEST(ReferrerMappingTest, TenElementReferrerChain)
+{
+ AdblockPlus::ReferrerMapping referrerMapping;
+ referrerMapping.Add("second", "first");
+ referrerMapping.Add("third", "second");
+ referrerMapping.Add("fourth", "third");
+ referrerMapping.Add("fifth", "fourth");
+ referrerMapping.Add("sixth", "fifth");
+ referrerMapping.Add("seventh", "sixth");
+ referrerMapping.Add("eighth", "seventh");
+ referrerMapping.Add("ninth", "eighth");
+ referrerMapping.Add("tenth", "ninth");
+ std::vector<std::string> referrerChain =
+ referrerMapping.BuildReferrerChain("tenth");
+ ASSERT_EQ(10, referrerChain.size());
+ ASSERT_EQ("first", referrerChain[0]);
+ ASSERT_EQ("second", referrerChain[1]);
+ ASSERT_EQ("third", referrerChain[2]);
+ ASSERT_EQ("fourth", referrerChain[3]);
+ ASSERT_EQ("fifth", referrerChain[4]);
+ ASSERT_EQ("sixth", referrerChain[5]);
+ ASSERT_EQ("seventh", referrerChain[6]);
+ ASSERT_EQ("eighth", referrerChain[7]);
+ ASSERT_EQ("ninth", referrerChain[8]);
+ ASSERT_EQ("tenth", referrerChain[9]);
+}
+
+TEST(ReferrerMappingTest, CacheOnlyFiveUrls)
+{
+ AdblockPlus::ReferrerMapping referrerMapping(5);
+ referrerMapping.Add("second", "first");
+ referrerMapping.Add("third", "second");
+ referrerMapping.Add("fourth", "third");
+ referrerMapping.Add("fifth", "fourth");
+ referrerMapping.Add("sixth", "fifth");
+ referrerMapping.Add("seventh", "sixth");
+ std::vector<std::string> referrerChain =
+ referrerMapping.BuildReferrerChain("seventh");
+ ASSERT_EQ(6, referrerChain.size());
+ ASSERT_EQ("second", referrerChain[0]);
+ ASSERT_EQ("third", referrerChain[1]);
+ ASSERT_EQ("fourth", referrerChain[2]);
+ ASSERT_EQ("fifth", referrerChain[3]);
+ ASSERT_EQ("sixth", referrerChain[4]);
+ ASSERT_EQ("seventh", referrerChain[5]);
+}
« src/ReferrerMapping.cpp ('K') | « src/ReferrerMapping.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld