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

Unified Diff: test/compiled/StringMap.cpp

Issue 29680720: Issue 6221 - Add native tests. (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Changes from review. Created Jan. 27, 2018, 3:33 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
Index: test/compiled/StringMap.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/compiled/StringMap.cpp
@@ -0,0 +1,82 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-present 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 <string>
+#include "gtest/gtest.h"
+#include "compiled/StringMap.h"
+
+template<template <typename T> class S>
+void testStringMap()
+{
+ S<std::string> map;
+ auto key = u"Foobar"_str;
+ EXPECT_EQ(key.length(), 6);
+ EXPECT_EQ(map.size(), 0);
+
+ map[u"Foobar"_str] = std::string("one");
sergei 2018/01/29 13:38:44 just wonder, is it required to use `std::string("o
hub 2018/01/29 16:57:46 constructor is implicit, so it is not needed.
+ EXPECT_EQ(map.size(), 1);
+
+ map[u""_str] = std::string("null");
+ EXPECT_EQ(map.size(), 2);
+
+ auto entry = map.find(u"Foobar"_str);
+ EXPECT_TRUE(entry);
+
+ entry = map.find(u"Foobar2"_str);
+ EXPECT_FALSE(entry);
+
+ map[u"Foobar2"_str] = std::string("two");
+ entry = map.find(u"Foobar2"_str);
+ EXPECT_TRUE(entry);
+
+ map[u"Foobar3"_str] = std::string("three");
+ entry = map.find(u"Foobar3"_str);
+ EXPECT_TRUE(entry);
+
+ EXPECT_EQ(map.size(), 4);
+
+ map.erase(u"Foobar2"_str);
+
+ // DISABLED. This should be true, but it isn't
+ //EXPECT_EQ(map.size(), 2);
sergei 2018/01/29 13:38:44 it should be compared against 3, not 2.
hub 2018/01/29 16:57:46 forgot to change that one. Done
+
+ entry = map.find(u"Foobar2"_str);
+ EXPECT_FALSE(entry);
+
+ int i = 0;
+ for (const auto& e : map)
+ {
+ EXPECT_FALSE(e.is_invalid());
+ // DISABLED entries that are deleted shouldn't be returned.
+ // See issue #6281
+ //EXPECT_FALSE(e.is_deleted());
+ i++;
+ }
+
+ EXPECT_EQ(i, 4); // SHOULD be 3. See issue #6281
+ EXPECT_EQ(i, map.size());
+}
+
+TEST(TestStringMap, stringMap)
+{
+ testStringMap<StringMap>();
+}
+
+TEST(TestStringMap, ownedStringMap)
+{
+ testStringMap<OwnedStringMap>();
+}

Powered by Google App Engine
This is Rietveld