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

Side by Side Diff: native_client_sdk/src/tests/nacl_io_socket_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
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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // TODO(noelallen) BUG=294412 209 // TODO(noelallen) BUG=294412
210 // Re-enable testing on bots when server sockets are available. 210 // Re-enable testing on bots when server sockets are available.
211 TEST_F(SocketTestTCP, DISABLED_Connect) { 211 TEST_F(SocketTestTCP, DISABLED_Connect) {
212 char outbuf[256]; 212 char outbuf[256];
213 char inbuf[512]; 213 char inbuf[512];
214 214
215 memset(outbuf, 1, sizeof(outbuf)); 215 memset(outbuf, 1, sizeof(outbuf));
216 memset(inbuf, 0, sizeof(inbuf)); 216 memset(inbuf, 0, sizeof(inbuf));
217 217
218 int sock = socket(AF_INET, SOCK_STREAM, 0); 218 int sock = socket(AF_INET, SOCK_STREAM, 0);
219 EXPECT_NE(-1, sock); 219 EXPECT_GT(sock, -1);
220 220
221 sockaddr_in addr; 221 sockaddr_in addr;
222 socklen_t addrlen = sizeof(addr); 222 socklen_t addrlen = sizeof(addr);
223 223
224 IP4ToSockAddr(LOCAL_HOST, PORT1, &addr); 224 IP4ToSockAddr(LOCAL_HOST, PORT1, &addr);
225 int err = connect(sock, (sockaddr*) &addr, addrlen); 225 int err = connect(sock, (sockaddr*) &addr, addrlen);
226 226
227 EXPECT_EQ(ENONE, err) << "Failed with errno: " << errno << "\n"; 227 EXPECT_EQ(ENONE, err) << "Failed with errno: " << errno << "\n";
228 228
229 EXPECT_EQ(sizeof(outbuf), write(sock, outbuf, sizeof(outbuf))); 229 EXPECT_EQ(sizeof(outbuf), write(sock, outbuf, sizeof(outbuf)));
230 EXPECT_EQ(sizeof(outbuf), read(sock, inbuf, sizeof(inbuf))); 230 EXPECT_EQ(sizeof(outbuf), read(sock, inbuf, sizeof(inbuf)));
231 231
232 // Now they should be the same 232 // Now they should be the same
233 EXPECT_EQ(0, memcmp(outbuf, inbuf, sizeof(outbuf))); 233 EXPECT_EQ(0, memcmp(outbuf, inbuf, sizeof(outbuf)));
234 } 234 }
235 235
236 TEST_F(SocketTest, Setsockopt) {
237 int sock = socket(AF_INET, SOCK_STREAM, 0);
238 EXPECT_GT(sock, -1);
239 int socket_error = 99;
240 socklen_t len = sizeof(socket_error);
241
242 // Test for valid option (SO_ERROR) which should be 0 when a socket
243 // is first created.
244 ASSERT_EQ(0, getsockopt(sock, SOL_SOCKET, SO_ERROR, &socket_error, &len));
245 ASSERT_EQ(0, socket_error);
246 ASSERT_EQ(sizeof(socket_error), len);
247
248 // Test for an invalid option (-1)
249 ASSERT_EQ(-1, getsockopt(sock, SOL_SOCKET, -1, &socket_error, &len));
250 ASSERT_EQ(ENOPROTOOPT, errno);
251 }
noelallen1 2013/09/30 22:56:16 Read an unbound socket, for a real Errno?
Sam Clegg 2013/10/01 00:15:49 I'm mimicking the linux behavior and strangely eno
252
253 TEST_F(SocketTest, Getsockopt) {
254 int sock = socket(AF_INET, SOCK_STREAM, 0);
255 EXPECT_GT(sock, -1);
256
257 // It should not be possible to set SO_ERROR using setsockopt.
258 int socket_error = 10;
259 socklen_t len = sizeof(socket_error);
260 ASSERT_EQ(-1, setsockopt(sock, SOL_SOCKET, SO_ERROR, &socket_error, len));
261 ASSERT_EQ(ENOPROTOOPT, errno);
262 }
263
236 #endif // PROVIDES_SOCKET_API 264 #endif // PROVIDES_SOCKET_API
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698