1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
#include "gtest/gtest.h"
#include "Utility/UriParser.h"
namespace
{
class UriParserTest: public ::testing::Test
{
};
}
// result strings (scheme/hostname/port/path) passed into UriParser::Parse
// are initialized to kAsdf so we can verify that they are unmodified if the
// URI is invalid
static const char* kAsdf = "asdf";
class UriTestCase
{
public:
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;
};
#define VALIDATE \
std::string scheme(kAsdf); \
std::string hostname(kAsdf); \
int port(1138); \
std::string path(kAsdf); \
EXPECT_EQ (testCase.m_result, UriParser::Parse(testCase.m_uri, scheme, hostname, port, path)); \
EXPECT_STREQ (testCase.m_scheme, scheme.c_str()); \
EXPECT_STREQ (testCase.m_hostname, hostname.c_str()); \
EXPECT_EQ (testCase.m_port, port); \
EXPECT_STREQ (testCase.m_path, path.c_str());
TEST_F (UriParserTest, Minimal)
{
const UriTestCase testCase("x://y", "x", "y", -1, "/");
VALIDATE
}
TEST_F (UriParserTest, MinimalPort)
{
const UriTestCase testCase("x://y:1", "x", "y", 1, "/");
VALIDATE
}
TEST_F (UriParserTest, MinimalPath)
{
const UriTestCase testCase("x://y/", "x", "y", -1, "/");
VALIDATE
}
TEST_F (UriParserTest, MinimalPortPath)
{
const UriTestCase testCase("x://y:1/", "x", "y", 1, "/");
VALIDATE
}
TEST_F (UriParserTest, TypicalPortPath)
{
const UriTestCase testCase("connect://192.168.100.132:5432/", "connect", "192.168.100.132", 5432, "/");
VALIDATE
}
TEST_F (UriParserTest, SchemeHostSeparator)
{
const UriTestCase testCase("x:/y");
VALIDATE
}
TEST_F (UriParserTest, SchemeHostSeparator2)
{
const UriTestCase testCase("x:y");
VALIDATE
}
TEST_F (UriParserTest, SchemeHostSeparator3)
{
const UriTestCase testCase("x//y");
VALIDATE
}
TEST_F (UriParserTest, SchemeHostSeparator4)
{
const UriTestCase testCase("x/y");
VALIDATE
}
TEST_F (UriParserTest, BadPort)
{
const UriTestCase testCase("x://y:a/");
VALIDATE
}
TEST_F (UriParserTest, BadPort2)
{
const UriTestCase testCase("x://y:5432a/");
VALIDATE
}
TEST_F (UriParserTest, Empty)
{
const UriTestCase testCase("");
VALIDATE
}
TEST_F (UriParserTest, PortOverflow)
{
const UriTestCase testCase("x://y:0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789/");
VALIDATE
}
|