Skip to content

Commit 41faa58

Browse files
joaomariolagopatrickelectric
authored andcommitted
test: Add port validation check after openURL
1 parent a283b52 commit 41faa58

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

src/hal/link/desktop/abstract-link.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const char* AbstractLink::_urlStringRegex = R"((?P<type>udp|serial):(?P<host>.*)
1717
std::shared_ptr<AbstractLink> AbstractLink::openUrl(const std::string& url)
1818
{
1919
if (url.empty()) {
20+
std::cerr << "Empty URL was provided when trying to open a link" << std::endl;
2021
return {};
2122
}
2223

@@ -30,6 +31,7 @@ std::shared_ptr<AbstractLink> AbstractLink::openUrl(const std::string& url)
3031
} urlStruct;
3132

3233
if (!regex_search(url, match, regex)) {
34+
std::cerr << "Invalid URL provided, should be in format `type:host:config`" << std::endl;
3335
return {};
3436
}
3537

@@ -46,5 +48,6 @@ std::shared_ptr<AbstractLink> AbstractLink::openUrl(const std::string& url)
4648
return std::make_shared<UdpLink>(urlStruct.host, urlStruct.config);
4749
}
4850

51+
std::cerr << "Unknown link type provided" << std::endl;
4952
return {};
5053
}

test/test-device-ping1d.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ int main(int argc, char* argv[])
1818
}
1919

2020
auto port = AbstractLink::openUrl(CommandLine::self()->connectionString);
21+
if (!port) {
22+
std::cerr << "Failed to open communication link with device" << std::endl;
23+
return -1;
24+
}
2125
Ping1d device = Ping1d(*port.get());
2226

2327
// Basic information

test/test-device-ping360.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ int main(int argc, char* argv[])
1818
}
1919

2020
auto port = AbstractLink::openUrl(CommandLine::self()->connectionString);
21+
if (!port) {
22+
std::cerr << "Failed to open communication link with device" << std::endl;
23+
return -1;
24+
}
2125
Ping360 device = Ping360(*port.get());
2226

2327
// Basic information

test/test-device.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ int main(int argc, char* argv[])
1919
}
2020

2121
auto port = AbstractLink::openUrl(CommandLine::self()->connectionString);
22+
if (!port) {
23+
std::cerr << "Failed to open communication link with device" << std::endl;
24+
return -1;
25+
}
2226
PingDevice device = PingDevice(*port.get());
2327

2428
// Basic information

0 commit comments

Comments
 (0)