summaryrefslogtreecommitdiff
path: root/src/test/test_application.cpp
blob: 63963cd1de9cb6b37395799739ddc630f648626a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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(), {});
}