Skip to content

Commit a605bd4

Browse files
committed
test: Add port validation check after openURL
1 parent 03c0615 commit a605bd4

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

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

+2
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

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)