GCC Code Coverage Report


Directory: src/gate/
File: src/gate/cxx_uris.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 102 104 98.1%
Functions: 26 27 96.3%
Branches: 27 68 39.7%

Line Branch Exec Source
1 #include "gate/uris.hpp"
2 #include "gate/exceptions.hpp"
3
4 namespace gate
5 {
6 char const* const Uri::SchemeFile = GATE_URI_SCHEME_FILE;
7 char const* const Uri::SchemeFtp = GATE_URI_SCHEME_FTP;
8 char const* const Uri::SchemeGopher = GATE_URI_SCHEME_GOPHER;
9 char const* const Uri::SchemeHttp = GATE_URI_SCHEME_HTTP;
10 char const* const Uri::SchemeHttps = GATE_URI_SCHEME_HTTPS;
11 char const* const Uri::SchemeMailto = GATE_URI_SCHEME_MAILTO;
12 char const* const Uri::SchemeNetPipe = GATE_URI_SCHEME_NETPIPE;
13 char const* const Uri::SchemeNetTcp = GATE_URI_SCHEME_NETTCP;
14 char const* const Uri::SchemeNetUdp = GATE_URI_SCHEME_NETUDP;
15 char const* const Uri::SchemeNews = GATE_URI_SCHEME_NEWS;
16 char const* const Uri::SchemeNntp = GATE_URI_SCHEME_NNTP;
17
18
19 1 Uri Uri::parse(String const& text)
20 {
21 1 Uri uri;
22
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 result_t result = gate_uri_parse(uri.c_impl(), text.c_impl());
23
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
24 1 return uri;
25 }
26 1 void Uri::parsePath(String const& path, String& absPath, String& queryPart)
27 {
28 1 gate_string_t abs_path = GATE_STRING_INIT_EMPTY;
29 1 gate_string_t query_part = GATE_STRING_INIT_EMPTY;
30
31
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 result_t result = gate_uri_parse_path(path.c_impl(), &abs_path, &query_part);
32
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
33 1 absPath = String::createFrom(abs_path);
34 1 queryPart = String::createFrom(query_part);
35 1 }
36
37 1 String Uri::escape(String const& text)
38 {
39 gate_string_t tmp;
40
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 result_t result = gate_uri_escape(text.c_impl(), &tmp);
41
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_ERROR(result);
42 2 return String::createFrom(tmp);
43 }
44 1 String Uri::unescape(String const& text)
45 {
46 gate_string_t tmp;
47
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 result_t result = gate_uri_unescape(text.c_impl(), &tmp);
48
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
49 2 return String::createFrom(tmp);
50 }
51
52 1 void Uri::parseUserInfo(String const& src, String& username, String& password)
53 {
54 1 gate_string_t strUser = GATE_STRING_INIT_EMPTY;
55 1 gate_string_t strPass = GATE_STRING_INIT_EMPTY;
56
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 result_t result = gate_uri_parse_user_info(src.c_impl(), &strUser, &strPass);
57
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_ERROR(result);
58 2 String user = String::createFrom(strUser);
59 2 String pass = String::createFrom(strPass);
60 1 username.swap(user);
61 1 password.swap(pass);
62 1 }
63 1 String Uri::buildUserInfo(String const& username, String const& password)
64 {
65 1 gate_string_t strInfo = GATE_STRING_INIT_EMPTY;
66
1/2
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
1 result_t result = gate_uri_build_user_info(username.c_impl(), password.c_impl(), &strInfo);
67
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_ERROR(result);
68 1 String info = String::createFrom(strInfo);
69 2 return info;
70 }
71
72
73 4 Uri::Uri()
74 {
75 4 result_t result = gate_uri_init(&this->impl);
76
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 GATEXX_CHECK_ERROR(result);
77 4 }
78 1 Uri::Uri(Uri const& src)
79 {
80 1 result_t result = gate_uri_copy(&this->impl, &src.impl);
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
82 1 }
83 1 Uri::Uri(gate_uri_t const& src)
84 {
85 1 result_t result = gate_uri_copy(&this->impl, &src);
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
87 1 }
88
89 1 Uri& Uri::operator=(Uri const& src)
90 {
91
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 Uri that(src);
92
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 this->swap(that);
93 2 return *this;
94 }
95 12 Uri::~Uri() noexcept
96 {
97 6 gate_uri_destroy(&this->impl);
98 6 }
99
100 2 void Uri::swap(Uri& target)
101 {
102 gate_uri_t tmp;
103
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 gate_mem_copy(&tmp, &this->impl, sizeof(gate_uri_t));
104
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 gate_mem_copy(&this->impl, &target.impl, sizeof(gate_uri_t));
105
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 gate_mem_copy(&target.impl, &tmp, sizeof(gate_uri_t));
106 2 }
107 2 gate_uri_t* Uri::c_impl()
108 {
109 2 return &this->impl;
110 }
111 gate_uri_t const* Uri::c_impl() const
112 {
113 return &this->impl;
114 }
115
116
117 1 String Uri::getScheme() const
118 {
119 1 return String::copy(this->impl.scheme);
120 }
121 3 String Uri::getUserInfo() const
122 {
123 3 return String::copy(this->impl.user_info);
124 }
125 1 String Uri::getHost() const
126 {
127 1 return String::copy(this->impl.host);
128 }
129 1 int32_t Uri::getPort() const
130 {
131 1 return this->impl.port;
132 }
133 1 String Uri::getAbsolutePath() const
134 {
135 1 return String::copy(this->impl.absolute_path);
136 }
137 1 String Uri::getQuery() const
138 {
139 1 return String::copy(this->impl.query);
140 }
141
142 1 void Uri::setScheme(String const& value)
143 {
144
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 String str = value.clone();
145 1 str.swap(this->impl.scheme);
146 1 }
147 1 void Uri::setUserInfo(String const& value)
148 {
149
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 String str = value.clone();
150 1 str.swap(this->impl.user_info);
151 1 }
152 1 void Uri::setHost(String const& value)
153 {
154
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 String str = value.clone();
155 1 str.swap(this->impl.host);
156 1 }
157 1 void Uri::setPort(int32_t const& value)
158 {
159 1 this->impl.port = value;
160 1 }
161 1 void Uri::setAbsolutePath(String const& value)
162 {
163
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 String str = value.clone();
164 1 str.swap(this->impl.absolute_path);
165 1 }
166 1 void Uri::setQuery(String const& value)
167 {
168
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 String str = value.clone();
169 1 str.swap(this->impl.query);
170 1 }
171
172 2 String Uri::toString(bool absPathOnly) const
173 {
174 gate_string_t text;
175
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 result_t result = gate_uri_to_string(&this->impl, &text, absPathOnly);
176
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_ERROR(result);
177 4 return String::createFrom(text);
178 }
179
180 } // end of namespace gate
181