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

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

Issue 23456045: [NaCl SDK] nacl_io: Add initial support for getsockopt (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 EXPECT_LT(ki_sendmsg(-1, &msg, 0), 0); 214 EXPECT_LT(ki_sendmsg(-1, &msg, 0), 0);
215 EXPECT_EQ(errno, EBADF); 215 EXPECT_EQ(errno, EBADF);
216 EXPECT_LT(ki_sendmsg(0, &msg, 0), 0); 216 EXPECT_LT(ki_sendmsg(0, &msg, 0), 0);
217 EXPECT_EQ(errno, ENOTSOCK); 217 EXPECT_EQ(errno, ENOTSOCK);
218 } 218 }
219 219
220 TEST_F(SocketTest, Setsockopt) { 220 TEST_F(SocketTest, Setsockopt) {
221 socklen_t len = 10; 221 socklen_t len = 10;
222 char optval[len]; 222 char optval[len];
223 223
224 EXPECT_LT(ki_setsockopt(123, SOL_SOCKET, SO_ACCEPTCONN, NULL, len), 0); 224 // Passing a bad address as optval should generate EFAULT
225 EXPECT_EQ(-1, ki_setsockopt(123, SOL_SOCKET, SO_ACCEPTCONN, NULL, len));
225 EXPECT_EQ(errno, EFAULT); 226 EXPECT_EQ(errno, EFAULT);
226 EXPECT_LT(ki_setsockopt(-1, SOL_SOCKET, SO_ACCEPTCONN, optval, len), 0); 227
228 // Passing a bad socket descriptor should generate EBADF
229 EXPECT_EQ(-1, ki_setsockopt(-1, SOL_SOCKET, SO_ACCEPTCONN, optval, len));
227 EXPECT_EQ(errno, EBADF); 230 EXPECT_EQ(errno, EBADF);
228 EXPECT_LT(ki_setsockopt(0, SOL_SOCKET, SO_ACCEPTCONN, optval, len), 0); 231
232 // Passing an FD that is valid but not a socket should generate ENOTSOCK
233 EXPECT_EQ(-1, ki_setsockopt(0, SOL_SOCKET, SO_ACCEPTCONN, optval, len));
229 EXPECT_EQ(errno, ENOTSOCK); 234 EXPECT_EQ(errno, ENOTSOCK);
230 } 235 }
231 236
232 TEST_F(SocketTest, Shutdown) { 237 TEST_F(SocketTest, Shutdown) {
233 EXPECT_LT(ki_shutdown(-1, SHUT_RDWR), 0); 238 EXPECT_LT(ki_shutdown(-1, SHUT_RDWR), 0);
234 EXPECT_EQ(errno, EBADF); 239 EXPECT_EQ(errno, EBADF);
235 EXPECT_LT(ki_shutdown(0, SHUT_RDWR), 0); 240 EXPECT_LT(ki_shutdown(0, SHUT_RDWR), 0);
236 EXPECT_EQ(errno, ENOTSOCK); 241 EXPECT_EQ(errno, ENOTSOCK);
237 } 242 }
238 243
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 TEST(SocketUtilityFunctions, Ntohl) { 406 TEST(SocketUtilityFunctions, Ntohl) {
402 uint8_t network_bytes[4] = { 0x44, 0x33, 0x22, 0x11 }; 407 uint8_t network_bytes[4] = { 0x44, 0x33, 0x22, 0x11 };
403 uint32_t network_long; 408 uint32_t network_long;
404 memcpy(&network_long, network_bytes, 4); 409 memcpy(&network_long, network_bytes, 4);
405 uint32_t host_long = ntohl(network_long); 410 uint32_t host_long = ntohl(network_long);
406 EXPECT_EQ(host_long, 0x44332211); 411 EXPECT_EQ(host_long, 0x44332211);
407 } 412 }
408 413
409 #endif // !defined(__GLIBC__) 414 #endif // !defined(__GLIBC__)
410 #endif // PROVIDES_SOCKETPAIR_API 415 #endif // PROVIDES_SOCKETPAIR_API
OLDNEW
« no previous file with comments | « native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698