GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../test/cctest/test_url.cc Lines: 77 77 100.0 %
Date: 2019-01-07 12:15:22 Branches: 55 110 50.0 %

Line Branch Exec Source
1
#include "node_url.h"
2
#include "node_i18n.h"
3
4
#include "gtest/gtest.h"
5
6
using node::url::URL;
7
using node::url::URL_FLAGS_FAILED;
8
9
16
class URLTest : public ::testing::Test {
10
 protected:
11
8
  void SetUp() override {
12
#if defined(NODE_HAVE_I18N_SUPPORT)
13
8
    std::string icu_data_dir;
14
8
    node::i18n::InitializeICUDirectory(icu_data_dir);
15
#endif
16
8
  }
17
18
8
  void TearDown() override {}
19
};
20
21
5
TEST_F(URLTest, Simple) {
22
1
  URL simple("https://example.org:81/a/b/c?query#fragment");
23
24
1
  EXPECT_FALSE(simple.flags() & URL_FLAGS_FAILED);
25
1
  EXPECT_EQ(simple.protocol(), "https:");
26
1
  EXPECT_EQ(simple.host(), "example.org");
27
1
  EXPECT_EQ(simple.port(), 81);
28
1
  EXPECT_EQ(simple.path(), "/a/b/c");
29
1
  EXPECT_EQ(simple.query(), "query");
30
1
  EXPECT_EQ(simple.fragment(), "fragment");
31
1
}
32
33
5
TEST_F(URLTest, Simple2) {
34
1
  const char* input = "https://example.org:81/a/b/c?query#fragment";
35
1
  URL simple(input, strlen(input));
36
37
1
  EXPECT_FALSE(simple.flags() & URL_FLAGS_FAILED);
38
1
  EXPECT_EQ(simple.protocol(), "https:");
39
1
  EXPECT_EQ(simple.host(), "example.org");
40
1
  EXPECT_EQ(simple.port(), 81);
41
1
  EXPECT_EQ(simple.path(), "/a/b/c");
42
1
  EXPECT_EQ(simple.query(), "query");
43
1
  EXPECT_EQ(simple.fragment(), "fragment");
44
1
}
45
46
5
TEST_F(URLTest, NoBase1) {
47
1
  URL error("123noscheme");
48
1
  EXPECT_TRUE(error.flags() & URL_FLAGS_FAILED);
49
1
}
50
51
5
TEST_F(URLTest, Base1) {
52
1
  URL base("http://example.org/foo/bar");
53

2
  ASSERT_FALSE(base.flags() & URL_FLAGS_FAILED);
54
55
1
  URL simple("../baz", &base);
56
1
  EXPECT_FALSE(simple.flags() & URL_FLAGS_FAILED);
57
1
  EXPECT_EQ(simple.protocol(), "http:");
58
1
  EXPECT_EQ(simple.host(), "example.org");
59

1
  EXPECT_EQ(simple.path(), "/baz");
60
}
61
62
5
TEST_F(URLTest, Base2) {
63
1
  URL simple("../baz", "http://example.org/foo/bar");
64
65
1
  EXPECT_FALSE(simple.flags() & URL_FLAGS_FAILED);
66
1
  EXPECT_EQ(simple.protocol(), "http:");
67
1
  EXPECT_EQ(simple.host(), "example.org");
68
1
  EXPECT_EQ(simple.path(), "/baz");
69
1
}
70
71
5
TEST_F(URLTest, Base3) {
72
1
  const char* input = "../baz";
73
1
  const char* base = "http://example.org/foo/bar";
74
75
1
  URL simple(input, strlen(input), base, strlen(base));
76
77
1
  EXPECT_FALSE(simple.flags() & URL_FLAGS_FAILED);
78
1
  EXPECT_EQ(simple.protocol(), "http:");
79
1
  EXPECT_EQ(simple.host(), "example.org");
80
1
  EXPECT_EQ(simple.path(), "/baz");
81
1
}
82
83
5
TEST_F(URLTest, ToFilePath) {
84
#define T(url, path) EXPECT_EQ(path, URL(url).ToFilePath())
85
1
  T("http://example.org/foo/bar", "");
86
87
#ifdef _WIN32
88
  T("file:///C:/Program%20Files/", "C:\\Program Files\\");
89
  T("file:///C:/a/b/c?query#fragment", "C:\\a\\b\\c");
90
  T("file://host/path/a/b/c?query#fragment", "\\\\host\\path\\a\\b\\c");
91
#if defined(NODE_HAVE_I18N_SUPPORT)
92
  T("file://xn--weird-prdj8vva.com/host/a", "\\\\wͪ͊eiͬ͋rd.com\\host\\a");
93
#else
94
  T("file://xn--weird-prdj8vva.com/host/a",
95
    "\\\\xn--weird-prdj8vva.com\\host\\a");
96
#endif
97
  T("file:///C:/a%2Fb", "");
98
  T("file:///", "");
99
  T("file:///home", "");
100
#else
101
1
  T("file:///", "/");
102
1
  T("file:///home/user?query#fragment", "/home/user");
103
1
  T("file:///home/user/?query#fragment", "/home/user/");
104
1
  T("file:///home/user/%20space", "/home/user/ space");
105
1
  T("file:///home/us%5Cer", "/home/us\\er");
106
1
  T("file:///home/us%2Fer", "");
107
1
  T("file://host/path", "");
108
#endif
109
110
#undef T
111
1
}
112
113
5
TEST_F(URLTest, FromFilePath) {
114
1
  URL file_url;
115
#ifdef _WIN32
116
  file_url = URL::FromFilePath("C:\\Program Files\\");
117
  EXPECT_EQ("file:", file_url.protocol());
118
  EXPECT_EQ("/C:/Program%20Files/", file_url.path());
119
120
  file_url = URL::FromFilePath("C:\\a\\b\\c");
121
  EXPECT_EQ("file:", file_url.protocol());
122
  EXPECT_EQ("/C:/a/b/c", file_url.path());
123
124
  file_url = URL::FromFilePath("b:\\a\\%%.js");
125
  EXPECT_EQ("file:", file_url.protocol());
126
  EXPECT_EQ("/b:/a/%25%25.js", file_url.path());
127
#else
128
1
  file_url = URL::FromFilePath("/");
129
1
  EXPECT_EQ("file:", file_url.protocol());
130
1
  EXPECT_EQ("/", file_url.path());
131
132
1
  file_url = URL::FromFilePath("/a/b/c");
133
1
  EXPECT_EQ("file:", file_url.protocol());
134
1
  EXPECT_EQ("/a/b/c", file_url.path());
135
136
1
  file_url = URL::FromFilePath("/a/%%.js");
137
1
  EXPECT_EQ("file:", file_url.protocol());
138
1
  EXPECT_EQ("/a/%25%25.js", file_url.path());
139
#endif
140

4
}