diff options
author | David Pursell <dpursell@google.com> | 2016-01-21 08:40:59 -0800 |
---|---|---|
committer | David Pursell <dpursell@google.com> | 2016-01-21 20:03:33 -0800 |
commit | 706955ff0d159d28bb6eb06dc10178624c505f4e (patch) | |
tree | 7b45b69a8d2dcd149aad72d068980a4c5a3b2e62 /adb/adb_utils_test.cpp | |
parent | bbedd9523faf2c56b9c8236b22658bb659eb1533 (diff) |
base: add network address parsing function from adb.
This CL moves the network address parsing function from adb to libbase
so that it can be used by fastboot as well as adb.
libbase seemed like the right choice because:
1. It already has some parsing functions (parseint)
2. The net address parsing function uses the libbase string
functions so we have a libbase dependency anyway.
The parsing function has been modified slightly to make the canonical
address optional, and debug logging on success has been removed.
For adb the only functional difference is that parsing a network
address will no longer print the result to the debug log, which seemed
unnecessary.
Bug: http://b/26236380
Change-Id: Ife6df02937225fc66de87884d3572d79c092c522
Diffstat (limited to 'adb/adb_utils_test.cpp')
-rw-r--r-- | adb/adb_utils_test.cpp | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/adb/adb_utils_test.cpp b/adb/adb_utils_test.cpp index 4508bca2b1..794dce63ad 100644 --- a/adb/adb_utils_test.cpp +++ b/adb/adb_utils_test.cpp @@ -111,88 +111,6 @@ TEST(adb_utils, adb_dirname) { EXPECT_EQ("/system/bin", adb_dirname("/system/bin/sh/")); } -TEST(adb_utils, parse_host_and_port) { - std::string canonical_address; - std::string host; - int port; - std::string error; - - // Name, default port. - port = 123; - ASSERT_TRUE(parse_host_and_port("www.google.com", &canonical_address, &host, &port, &error)); - ASSERT_EQ("www.google.com:123", canonical_address); - ASSERT_EQ("www.google.com", host); - ASSERT_EQ(123, port); - - // Name, explicit port. - ASSERT_TRUE(parse_host_and_port("www.google.com:666", &canonical_address, &host, &port, &error)); - ASSERT_EQ("www.google.com:666", canonical_address); - ASSERT_EQ("www.google.com", host); - ASSERT_EQ(666, port); - - // IPv4, default port. - port = 123; - ASSERT_TRUE(parse_host_and_port("1.2.3.4", &canonical_address, &host, &port, &error)); - ASSERT_EQ("1.2.3.4:123", canonical_address); - ASSERT_EQ("1.2.3.4", host); - ASSERT_EQ(123, port); - - // IPv4, explicit port. - ASSERT_TRUE(parse_host_and_port("1.2.3.4:666", &canonical_address, &host, &port, &error)); - ASSERT_EQ("1.2.3.4:666", canonical_address); - ASSERT_EQ("1.2.3.4", host); - ASSERT_EQ(666, port); - - // Simple IPv6, default port. - port = 123; - ASSERT_TRUE(parse_host_and_port("::1", &canonical_address, &host, &port, &error)); - ASSERT_EQ("[::1]:123", canonical_address); - ASSERT_EQ("::1", host); - ASSERT_EQ(123, port); - - // Simple IPv6, explicit port. - ASSERT_TRUE(parse_host_and_port("[::1]:666", &canonical_address, &host, &port, &error)); - ASSERT_EQ("[::1]:666", canonical_address); - ASSERT_EQ("::1", host); - ASSERT_EQ(666, port); - - // Hairy IPv6, default port. - port = 123; - ASSERT_TRUE(parse_host_and_port("fe80::200:5aee:feaa:20a2", &canonical_address, &host, &port, &error)); - ASSERT_EQ("[fe80::200:5aee:feaa:20a2]:123", canonical_address); - ASSERT_EQ("fe80::200:5aee:feaa:20a2", host); - ASSERT_EQ(123, port); - - // Simple IPv6, explicit port. - ASSERT_TRUE(parse_host_and_port("[fe80::200:5aee:feaa:20a2]:666", &canonical_address, &host, &port, &error)); - ASSERT_EQ("[fe80::200:5aee:feaa:20a2]:666", canonical_address); - ASSERT_EQ("fe80::200:5aee:feaa:20a2", host); - ASSERT_EQ(666, port); - - // Invalid IPv4. - EXPECT_FALSE(parse_host_and_port("1.2.3.4:", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("1.2.3.4::", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("1.2.3.4:hello", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port(":123", &canonical_address, &host, &port, &error)); - - // Invalid IPv6. - EXPECT_FALSE(parse_host_and_port(":1", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("::::::::1", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("[::1", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("[::1]", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("[::1]:", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("[::1]::", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("[::1]:hello", &canonical_address, &host, &port, &error)); - - // Invalid ports. - EXPECT_FALSE(parse_host_and_port("[::1]:-1", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("[::1]:0", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("[::1]:65536", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("1.2.3.4:-1", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("1.2.3.4:0", &canonical_address, &host, &port, &error)); - EXPECT_FALSE(parse_host_and_port("1.2.3.4:65536", &canonical_address, &host, &port, &error)); -} - void test_mkdirs(const std::string basepath) { EXPECT_TRUE(mkdirs(basepath)); EXPECT_NE(-1, adb_creat(basepath.c_str(), 0600)); |