summaryrefslogtreecommitdiff
path: root/unittests/Host
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:50:09 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:50:09 +0000
commitf3fbd1c0586ff6ec7895991e6c28f61a503c36a8 (patch)
tree48d008fd3df8c0e73271a4b18474e0aac6dbfe33 /unittests/Host
parent2fc5d2d1dfaf623ce4e24cd8590565902f8c557c (diff)
Notes
Diffstat (limited to 'unittests/Host')
-rw-r--r--unittests/Host/CMakeLists.txt1
-rw-r--r--unittests/Host/FileSpecTest.cpp111
-rw-r--r--unittests/Host/SocketAddressTest.cpp7
-rw-r--r--unittests/Host/SocketTest.cpp12
4 files changed, 125 insertions, 6 deletions
diff --git a/unittests/Host/CMakeLists.txt b/unittests/Host/CMakeLists.txt
index b4739e113f48..be0450874203 100644
--- a/unittests/Host/CMakeLists.txt
+++ b/unittests/Host/CMakeLists.txt
@@ -1,4 +1,5 @@
add_lldb_unittest(HostTests
+ FileSpecTest.cpp
SocketAddressTest.cpp
SocketTest.cpp
SymbolsTest.cpp
diff --git a/unittests/Host/FileSpecTest.cpp b/unittests/Host/FileSpecTest.cpp
new file mode 100644
index 000000000000..4e619529773f
--- /dev/null
+++ b/unittests/Host/FileSpecTest.cpp
@@ -0,0 +1,111 @@
+//===-- FileSpecTest.cpp ----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Host/FileSpec.h"
+
+using namespace lldb_private;
+
+TEST(FileSpecTest, FileAndDirectoryComponents)
+{
+ FileSpec fs_posix("/foo/bar", false, FileSpec::ePathSyntaxPosix);
+ EXPECT_STREQ("/foo/bar", fs_posix.GetCString());
+ EXPECT_STREQ("/foo", fs_posix.GetDirectory().GetCString());
+ EXPECT_STREQ("bar", fs_posix.GetFilename().GetCString());
+
+ FileSpec fs_windows("F:\\bar", false, FileSpec::ePathSyntaxWindows);
+ EXPECT_STREQ("F:\\bar", fs_windows.GetCString());
+ // EXPECT_STREQ("F:\\", fs_windows.GetDirectory().GetCString()); // It returns "F:/"
+ EXPECT_STREQ("bar", fs_windows.GetFilename().GetCString());
+
+ FileSpec fs_posix_root("/", false, FileSpec::ePathSyntaxPosix);
+ EXPECT_STREQ("/", fs_posix_root.GetCString());
+ EXPECT_EQ(nullptr, fs_posix_root.GetDirectory().GetCString());
+ EXPECT_STREQ("/", fs_posix_root.GetFilename().GetCString());
+
+ FileSpec fs_windows_drive("F:", false, FileSpec::ePathSyntaxWindows);
+ EXPECT_STREQ("F:", fs_windows_drive.GetCString());
+ EXPECT_EQ(nullptr, fs_windows_drive.GetDirectory().GetCString());
+ EXPECT_STREQ("F:", fs_windows_drive.GetFilename().GetCString());
+
+ FileSpec fs_windows_root("F:\\", false, FileSpec::ePathSyntaxWindows);
+ EXPECT_STREQ("F:\\", fs_windows_root.GetCString());
+ EXPECT_STREQ("F:", fs_windows_root.GetDirectory().GetCString());
+ // EXPECT_STREQ("\\", fs_windows_root.GetFilename().GetCString()); // It returns "/"
+
+ FileSpec fs_posix_long("/foo/bar/baz", false, FileSpec::ePathSyntaxPosix);
+ EXPECT_STREQ("/foo/bar/baz", fs_posix_long.GetCString());
+ EXPECT_STREQ("/foo/bar", fs_posix_long.GetDirectory().GetCString());
+ EXPECT_STREQ("baz", fs_posix_long.GetFilename().GetCString());
+
+ FileSpec fs_windows_long("F:\\bar\\baz", false, FileSpec::ePathSyntaxWindows);
+ EXPECT_STREQ("F:\\bar\\baz", fs_windows_long.GetCString());
+ // EXPECT_STREQ("F:\\bar", fs_windows_long.GetDirectory().GetCString()); // It returns "F:/bar"
+ EXPECT_STREQ("baz", fs_windows_long.GetFilename().GetCString());
+
+ FileSpec fs_posix_trailing_slash("/foo/bar/", false, FileSpec::ePathSyntaxPosix);
+ EXPECT_STREQ("/foo/bar/.", fs_posix_trailing_slash.GetCString());
+ EXPECT_STREQ("/foo/bar", fs_posix_trailing_slash.GetDirectory().GetCString());
+ EXPECT_STREQ(".", fs_posix_trailing_slash.GetFilename().GetCString());
+
+ FileSpec fs_windows_trailing_slash("F:\\bar\\", false, FileSpec::ePathSyntaxWindows);
+ EXPECT_STREQ("F:\\bar\\.", fs_windows_trailing_slash.GetCString());
+ // EXPECT_STREQ("F:\\bar", fs_windows_trailing_slash.GetDirectory().GetCString()); // It returns "F:/bar"
+ EXPECT_STREQ(".", fs_windows_trailing_slash.GetFilename().GetCString());
+}
+
+TEST(FileSpecTest, AppendPathComponent)
+{
+ FileSpec fs_posix("/foo", false, FileSpec::ePathSyntaxPosix);
+ fs_posix.AppendPathComponent("bar");
+ EXPECT_STREQ("/foo/bar", fs_posix.GetCString());
+ EXPECT_STREQ("/foo", fs_posix.GetDirectory().GetCString());
+ EXPECT_STREQ("bar", fs_posix.GetFilename().GetCString());
+
+ FileSpec fs_windows("F:\\bar", false, FileSpec::ePathSyntaxWindows);
+ fs_windows.AppendPathComponent("baz");
+ EXPECT_STREQ("F:\\bar\\baz", fs_windows.GetCString());
+ // EXPECT_STREQ("F:\\bar", fs_windows.GetDirectory().GetCString()); // It returns "F:/bar"
+ EXPECT_STREQ("baz", fs_windows.GetFilename().GetCString());
+
+ FileSpec fs_posix_root("/", false, FileSpec::ePathSyntaxPosix);
+ fs_posix_root.AppendPathComponent("bar");
+ EXPECT_STREQ("/bar", fs_posix_root.GetCString());
+ EXPECT_STREQ("/", fs_posix_root.GetDirectory().GetCString());
+ EXPECT_STREQ("bar", fs_posix_root.GetFilename().GetCString());
+
+ FileSpec fs_windows_root("F:\\", false, FileSpec::ePathSyntaxWindows);
+ fs_windows_root.AppendPathComponent("bar");
+ EXPECT_STREQ("F:\\bar", fs_windows_root.GetCString());
+ // EXPECT_STREQ("F:\\", fs_windows_root.GetDirectory().GetCString()); // It returns "F:/"
+ EXPECT_STREQ("bar", fs_windows_root.GetFilename().GetCString());
+}
+
+TEST(FileSpecTest, CopyByAppendingPathComponent)
+{
+ FileSpec fs = FileSpec("/foo", false, FileSpec::ePathSyntaxPosix).CopyByAppendingPathComponent("bar");
+ EXPECT_STREQ("/foo/bar", fs.GetCString());
+ EXPECT_STREQ("/foo", fs.GetDirectory().GetCString());
+ EXPECT_STREQ("bar", fs.GetFilename().GetCString());
+}
+
+TEST(FileSpecTest, Equal)
+{
+ FileSpec backward("C:\\foo\\bar", false, FileSpec::ePathSyntaxWindows);
+ FileSpec forward("C:/foo/bar", false, FileSpec::ePathSyntaxWindows);
+ EXPECT_EQ(forward, backward);
+
+ const bool full_match = true;
+ const bool remove_backup_dots = true;
+ EXPECT_TRUE(FileSpec::Equal(forward, backward, full_match, remove_backup_dots));
+ EXPECT_TRUE(FileSpec::Equal(forward, backward, full_match, !remove_backup_dots));
+ EXPECT_TRUE(FileSpec::Equal(forward, backward, !full_match, remove_backup_dots));
+ EXPECT_TRUE(FileSpec::Equal(forward, backward, !full_match, !remove_backup_dots));
+}
diff --git a/unittests/Host/SocketAddressTest.cpp b/unittests/Host/SocketAddressTest.cpp
index bd6bda13f449..6b27e04ce702 100644
--- a/unittests/Host/SocketAddressTest.cpp
+++ b/unittests/Host/SocketAddressTest.cpp
@@ -33,11 +33,8 @@ TEST_F (SocketAddressTest, Set)
ASSERT_EQ (0, sa.GetPort ());
ASSERT_TRUE (sa.SetToLocalhost (AF_INET6, 1139));
-#ifdef _WIN32
- ASSERT_STREQ ("0:0:0:0:0:0:0:1", sa.GetIPAddress ().c_str ());
-#else
- ASSERT_STREQ ("::1", sa.GetIPAddress ().c_str ());
-#endif
+ ASSERT_TRUE(sa.GetIPAddress() == "::1" || sa.GetIPAddress() == "0:0:0:0:0:0:0:1") << "Address was: "
+ << sa.GetIPAddress();
ASSERT_EQ (1139, sa.GetPort ());
}
diff --git a/unittests/Host/SocketTest.cpp b/unittests/Host/SocketTest.cpp
index ebb2f319a9c5..e3e522744760 100644
--- a/unittests/Host/SocketTest.cpp
+++ b/unittests/Host/SocketTest.cpp
@@ -116,7 +116,11 @@ TEST_F (SocketTest, DecodeHostAndPort)
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_STREQ ("", host_str.c_str ());
EXPECT_STREQ ("12345", port_str.c_str ());
@@ -128,6 +132,12 @@ TEST_F (SocketTest, DecodeHostAndPort)
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_STREQ("*", host_str.c_str());
+ EXPECT_STREQ("65535", port_str.c_str());
+ EXPECT_EQ(65535, port);
+ EXPECT_TRUE(error.Success());
}
#ifndef LLDB_DISABLE_POSIX