From e163298ef21b34b78c95c78d0089a83451c4c669 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 23 Aug 2017 15:42:28 -0700 Subject: [PATCH] Fix adb tcpip tests. The test was assuming we still output the full help for every syntax error. While I'm here, make the diagnostics suck less. Bug: N/A Test: ran tests Change-Id: Idc28616f20c66391f32046cf4216f122998a84bd --- adb/commandline.cpp | 10 +++++++--- adb/test_adb.py | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/adb/commandline.cpp b/adb/commandline.cpp index 9f234737b..d126f52a5 100644 --- a/adb/commandline.cpp +++ b/adb/commandline.cpp @@ -1588,9 +1588,13 @@ int adb_commandline(int argc, const char** argv) { } else { return 0; } - } - else if (!strcmp(argv[0], "tcpip") && argc > 1) { - return adb_connect_command(android::base::StringPrintf("tcpip:%s", argv[1])); + } else if (!strcmp(argv[0], "tcpip")) { + if (argc != 2) return syntax_error("tcpip requires an argument"); + int port; + if (!android::base::ParseInt(argv[1], &port, 1, 65535)) { + return syntax_error("tcpip: invalid port: %s", argv[1]); + } + return adb_connect_command(android::base::StringPrintf("tcpip:%d", port)); } else if (!strcmp(argv[0], "remount") || !strcmp(argv[0], "reboot") || diff --git a/adb/test_adb.py b/adb/test_adb.py index cb3e0d85e..98c8a5922 100644 --- a/adb/test_adb.py +++ b/adb/test_adb.py @@ -60,13 +60,13 @@ class NonApiTest(unittest.TestCase): stderr=subprocess.STDOUT) out, _ = p.communicate() self.assertEqual(1, p.returncode) - self.assertIn('help message', out) + self.assertIn('requires an argument', out) p = subprocess.Popen(['adb', 'tcpip', 'foo'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, _ = p.communicate() self.assertEqual(1, p.returncode) - self.assertIn('error', out) + self.assertIn('invalid port', out) # Helper method that reads a pipe until it is closed, then sets the event. def _read_pipe_and_set_event(self, pipe, event):