OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <arpa/inet.h> | 5 #include <arpa/inet.h> |
6 #include <errno.h> | 6 #include <errno.h> |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <netinet/in.h> | 8 #include <netinet/in.h> |
9 #include <pthread.h> | 9 #include <pthread.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
12 #include <sys/stat.h> | 12 #include <sys/stat.h> |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <string> | |
16 | 15 |
17 #include "gmock/gmock.h" | 16 #include "gmock/gmock.h" |
18 #include "gtest/gtest.h" | 17 #include "gtest/gtest.h" |
19 | 18 |
20 #include "nacl_io/kernel_intercept.h" | 19 #include "nacl_io/kernel_intercept.h" |
21 #include "nacl_io/kernel_proxy.h" | 20 #include "nacl_io/kernel_proxy.h" |
22 #include "nacl_io/ossocket.h" | 21 #include "nacl_io/ossocket.h" |
23 #include "nacl_io/ostypes.h" | 22 #include "nacl_io/ostypes.h" |
24 | 23 |
25 #ifdef PROVIDES_SOCKET_API | 24 #ifdef PROVIDES_SOCKET_API |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, NULL), 0); | 252 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, NULL), 0); |
254 EXPECT_EQ(errno, EFAULT); | 253 EXPECT_EQ(errno, EFAULT); |
255 EXPECT_LT(ki_socketpair(AF_UNIX, SOCK_STREAM, 0, sv), 0); | 254 EXPECT_LT(ki_socketpair(AF_UNIX, SOCK_STREAM, 0, sv), 0); |
256 EXPECT_EQ(errno, EAFNOSUPPORT); | 255 EXPECT_EQ(errno, EAFNOSUPPORT); |
257 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, sv), 0); | 256 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, sv), 0); |
258 EXPECT_EQ(errno, EPROTONOSUPPORT); | 257 EXPECT_EQ(errno, EPROTONOSUPPORT); |
259 EXPECT_LT(ki_socketpair(AF_INET6, SOCK_STREAM, 0, sv), 0); | 258 EXPECT_LT(ki_socketpair(AF_INET6, SOCK_STREAM, 0, sv), 0); |
260 EXPECT_EQ(errno, EPROTONOSUPPORT); | 259 EXPECT_EQ(errno, EPROTONOSUPPORT); |
261 } | 260 } |
262 | 261 |
263 // These utility functions are only used for newlib (glibc provides its own | |
264 // implementations of these functions). | |
265 #if !defined(__GLIBC__) | |
266 | |
267 TEST(SocketUtilityFunctions, Hstrerror) { | |
268 EXPECT_STREQ(hstrerror(2718), | |
269 "Unknown error in gethostbyname: 2718."); | |
270 } | |
271 | |
272 #endif // !defined(__GLIBC__) | |
273 | |
274 TEST(SocketUtilityFunctions, Htonl) { | 262 TEST(SocketUtilityFunctions, Htonl) { |
275 uint32_t host_long = 0x44332211; | 263 uint32_t host_long = 0x44332211; |
276 uint32_t network_long = htonl(host_long); | 264 uint32_t network_long = htonl(host_long); |
277 uint8_t network_bytes[4]; | 265 uint8_t network_bytes[4]; |
278 memcpy(network_bytes, &network_long, 4); | 266 memcpy(network_bytes, &network_long, 4); |
279 EXPECT_EQ(network_bytes[0], 0x44); | 267 EXPECT_EQ(network_bytes[0], 0x44); |
280 EXPECT_EQ(network_bytes[1], 0x33); | 268 EXPECT_EQ(network_bytes[1], 0x33); |
281 EXPECT_EQ(network_bytes[2], 0x22); | 269 EXPECT_EQ(network_bytes[2], 0x22); |
282 EXPECT_EQ(network_bytes[3], 0x11); | 270 EXPECT_EQ(network_bytes[3], 0x11); |
283 } | 271 } |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 | 527 |
540 TEST(SocketUtilityFunctions, Ntohl) { | 528 TEST(SocketUtilityFunctions, Ntohl) { |
541 uint8_t network_bytes[4] = { 0x44, 0x33, 0x22, 0x11 }; | 529 uint8_t network_bytes[4] = { 0x44, 0x33, 0x22, 0x11 }; |
542 uint32_t network_long; | 530 uint32_t network_long; |
543 memcpy(&network_long, network_bytes, 4); | 531 memcpy(&network_long, network_bytes, 4); |
544 uint32_t host_long = ntohl(network_long); | 532 uint32_t host_long = ntohl(network_long); |
545 EXPECT_EQ(host_long, 0x44332211); | 533 EXPECT_EQ(host_long, 0x44332211); |
546 } | 534 } |
547 | 535 |
548 #endif // PROVIDES_SOCKETPAIR_API | 536 #endif // PROVIDES_SOCKETPAIR_API |
OLD | NEW |