Index: dependencies
===================================================================
--- a/dependencies
+++ b/dependencies
@@ -1,3 +1,4 @@
_root = hg:https://hg.adblockplus.org/ git:https://github.com/adblockplus/
_self = buildtools/ensure_dependencies.py
buildtools = buildtools hg:3816c08c0f98 git:93e54d4
+third_party/googletest = googletest-github hg:368e1f54e5f6 git:d225acc90bc3a8c420a9bcd1f033033c1ccd7fe0
Index: meson.build
===================================================================
--- a/meson.build
+++ b/meson.build
@@ -187,14 +187,40 @@
depend_files: [ JS_LIBRARY ],
command: [
emcc, '-o', output_file,
'--post-js', bindings_output,
'--js-library', JS_LIBRARY,
'@INPUT@'
] + compiler_args + optional_args)
else
+ GTEST_DIR = join_paths('third-party', 'googletest', 'googletest')
+ GTEST_PARAMS = []
+ compiler = meson.get_compiler('cpp')
+ if compiler.has_argument('-pthread')
+ GTEST_PARAMS += '-pthread'
+ endif
+
+ test_sources = [
+ 'test/compiled/abptest.cpp',
+ 'test/compiled/String.cpp',
+ 'test/compiled/StringMap.cpp',
+ 'test/compiled/RegExp.cpp',
+ ]
+
adblockpluscore = library('adblockpluscore', shared_sources,
native_sources,
cpp_args: ADDITIONAL_PARAMS + CORE_PARAMS,
link_args: LINK_PARAMS)
+ gtest = static_library('gtest', files(join_paths(GTEST_DIR, 'src', 'gtest-all.cc')),
+ include_directories: [
+ include_directories(join_paths(GTEST_DIR, 'include'), is_system: true),
+ include_directories(GTEST_DIR)
+ ],
+ cpp_args: GTEST_PARAMS)
+ abptest = executable('abptest', test_sources,
+ cpp_args: ADDITIONAL_PARAMS + CORE_PARAMS,
+ include_directories: include_directories(join_paths(GTEST_DIR, 'include')),
+ link_args: LINK_PARAMS,
+ link_with: [ adblockpluscore, gtest ])
+ test('abptest', abptest)
endif
Index: test/compiled/RegExp.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/compiled/RegExp.cpp
@@ -0,0 +1,32 @@
+/*
+ * This file is part of Adblock Plus ,
+ * 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 .
+ */
+
+#include "gtest/gtest.h"
+#include "compiled/String.h"
+
+TEST(TestRegexp, RegExp)
+{
+ auto id = GenerateRegExp(u"[0-9]*"_str, false);
+ EXPECT_EQ(id, 0);
+ EXPECT_FALSE(TestRegExp(id, u"abcd"_str));
+ EXPECT_TRUE(TestRegExp(id, u"1234"_str));
+
+ DeleteRegExp(id);
+ // RegExp has been delete: all is false
+ EXPECT_FALSE(TestRegExp(id, u"abcd"_str));
+ EXPECT_FALSE(TestRegExp(id, u"1234"_str));
+}
Index: test/compiled/String.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/compiled/String.cpp
@@ -0,0 +1,48 @@
+/*
+ * This file is part of Adblock Plus ,
+ * 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 .
+ */
+
+#include
+#include "gtest/gtest.h"
+#include "compiled/String.h"
+
+TEST(TestString, constructInvalidDependentString)
+{
+ DependentString s;
+ EXPECT_TRUE(s.is_invalid());
+
+ DependentString s2(s);
+ EXPECT_TRUE(s2.is_invalid());
+}
+
+TEST(TestString, constructInvalidOwnedString)
+{
+ OwnedString s;
+ EXPECT_TRUE(s.is_invalid());
+
+ // Valid string
+ OwnedString s2(2);
+ EXPECT_FALSE(s2.is_invalid());
+
+ // Ensure we still have an invalid string.
+ OwnedString s3(s);
+ EXPECT_TRUE(s3.is_invalid());
+
+ // Empty valid string lead to valid string.
+ OwnedString s4(u""_str);
+ EXPECT_FALSE(s4.is_invalid());
+}
+
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 ,
+ * 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 .
+ */
+
+#include
+#include "gtest/gtest.h"
+#include "compiled/StringMap.h"
+
+template class S>
+void testStringMap()
+{
+ S map;
+ auto key = u"Foobar"_str;
+ EXPECT_EQ(key.length(), 6);
+ EXPECT_EQ(map.size(), 0);
+
+ map[u"Foobar"_str] = "one";
+ EXPECT_EQ(map.size(), 1);
+
+ map[u""_str] = "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] = "two";
+ entry = map.find(u"Foobar2"_str);
+ EXPECT_TRUE(entry);
+
+ map[u"Foobar3"_str] = "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(), 3);
+
+ 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();
+}
+
+TEST(TestStringMap, ownedStringMap)
+{
+ testStringMap();
+}
Index: test/compiled/abptest.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/compiled/abptest.cpp
@@ -0,0 +1,25 @@
+/*
+ * This file is part of Adblock Plus ,
+ * 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 .
+ */
+
+#include "gtest/gtest.h"
+#include "compiled/String.h"
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}