Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: native_client_sdk/src/tests/nacl_io_test/socket_test.cc

Issue 1335783005: [NaCl SDK] nacl_io: Add support for basic socketpairs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 EXPECT_LT(ki_socket(AF_UNIX, SOCK_STREAM, 0), 0); 247 EXPECT_LT(ki_socket(AF_UNIX, SOCK_STREAM, 0), 0);
248 EXPECT_EQ(errno, EAFNOSUPPORT); 248 EXPECT_EQ(errno, EAFNOSUPPORT);
249 EXPECT_LT(ki_socket(AF_INET, SOCK_RAW, 0), 0); 249 EXPECT_LT(ki_socket(AF_INET, SOCK_RAW, 0), 0);
250 EXPECT_EQ(errno, EPROTONOSUPPORT); 250 EXPECT_EQ(errno, EPROTONOSUPPORT);
251 } 251 }
252 252
253 TEST_F(SocketTest, Socketpair) { 253 TEST_F(SocketTest, Socketpair) {
254 int sv[2]; 254 int sv[2];
255 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, NULL), 0); 255 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, NULL), 0);
256 EXPECT_EQ(errno, EFAULT); 256 EXPECT_EQ(errno, EFAULT);
257 EXPECT_LT(ki_socketpair(AF_UNIX, SOCK_STREAM, 0, sv), 0);
258 EXPECT_EQ(errno, EAFNOSUPPORT);
259 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, sv), 0); 257 EXPECT_LT(ki_socketpair(AF_INET, SOCK_STREAM, 0, sv), 0);
260 EXPECT_EQ(errno, EPROTONOSUPPORT); 258 EXPECT_EQ(errno, EOPNOTSUPP);
261 EXPECT_LT(ki_socketpair(AF_INET6, SOCK_STREAM, 0, sv), 0); 259 EXPECT_LT(ki_socketpair(AF_INET6, SOCK_STREAM, 0, sv), 0);
262 EXPECT_EQ(errno, EPROTONOSUPPORT); 260 EXPECT_EQ(errno, EOPNOTSUPP);
261
262 sv[0] = sv[1] = -1;
263 errno = 0;
264 EXPECT_EQ(ki_socketpair(AF_UNIX, SOCK_STREAM, 0, sv), 0);
265 EXPECT_EQ(errno, 0);
266 EXPECT_GE(sv[0], 0);
267 EXPECT_GE(sv[1], 0);
Sam Clegg 2015/09/17 09:40:39 More testing here would be good. Perhaps a split
263 } 268 }
264 269
265 TEST(SocketUtilityFunctions, Htonl) { 270 TEST(SocketUtilityFunctions, Htonl) {
266 uint32_t host_long = 0x44332211; 271 uint32_t host_long = 0x44332211;
267 uint32_t network_long = htonl(host_long); 272 uint32_t network_long = htonl(host_long);
268 uint8_t network_bytes[4]; 273 uint8_t network_bytes[4];
269 memcpy(network_bytes, &network_long, 4); 274 memcpy(network_bytes, &network_long, 4);
270 EXPECT_EQ(network_bytes[0], 0x44); 275 EXPECT_EQ(network_bytes[0], 0x44);
271 EXPECT_EQ(network_bytes[1], 0x33); 276 EXPECT_EQ(network_bytes[1], 0x33);
272 EXPECT_EQ(network_bytes[2], 0x22); 277 EXPECT_EQ(network_bytes[2], 0x22);
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 535
531 TEST(SocketUtilityFunctions, Ntohl) { 536 TEST(SocketUtilityFunctions, Ntohl) {
532 uint8_t network_bytes[4] = { 0x44, 0x33, 0x22, 0x11 }; 537 uint8_t network_bytes[4] = { 0x44, 0x33, 0x22, 0x11 };
533 uint32_t network_long; 538 uint32_t network_long;
534 memcpy(&network_long, network_bytes, 4); 539 memcpy(&network_long, network_bytes, 4);
535 uint32_t host_long = ntohl(network_long); 540 uint32_t host_long = ntohl(network_long);
536 EXPECT_EQ(host_long, 0x44332211); 541 EXPECT_EQ(host_long, 0x44332211);
537 } 542 }
538 543
539 #endif // PROVIDES_SOCKETPAIR_API 544 #endif // PROVIDES_SOCKETPAIR_API
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698