| 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 |
| 5 #include <arpa/inet.h> |
| 4 #include <errno.h> | 6 #include <errno.h> |
| 5 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <netinet/in.h> |
| 6 #include <pthread.h> | 9 #include <pthread.h> |
| 10 #include <sys/types.h> |
| 11 #include <sys/socket.h> |
| 7 #include <sys/stat.h> | 12 #include <sys/stat.h> |
| 8 | 13 |
| 9 #include <map> | 14 #include <map> |
| 10 #include <string> | 15 #include <string> |
| 11 | 16 |
| 12 #include "gmock/gmock.h" | 17 #include "gmock/gmock.h" |
| 13 #include "gtest/gtest.h" | 18 #include "gtest/gtest.h" |
| 14 | 19 |
| 15 #include "nacl_io/kernel_intercept.h" | 20 #include "nacl_io/kernel_intercept.h" |
| 16 #include "nacl_io/kernel_proxy.h" | 21 #include "nacl_io/kernel_proxy.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 EXPECT_EQ(errno, EBADF); | 238 EXPECT_EQ(errno, EBADF); |
| 234 EXPECT_LT(ki_shutdown(0, SHUT_RDWR), 0); | 239 EXPECT_LT(ki_shutdown(0, SHUT_RDWR), 0); |
| 235 EXPECT_EQ(errno, ENOTSOCK); | 240 EXPECT_EQ(errno, ENOTSOCK); |
| 236 } | 241 } |
| 237 | 242 |
| 238 TEST_F(SocketTest, Socket) { | 243 TEST_F(SocketTest, Socket) { |
| 239 EXPECT_LT(ki_socket(AF_UNIX, SOCK_STREAM, 0), 0); | 244 EXPECT_LT(ki_socket(AF_UNIX, SOCK_STREAM, 0), 0); |
| 240 EXPECT_EQ(errno, EAFNOSUPPORT); | 245 EXPECT_EQ(errno, EAFNOSUPPORT); |
| 241 EXPECT_LT(ki_socket(AF_INET, SOCK_RAW, 0), 0); | 246 EXPECT_LT(ki_socket(AF_INET, SOCK_RAW, 0), 0); |
| 242 EXPECT_EQ(errno, EPROTONOSUPPORT); | 247 EXPECT_EQ(errno, EPROTONOSUPPORT); |
| 243 | |
| 244 // These four af/protocol combinations should be supported. | |
| 245 EXPECT_LT(ki_socket(AF_INET, SOCK_STREAM, 0), 0); | |
| 246 EXPECT_EQ(errno, EACCES); | |
| 247 EXPECT_LT(ki_socket(AF_INET, SOCK_DGRAM, 0), 0); | |
| 248 EXPECT_EQ(errno, EACCES); | |
| 249 EXPECT_LT(ki_socket(AF_INET6, SOCK_STREAM, 0), 0); | |
| 250 EXPECT_EQ(errno, EACCES); | |
| 251 EXPECT_LT(ki_socket(AF_INET6, SOCK_DGRAM, 0), 0); | |
| 252 EXPECT_EQ(errno, EACCES); | |
| 253 } | 248 } |
| 254 | 249 |
| 255 TEST_F(SocketTest, Socketpair) { | 250 TEST_F(SocketTest, Socketpair) { |
| 256 int sv[2]; | 251 int sv[2]; |
| 257 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, NULL), 0); | 252 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, NULL), 0); |
| 258 EXPECT_EQ(errno, EFAULT); | 253 EXPECT_EQ(errno, EFAULT); |
| 259 EXPECT_LT(ki_socketpair(AF_UNIX, SOCK_STREAM, 0, sv), 0); | 254 EXPECT_LT(ki_socketpair(AF_UNIX, SOCK_STREAM, 0, sv), 0); |
| 260 EXPECT_EQ(errno, EAFNOSUPPORT); | 255 EXPECT_EQ(errno, EAFNOSUPPORT); |
| 261 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, sv), 0); | 256 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, sv), 0); |
| 262 EXPECT_EQ(errno, EPROTONOSUPPORT); | 257 EXPECT_EQ(errno, EPROTONOSUPPORT); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 TEST(SocketUtilityFunctions, Ntohl) { | 400 TEST(SocketUtilityFunctions, Ntohl) { |
| 406 uint8_t network_bytes[4] = { 0x44, 0x33, 0x22, 0x11 }; | 401 uint8_t network_bytes[4] = { 0x44, 0x33, 0x22, 0x11 }; |
| 407 uint32_t network_long; | 402 uint32_t network_long; |
| 408 memcpy(&network_long, network_bytes, 4); | 403 memcpy(&network_long, network_bytes, 4); |
| 409 uint32_t host_long = ntohl(network_long); | 404 uint32_t host_long = ntohl(network_long); |
| 410 EXPECT_EQ(host_long, 0x44332211); | 405 EXPECT_EQ(host_long, 0x44332211); |
| 411 } | 406 } |
| 412 | 407 |
| 413 #endif // !defined(__GLIBC__) | 408 #endif // !defined(__GLIBC__) |
| 414 #endif // PROVIDES_SOCKETPAIR_API | 409 #endif // PROVIDES_SOCKETPAIR_API |
| OLD | NEW |