diff options
| author | Spencer Low <CompareAndSwap@gmail.com> | 2015-10-18 16:45:09 -0700 |
|---|---|---|
| committer | Spencer Low <CompareAndSwap@gmail.com> | 2015-10-18 16:45:09 -0700 |
| commit | 0a79600e723de2da76ce7f3a44fb3821a484931b (patch) | |
| tree | 90e67a46bffc77be6096c0f129c1bc22d13482bd /adb/sysdeps_win32_test.cpp | |
| parent | fb371d6a6bc59be3eebf089b93b5aa07ad13b5b2 (diff) | |
adb: win32: Improve Winsock error code mappings and strings
Improved mapping of Winsock error codes to POSIX error codes, especially
WSAECONNABORTED to EPIPE (which WriteFdExactly() looks for) when sending
to a closed socket and WSAECONNRESET to ECONNRESET when the peer resets
the connection.
Use a macro to map strerror() to adb_strerror() which handles these
POSIX error codes that the Windows C Runtime doesn't recognize.
Also:
* Unittest for adb_strerror().
* Don't trace when send() returns WSAEWOULDBLOCK because that is
expected.
Change-Id: If46aeb7b36de3eebfbbccf5478ff5b1bb087714b
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
Diffstat (limited to 'adb/sysdeps_win32_test.cpp')
| -rwxr-xr-x | adb/sysdeps_win32_test.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/adb/sysdeps_win32_test.cpp b/adb/sysdeps_win32_test.cpp index cc3ac5c166..66d1ba881a 100755 --- a/adb/sysdeps_win32_test.cpp +++ b/adb/sysdeps_win32_test.cpp @@ -67,3 +67,29 @@ TEST(sysdeps_win32, adb_getenv) { EXPECT_GT(strlen(path_val), 0); } } + +void TestAdbStrError(int err, const char* expected) { + errno = 12345; + const char* result = adb_strerror(err); + // Check that errno is not overwritten. + EXPECT_EQ(12345, errno); + EXPECT_STREQ(expected, result); +} + +TEST(sysdeps_win32, adb_strerror) { + // Test an error code that should not have a mapped string. Use an error + // code that is not used by the internal implementation of adb_strerror(). + TestAdbStrError(-2, "Unknown error"); + // adb_strerror() uses -1 internally, so test that it can still be passed + // as a parameter. + TestAdbStrError(-1, "Unknown error"); + // Test very big, positive unknown error. + TestAdbStrError(1000000, "Unknown error"); + // Test success case. + TestAdbStrError(0, "No error"); + // Test error that regular strerror() should have a string for. + TestAdbStrError(EPERM, "Operation not permitted"); + // Test error that regular strerror() doesn't have a string for, but that + // adb_strerror() returns. + TestAdbStrError(ECONNRESET, "Connection reset by peer"); +} |
