2017-02-10 20:21:22 +08:00
|
|
|
#include "lldb/Utility/UriParser.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "gtest/gtest.h"
|
2015-01-07 07:38:24 +08:00
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
using namespace lldb_private;
|
2015-01-07 07:38:24 +08:00
|
|
|
|
|
|
|
// result strings (scheme/hostname/port/path) passed into UriParser::Parse
|
2016-09-07 04:57:50 +08:00
|
|
|
// are initialized to kAsdf so we can verify that they are unmodified if the
|
2015-01-07 07:38:24 +08:00
|
|
|
// URI is invalid
|
2016-09-07 04:57:50 +08:00
|
|
|
static const char *kAsdf = "asdf";
|
2015-01-07 07:38:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
class UriTestCase {
|
2015-01-07 07:38:24 +08:00
|
|
|
public:
|
2016-09-07 04:57:50 +08:00
|
|
|
UriTestCase(const char *uri, const char *scheme, const char *hostname,
|
|
|
|
int port, const char *path)
|
|
|
|
: m_uri(uri), m_result(true), m_scheme(scheme), m_hostname(hostname),
|
|
|
|
m_port(port), m_path(path) {}
|
|
|
|
|
|
|
|
UriTestCase(const char *uri)
|
|
|
|
: m_uri(uri), m_result(false), m_scheme(kAsdf), m_hostname(kAsdf),
|
|
|
|
m_port(1138), m_path(kAsdf) {}
|
|
|
|
|
|
|
|
const char *m_uri;
|
|
|
|
bool m_result;
|
|
|
|
const char *m_scheme;
|
|
|
|
const char *m_hostname;
|
|
|
|
int m_port;
|
|
|
|
const char *m_path;
|
2015-01-07 07:38:24 +08:00
|
|
|
};
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
#define VALIDATE \
|
2016-11-17 09:38:02 +08:00
|
|
|
llvm::StringRef scheme(kAsdf); \
|
|
|
|
llvm::StringRef hostname(kAsdf); \
|
2016-09-07 04:57:50 +08:00
|
|
|
int port(1138); \
|
2016-11-17 09:38:02 +08:00
|
|
|
llvm::StringRef path(kAsdf); \
|
2016-09-07 04:57:50 +08:00
|
|
|
EXPECT_EQ(testCase.m_result, \
|
|
|
|
UriParser::Parse(testCase.m_uri, scheme, hostname, port, path)); \
|
2016-11-17 09:38:02 +08:00
|
|
|
EXPECT_STREQ(testCase.m_scheme, scheme.str().c_str()); \
|
|
|
|
EXPECT_STREQ(testCase.m_hostname, hostname.str().c_str()); \
|
2016-09-07 04:57:50 +08:00
|
|
|
EXPECT_EQ(testCase.m_port, port); \
|
2016-11-17 09:38:02 +08:00
|
|
|
EXPECT_STREQ(testCase.m_path, path.str().c_str());
|
2015-01-07 07:38:24 +08:00
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, Minimal) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x://y", "x", "y", -1, "/");
|
|
|
|
VALIDATE
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, MinimalPort) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x://y:1", "x", "y", 1, "/");
|
2016-11-17 09:38:02 +08:00
|
|
|
llvm::StringRef scheme(kAsdf);
|
|
|
|
llvm::StringRef hostname(kAsdf);
|
|
|
|
int port(1138);
|
|
|
|
llvm::StringRef path(kAsdf);
|
|
|
|
bool result = UriParser::Parse(testCase.m_uri, scheme, hostname, port, path);
|
|
|
|
EXPECT_EQ(testCase.m_result, result);
|
|
|
|
|
|
|
|
EXPECT_STREQ(testCase.m_scheme, scheme.str().c_str());
|
|
|
|
EXPECT_STREQ(testCase.m_hostname, hostname.str().c_str());
|
|
|
|
EXPECT_EQ(testCase.m_port, port);
|
|
|
|
EXPECT_STREQ(testCase.m_path, path.str().c_str());
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, MinimalPath) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x://y/", "x", "y", -1, "/");
|
|
|
|
VALIDATE
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, MinimalPortPath) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x://y:1/", "x", "y", 1, "/");
|
|
|
|
VALIDATE
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, LongPath) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x://y/abc/def/xyz", "x", "y", -1, "/abc/def/xyz");
|
|
|
|
VALIDATE
|
2015-08-21 07:09:34 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, TypicalPortPath) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("connect://192.168.100.132:5432/", "connect",
|
|
|
|
"192.168.100.132", 5432, "/");
|
2016-11-17 09:38:02 +08:00
|
|
|
VALIDATE;
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, BracketedHostnamePort) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("connect://[192.168.100.132]:5432/", "connect",
|
|
|
|
"192.168.100.132", 5432, "/");
|
2016-11-17 09:38:02 +08:00
|
|
|
llvm::StringRef scheme(kAsdf);
|
|
|
|
llvm::StringRef hostname(kAsdf);
|
|
|
|
int port(1138);
|
|
|
|
llvm::StringRef path(kAsdf);
|
|
|
|
bool result = UriParser::Parse(testCase.m_uri, scheme, hostname, port, path);
|
|
|
|
EXPECT_EQ(testCase.m_result, result);
|
|
|
|
|
|
|
|
EXPECT_STREQ(testCase.m_scheme, scheme.str().c_str());
|
|
|
|
EXPECT_STREQ(testCase.m_hostname, hostname.str().c_str());
|
|
|
|
EXPECT_EQ(testCase.m_port, port);
|
|
|
|
EXPECT_STREQ(testCase.m_path, path.str().c_str());
|
2015-08-21 07:09:34 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, BracketedHostname) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("connect://[192.168.100.132]", "connect",
|
|
|
|
"192.168.100.132", -1, "/");
|
|
|
|
VALIDATE
|
2015-08-21 07:09:34 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, BracketedHostnameWithColon) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("connect://[192.168.100.132:5555]:1234", "connect",
|
|
|
|
"192.168.100.132:5555", 1234, "/");
|
|
|
|
VALIDATE
|
2015-08-21 07:09:34 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, SchemeHostSeparator) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x:/y");
|
|
|
|
VALIDATE
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, SchemeHostSeparator2) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x:y");
|
|
|
|
VALIDATE
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, SchemeHostSeparator3) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x//y");
|
|
|
|
VALIDATE
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, SchemeHostSeparator4) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x/y");
|
|
|
|
VALIDATE
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, BadPort) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x://y:a/");
|
|
|
|
VALIDATE
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, BadPort2) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x://y:5432a/");
|
|
|
|
VALIDATE
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, Empty) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("");
|
|
|
|
VALIDATE
|
2015-01-07 07:38:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-10 20:21:22 +08:00
|
|
|
TEST(UriParserTest, PortOverflow) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const UriTestCase testCase("x://"
|
|
|
|
"y:"
|
|
|
|
"0123456789012345678901234567890123456789012345678"
|
|
|
|
"9012345678901234567890123456789012345678901234567"
|
|
|
|
"89/");
|
|
|
|
VALIDATE
|
2015-01-16 04:57:01 +08:00
|
|
|
}
|