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

Unified Diff: native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc

Issue 63573006: [NaCl SDK] nacl_io: Auto-bind UDP socket on first sendto(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/mount_node_udp.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc
diff --git a/native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc b/native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc
index 24a9b030a8e96512aac7e77a617f91802b2359d4..7aa07bcca47c00e833d61b2e2b6b14ff5c7c410f 100644
--- a/native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc
+++ b/native_client_sdk/src/tests/nacl_io_socket_test/socket_test.cc
@@ -244,6 +244,42 @@ TEST_F(SocketTestUDP, SendRcv) {
EXPECT_EQ(0, memcmp(outbuf, inbuf, sizeof(outbuf)));
}
+TEST_F(SocketTestUDP, SendRcvUnbound) {
+ char outbuf[256];
+ char inbuf[512];
+
+ memset(outbuf, 1, sizeof(outbuf));
+ memset(inbuf, 0, sizeof(inbuf));
+
+ // Don't bind sock1_, this will automatically bind sock1_ to a random port
+ // at the time of the first send.
Sam Clegg 2013/11/18 17:10:42 Maybe check getlocalname() before and after the se
binji 2013/11/18 20:54:18 Done.
+ //EXPECT_EQ(0, Bind(sock1_, LOCAL_HOST, PORT1));
+ EXPECT_EQ(0, Bind(sock2_, LOCAL_HOST, PORT2));
+
+ sockaddr_in addr;
+ socklen_t addrlen = sizeof(addr);
+ IP4ToSockAddr(LOCAL_HOST, PORT2, &addr);
+
+ int len1 =
+ sendto(sock1_, outbuf, sizeof(outbuf), 0, (sockaddr*) &addr, addrlen);
+ EXPECT_EQ(sizeof(outbuf), len1);
+
+ // Ensure the buffers are different
+ EXPECT_NE(0, memcmp(outbuf, inbuf, sizeof(outbuf)));
+ memset(&addr, 0, sizeof(addr));
+
+ // Try to receive the previously sent packet
+ int len2 =
+ recvfrom(sock2_, inbuf, sizeof(inbuf), 0, (sockaddr*) &addr, &addrlen);
+ EXPECT_EQ(sizeof(outbuf), len2);
+ EXPECT_EQ(sizeof(sockaddr_in), addrlen);
+ EXPECT_EQ(LOCAL_HOST, htonl(addr.sin_addr.s_addr));
+ EXPECT_NE(0, htons(addr.sin_port));
+
+ // Now they should be the same
+ EXPECT_EQ(0, memcmp(outbuf, inbuf, sizeof(outbuf)));
+}
+
const size_t kQueueSize = 65536 * 8;
TEST_F(SocketTestUDP, FullFifo) {
char outbuf[16 * 1024];
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/mount_node_udp.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698