summaryrefslogtreecommitdiffstats
path: root/lldb/gtest
diff options
context:
space:
mode:
authorVince Harron <vharron@google.com>2015-01-06 23:38:24 +0000
committerVince Harron <vharron@google.com>2015-01-06 23:38:24 +0000
commit3218c0fb943a05ffeeeefaffaa0f7f64b2bb3858 (patch)
treea21b29c98bf6d46a5dabeb20d0dc94497c0bf50a /lldb/gtest
parent009597d0489a61f2dee9a4739865cb0809d2bd2e (diff)
downloadbcm5719-llvm-3218c0fb943a05ffeeeefaffaa0f7f64b2bb3858.tar.gz
bcm5719-llvm-3218c0fb943a05ffeeeefaffaa0f7f64b2bb3858.zip
Adds UriParser::Parse and unit tests
This can be used to parse URIs passed to 'platform connect' Differential Revision: http://reviews.llvm.org/D6858 llvm-svn: 225317
Diffstat (limited to 'lldb/gtest')
-rw-r--r--lldb/gtest/gtest.xcodeproj/project.pbxproj4
-rw-r--r--lldb/gtest/unittest/Utility/Makefile3
-rw-r--r--lldb/gtest/unittest/Utility/UriParserTest.cpp129
3 files changed, 135 insertions, 1 deletions
diff --git a/lldb/gtest/gtest.xcodeproj/project.pbxproj b/lldb/gtest/gtest.xcodeproj/project.pbxproj
index 07cccde09a4..12d7a70e1d3 100644
--- a/lldb/gtest/gtest.xcodeproj/project.pbxproj
+++ b/lldb/gtest/gtest.xcodeproj/project.pbxproj
@@ -10,6 +10,8 @@
236ED33319D49076008CA7D7 /* ThreadStateCoordinatorTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadStateCoordinatorTest.cpp; sourceTree = "<group>"; };
236ED33419D49081008CA7D7 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
236ED33619D490B0008CA7D7 /* Makefile.rules */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Makefile.rules; sourceTree = "<group>"; };
+ 33064C981A5C7A1A0033D415 /* UriParserTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UriParserTest.cpp; path = Utility/UriParserTest.cpp; sourceTree = "<group>"; };
+ 33064C9D1A5C7AC90033D415 /* do-gtest.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = "do-gtest.py"; sourceTree = "<group>"; };
338C47F41A1E67B900B46077 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; name = Makefile; path = Utility/Makefile; sourceTree = "<group>"; };
338C47F51A1E67B900B46077 /* StringExtractorTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringExtractorTest.cpp; path = Utility/StringExtractorTest.cpp; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -60,6 +62,7 @@
23CDD8EE19D4790700461DDC = {
isa = PBXGroup;
children = (
+ 33064C9D1A5C7AC90033D415 /* do-gtest.py */,
236ED33519D49098008CA7D7 /* make */,
236ED32F19D4901D008CA7D7 /* unittest */,
);
@@ -68,6 +71,7 @@
338C47F31A1E677900B46077 /* Utility */ = {
isa = PBXGroup;
children = (
+ 33064C981A5C7A1A0033D415 /* UriParserTest.cpp */,
338C47F41A1E67B900B46077 /* Makefile */,
338C47F51A1E67B900B46077 /* StringExtractorTest.cpp */,
);
diff --git a/lldb/gtest/unittest/Utility/Makefile b/lldb/gtest/unittest/Utility/Makefile
index cd006b3be8e..c35aa6c0975 100644
--- a/lldb/gtest/unittest/Utility/Makefile
+++ b/lldb/gtest/unittest/Utility/Makefile
@@ -5,7 +5,8 @@ LEVEL := $(realpath $(THIS_FILE_DIR)../../make)
CFLAGS_EXTRAS := -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS
ENABLE_THREADS := YES
CXX_SOURCES := $(wildcard *.cpp) \
- $(realpath $(LEVEL)/../../source/Utility/StringExtractor.cpp)
+ $(realpath $(LEVEL)/../../source/Utility/StringExtractor.cpp) \
+ $(realpath $(LEVEL)/../../source/Utility/UriParser.cpp)
MAKE_DSYM := NO
OS := $(shell uname -s)
diff --git a/lldb/gtest/unittest/Utility/UriParserTest.cpp b/lldb/gtest/unittest/Utility/UriParserTest.cpp
new file mode 100644
index 00000000000..b9db7ac09e4
--- /dev/null
+++ b/lldb/gtest/unittest/Utility/UriParserTest.cpp
@@ -0,0 +1,129 @@
+#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", 0, "/");
+ 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", 0, "/");
+ 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
+}
+
OpenPOWER on IntegriCloud