summaryrefslogtreecommitdiff
path: root/src/test/test_application.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test_application.cpp')
-rw-r--r--src/test/test_application.cpp80
1 files changed, 80 insertions, 0 deletions
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(), {});
+}