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

Unified Diff: test/UtilSplitString.cpp

Issue 5921969115496448: Issue 1115 - Some yahoo page not correctly shown on IE8 when ABP enabled (Closed)
Patch Set: x Created Jan. 29, 2015, 3:23 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
Index: test/UtilSplitString.cpp
diff --git a/test/UtilSplitString.cpp b/test/UtilSplitString.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a3ca8c3abe35860c632c4f026f4c57f00515aebc
--- /dev/null
+++ b/test/UtilSplitString.cpp
@@ -0,0 +1,122 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2015 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/>.
+ */
Eric 2015/02/02 18:41:58 Many of the same comments from the previous file a
+
+#include <fstream>
+#include <Windows.h>
+#include <gtest/gtest.h>
+
+#include "../src/shared/Utils.h"
+
+TEST(SplitStringTest, EmptyHandler)
+{
+ SplitString(L"aaa!asdasd!", L'!', std::function<bool(std::wstring::const_iterator, std::wstring::const_iterator)>());
+}
+
+TEST(SplitStringTest, EmptyQueryString)
+{
+ bool isCalled = false;
+ SplitString(L"", L'\0', [&isCalled](std::wstring::const_iterator, std::wstring::const_iterator)->bool
+ {
+ return isCalled = true;
+ });
+ EXPECT_FALSE(isCalled);
+}
+
+TEST(SplitStringTest, StringWithoutDelimiter)
+{
+ std::wstring value;
+ bool isCalled = false;
+ SplitString(L"value", L'D', [&value, &isCalled](std::wstring::const_iterator begin, std::wstring::const_iterator end)->bool
+ {
+ EXPECT_FALSE(isCalled);
+ isCalled = true;
+ value.assign(begin, end);
+ return true;
+ });
+ EXPECT_EQ(L"value", value);
+}
+
+TEST(SplitStringTest, StringWithDelimiter)
+{
+ std::wstring value[2];
+ int callNumber = 0;
+ SplitString(L"value1&value2", L'&', [&value, &callNumber](std::wstring::const_iterator begin, std::wstring::const_iterator end)->bool
+ {
+ value[callNumber++].assign(begin, end);
+ return true;
+ });
+ EXPECT_EQ(L"value1", value[0]);
+ EXPECT_EQ(L"value2", value[1]);
+ EXPECT_EQ(2, callNumber);
+}
+
+TEST(SplitStringTest, StringWithDelimiterAtTheEnd)
+{
+ std::wstring value[3];
+ int callNumber = 0;
+ SplitString(L"value1&value2&", L'&', [&value, &callNumber](std::wstring::const_iterator begin, std::wstring::const_iterator end)->bool
+ {
+ value[callNumber++].assign(begin, end);
+ return true;
+ });
+ EXPECT_EQ(L"value1", value[0]);
+ EXPECT_EQ(L"value2", value[1]);
+ EXPECT_EQ(L"", value[2]);
+ EXPECT_EQ(3, callNumber);
+}
+
+TEST(SplitStringTest, StringWithDelimiterAtTheBeginning)
+{
+ std::wstring value[3];
+ int callNumber = 0;
+ SplitString(L"&value1&value2", L'&', [&value, &callNumber](std::wstring::const_iterator begin, std::wstring::const_iterator end)->bool
+ {
+ value[callNumber++].assign(begin, end);
+ return true;
+ });
+ EXPECT_EQ(L"", value[0]);
+ EXPECT_EQ(L"value1", value[1]);
+ EXPECT_EQ(L"value2", value[2]);
+ EXPECT_EQ(3, callNumber);
+}
+
+TEST(SplitStringTest, StringWithOnlyDelimiters)
+{
+ std::wstring value[4];
+ int callNumber = 0;
+ SplitString(L"&&&", L'&', [&value, &callNumber](std::wstring::const_iterator begin, std::wstring::const_iterator end)->bool
+ {
+ value[callNumber++].assign(begin, end);
+ return true;
+ });
+ EXPECT_EQ(L"", value[0]);
+ EXPECT_EQ(L"", value[1]);
+ EXPECT_EQ(L"", value[2]);
+ EXPECT_EQ(L"", value[3]);
+ EXPECT_EQ(4, callNumber);
+}
+
+TEST(SplitStringTest, ProcessUntilHandlerReturnsFalse)
+{
+ int callNumber = 0;
+ // handler is called three times
+ SplitString(L"&&&&&&", L'&', [&callNumber](std::wstring::const_iterator begin, std::wstring::const_iterator end)->bool
+ {
+ return ++callNumber <= 2;
+ });
+ EXPECT_EQ(3, callNumber);
+}
« test/UtilProcessQueryStringParameters.cpp ('K') | « test/UtilProcessQueryStringParameters.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld