summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-08-27 22:09:16 +0300
committeraqua <aqua@iserlohn-fortress.net>2022-08-27 22:44:31 +0300
commit86db843bc53a93dbf566b24df1462a22fccb619a (patch)
treee4a48a8e9053294f62ed5ea1d66d5c8f9d3d901e /src/test
parentRename rView to RekonqView (diff)
downloadrekonq-86db843bc53a93dbf566b24df1462a22fccb619a.tar.xz
Add parseCommandLine tests
- use PluginLoader in plugin tests
Diffstat (limited to 'src/test')
-rw-r--r--src/test/application_mock.hpp17
-rw-r--r--src/test/test_application.cpp80
2 files changed, 97 insertions, 0 deletions
diff --git a/src/test/application_mock.hpp b/src/test/application_mock.hpp
new file mode 100644
index 00000000..edfaf0bc
--- /dev/null
+++ b/src/test/application_mock.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "../application.hpp"
+#include <gmock/gmock.h>
+
+class FakeApplication : public Application {
+ Q_OBJECT
+
+public:
+ explicit FakeApplication(int &argc, char *argv[]) : Application(argc, argv) {}
+ ~FakeApplication() override = default;
+
+ MOCK_METHOD(bool, registerPlugin, (const QString &), (override));
+
+ MOCK_METHOD(RekonqWindow *, newWindow, (), (override));
+ MOCK_METHOD(RekonqView *, newView, (const QUrl &, RekonqWindow *), (override));
+};
diff --git a/src/test/test_application.cpp b/src/test/test_application.cpp
new file mode 100644
index 00000000..63963cd1
--- /dev/null
+++ b/src/test/test_application.cpp
@@ -0,0 +1,80 @@
+#include "test/application_mock.hpp"
+#include <gtest/gtest.h>
+
+// NOLINTNEXTLINE(modernize-avoid-c-arrays)
+Application::Application(int &argc, char *argv[]) : SingleApplication(argc, argv) {}
+Application::~Application() = default;
+
+using ::testing::_; // NOLINT(bugprone-reserved-identifier)
+
+MATCHER_P(QStringEq, a, "")
+{
+ *result_listener << "where the arg is " << qUtf8Printable(arg);
+ return arg.compare(a) == 0;
+}
+
+MATCHER_P(QUrlEq, a, "")
+{
+ *result_listener << "where the arg is " << qUtf8Printable(arg.toString());
+ return arg.toString().compare(a) == 0;
+}
+
+TEST(Application, parseCommandLine_url)
+{
+ int argc = 2;
+ // NOLINTNEXTLINE(modernize-avoid-c-arrays)
+ char *argv[]{(char *)"FakeApplication", (char *)"about:blank"};
+
+ FakeApplication app(argc, argv);
+ EXPECT_CALL(app, registerPlugin).Times(0);
+ EXPECT_CALL(app, newView(QUrlEq("about:blank"), nullptr)).Times(1);
+ EXPECT_CALL(app, newWindow).Times(1);
+
+ ASSERT_TRUE(Application::instance() != nullptr);
+
+ EXPECT_TRUE(app.pluginList().isEmpty());
+ EXPECT_TRUE(app.windowList().isEmpty());
+ EXPECT_TRUE(app.viewList().isEmpty());
+
+ app.parseCommandLine(app.instanceId(), {});
+}
+
+TEST(Application, parseCommandLine_webapp)
+{
+ int argc = 3;
+ // NOLINTNEXTLINE(modernize-avoid-c-arrays)
+ char *argv[]{(char *)"FakeApplication", (char *)"--webapp", (char *)"about:blank"};
+
+ FakeApplication app(argc, argv);
+ EXPECT_CALL(app, registerPlugin).Times(0);
+ EXPECT_CALL(app, newView(QUrlEq("about:blank"), nullptr)).Times(1);
+ EXPECT_CALL(app, newWindow).Times(0);
+
+ ASSERT_TRUE(Application::instance() != nullptr);
+
+ EXPECT_TRUE(app.pluginList().isEmpty());
+ EXPECT_TRUE(app.windowList().isEmpty());
+ EXPECT_TRUE(app.viewList().isEmpty());
+
+ app.parseCommandLine(app.instanceId(), {});
+}
+
+TEST(Application, parseCommandLine_load)
+{
+ int argc = 3;
+ // NOLINTNEXTLINE(modernize-avoid-c-arrays)
+ char *argv[]{(char *)"FakeApplication", (char *)"--load", (char *)"libPlugin.so"};
+
+ FakeApplication app(argc, argv);
+ EXPECT_CALL(app, registerPlugin(QStringEq("libPlugin.so"))).Times(1);
+ EXPECT_CALL(app, newView).Times(1);
+ EXPECT_CALL(app, newWindow).Times(1);
+
+ ASSERT_TRUE(Application::instance() != nullptr);
+
+ EXPECT_TRUE(app.pluginList().isEmpty());
+ EXPECT_TRUE(app.windowList().isEmpty());
+ EXPECT_TRUE(app.viewList().isEmpty());
+
+ app.parseCommandLine(app.instanceId(), {});
+}