diff options
author | Michał Górny <mgorny@moritz.systems> | 2021-09-24 10:28:58 +0200 |
---|---|---|
committer | Michał Górny <mgorny@moritz.systems> | 2021-09-24 14:58:02 +0200 |
commit | 5f1c8d8a432deacfeada5e5a3794d0c938171c37 (patch) | |
tree | 4e823b5b1c48aab8277fff89f2d6eb6fbffcf240 /lldb/unittests/Host/SocketTest.cpp | |
parent | 8e4f7b749c2c03809f022c95698686c8584097fc (diff) | |
download | llvm-5f1c8d8a432deacfeada5e5a3794d0c938171c37.zip llvm-5f1c8d8a432deacfeada5e5a3794d0c938171c37.tar.gz llvm-5f1c8d8a432deacfeada5e5a3794d0c938171c37.tar.bz2 |
[lldb] [Host] Refactor Socket::DecodeHostAndPort() to use LLVM API
Refactor Socket::DecodeHostAndPort() to use LLVM API over redundant
LLDB API. In particular, this means llvm::Regex, llvm::Error return
type and llvm::to_integer().
While at it, change the port type from int32_t to uint16_t. The method
never returns any value outside this range, and using the correct type
allows us to rely on getAsInteger()'s implicit overflow check.
Differential Revision: https://reviews.llvm.org/D110391
Diffstat (limited to 'lldb/unittests/Host/SocketTest.cpp')
-rw-r--r-- | lldb/unittests/Host/SocketTest.cpp | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/lldb/unittests/Host/SocketTest.cpp b/lldb/unittests/Host/SocketTest.cpp index 5593b77..6b9fb42 100644 --- a/lldb/unittests/Host/SocketTest.cpp +++ b/lldb/unittests/Host/SocketTest.cpp @@ -10,6 +10,7 @@ #include "TestingSupport/SubsystemRAII.h" #include "lldb/Host/Config.h" #include "lldb/Utility/UriParser.h" +#include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" using namespace lldb_private; @@ -34,67 +35,63 @@ protected: TEST_P(SocketTest, DecodeHostAndPort) { std::string host_str; std::string port_str; - int32_t port; - Status error; - EXPECT_TRUE(Socket::DecodeHostAndPort("localhost:1138", host_str, port_str, - port, &error)); + uint16_t port; + + EXPECT_THAT_ERROR( + Socket::DecodeHostAndPort("localhost:1138", host_str, port_str, port), + llvm::Succeeded()); EXPECT_STREQ("localhost", host_str.c_str()); EXPECT_STREQ("1138", port_str.c_str()); EXPECT_EQ(1138, port); - EXPECT_TRUE(error.Success()); - - EXPECT_FALSE(Socket::DecodeHostAndPort("google.com:65536", host_str, port_str, - port, &error)); - EXPECT_TRUE(error.Fail()); - EXPECT_STREQ("invalid host:port specification: 'google.com:65536'", - error.AsCString()); - - EXPECT_FALSE(Socket::DecodeHostAndPort("google.com:-1138", host_str, port_str, - port, &error)); - EXPECT_TRUE(error.Fail()); - EXPECT_STREQ("invalid host:port specification: 'google.com:-1138'", - error.AsCString()); - - EXPECT_FALSE(Socket::DecodeHostAndPort("google.com:65536", host_str, port_str, - port, &error)); - EXPECT_TRUE(error.Fail()); - EXPECT_STREQ("invalid host:port specification: 'google.com:65536'", - error.AsCString()); - - EXPECT_TRUE( - Socket::DecodeHostAndPort("12345", host_str, port_str, port, &error)); + + EXPECT_THAT_ERROR( + Socket::DecodeHostAndPort("google.com:65536", host_str, port_str, port), + llvm::FailedWithMessage( + "invalid host:port specification: 'google.com:65536'")); + + EXPECT_THAT_ERROR( + Socket::DecodeHostAndPort("google.com:-1138", host_str, port_str, port), + llvm::FailedWithMessage( + "invalid host:port specification: 'google.com:-1138'")); + + EXPECT_THAT_ERROR( + Socket::DecodeHostAndPort("google.com:65536", host_str, port_str, port), + llvm::FailedWithMessage( + "invalid host:port specification: 'google.com:65536'")); + + EXPECT_THAT_ERROR( + Socket::DecodeHostAndPort("12345", host_str, port_str, port), + llvm::Succeeded()); EXPECT_STREQ("", host_str.c_str()); EXPECT_STREQ("12345", port_str.c_str()); EXPECT_EQ(12345, port); - EXPECT_TRUE(error.Success()); - EXPECT_TRUE( - Socket::DecodeHostAndPort("*:0", host_str, port_str, port, &error)); + EXPECT_THAT_ERROR(Socket::DecodeHostAndPort("*:0", host_str, port_str, port), + llvm::Succeeded()); EXPECT_STREQ("*", host_str.c_str()); EXPECT_STREQ("0", port_str.c_str()); EXPECT_EQ(0, port); - EXPECT_TRUE(error.Success()); - EXPECT_TRUE( - Socket::DecodeHostAndPort("*:65535", host_str, port_str, port, &error)); + EXPECT_THAT_ERROR( + Socket::DecodeHostAndPort("*:65535", host_str, port_str, port), + llvm::Succeeded()); EXPECT_STREQ("*", host_str.c_str()); EXPECT_STREQ("65535", port_str.c_str()); EXPECT_EQ(65535, port); - EXPECT_TRUE(error.Success()); - EXPECT_TRUE( - Socket::DecodeHostAndPort("[::1]:12345", host_str, port_str, port, &error)); + EXPECT_THAT_ERROR( + Socket::DecodeHostAndPort("[::1]:12345", host_str, port_str, port), + llvm::Succeeded()); EXPECT_STREQ("::1", host_str.c_str()); EXPECT_STREQ("12345", port_str.c_str()); EXPECT_EQ(12345, port); - EXPECT_TRUE(error.Success()); - EXPECT_TRUE( - Socket::DecodeHostAndPort("[abcd:12fg:AF58::1]:12345", host_str, port_str, port, &error)); + EXPECT_THAT_ERROR(Socket::DecodeHostAndPort("[abcd:12fg:AF58::1]:12345", + host_str, port_str, port), + llvm::Succeeded()); EXPECT_STREQ("abcd:12fg:AF58::1", host_str.c_str()); EXPECT_STREQ("12345", port_str.c_str()); EXPECT_EQ(12345, port); - EXPECT_TRUE(error.Success()); } #if LLDB_ENABLE_POSIX |