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

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

Issue 344833005: [NaCl SDK] nacl_io: Fix bug in getaddrinfo() where service is "0" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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/libraries/nacl_io/host_resolver.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <netinet/in.h> 6 #include <netinet/in.h>
7 #include <sys/types.h> 7 #include <sys/types.h>
8 #include <sys/socket.h> 8 #include <sys/socket.h>
9 9
10 #include "fake_ppapi/fake_pepper_interface.h" 10 #include "fake_ppapi/fake_pepper_interface.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 #define NULL_INFO ((struct addrinfo*)NULL) 83 #define NULL_INFO ((struct addrinfo*)NULL)
84 #define NULL_ADDR ((struct sockaddr*)NULL) 84 #define NULL_ADDR ((struct sockaddr*)NULL)
85 #define NULL_HOST (static_cast<hostent*>(NULL)) 85 #define NULL_HOST (static_cast<hostent*>(NULL))
86 86
87 TEST_F(HostResolverTest, Getaddrinfo_Numeric) { 87 TEST_F(HostResolverTest, Getaddrinfo_Numeric) {
88 struct addrinfo* ai = NULL; 88 struct addrinfo* ai = NULL;
89 struct sockaddr_in* in; 89 struct sockaddr_in* in;
90 struct addrinfo hints; 90 struct addrinfo hints;
91 91
92 // Numberic only 92 // Numeric only
93 memset(&hints, 0, sizeof(hints)); 93 memset(&hints, 0, sizeof(hints));
94 hints.ai_family = AF_INET; 94 hints.ai_family = AF_INET;
95 hints.ai_socktype = SOCK_STREAM; 95 hints.ai_socktype = SOCK_STREAM;
96 96
97 uint32_t expected_addr = htonl(0x01020304); 97 uint32_t expected_addr = htonl(0x01020304);
98 ASSERT_EQ(0, ki_getaddrinfo("1.2.3.4", NULL, &hints, &ai)); 98 ASSERT_EQ(0, ki_getaddrinfo("1.2.3.4", NULL, &hints, &ai));
99 ASSERT_NE(NULL_INFO, ai); 99 ASSERT_NE(NULL_INFO, ai);
100 ASSERT_NE(NULL_ADDR, ai->ai_addr); 100 ASSERT_NE(NULL_ADDR, ai->ai_addr);
101 ASSERT_EQ(AF_INET, ai->ai_family); 101 ASSERT_EQ(AF_INET, ai->ai_family);
102 ASSERT_EQ(SOCK_STREAM, ai->ai_socktype); 102 ASSERT_EQ(SOCK_STREAM, ai->ai_socktype);
103 in = (struct sockaddr_in*)ai->ai_addr; 103 in = (struct sockaddr_in*)ai->ai_addr;
104 ASSERT_EQ(expected_addr, in->sin_addr.s_addr); 104 ASSERT_EQ(expected_addr, in->sin_addr.s_addr);
105 ASSERT_EQ(NULL_INFO, ai->ai_next); 105 ASSERT_EQ(NULL_INFO, ai->ai_next);
106 106
107 ki_freeaddrinfo(ai); 107 ki_freeaddrinfo(ai);
108 } 108 }
109 109
110 TEST_F(HostResolverTest, Getaddrinfo_NumericService) {
111 struct addrinfo* ai = NULL;
112 struct sockaddr_in* in;
113 struct addrinfo hints;
114
115 memset(&hints, 0, sizeof(hints));
116 hints.ai_family = AF_INET;
117 hints.ai_socktype = SOCK_STREAM;
118
119 ASSERT_EQ(0, ki_getaddrinfo("1.2.3.4", "0", &hints, &ai));
120 ASSERT_NE(NULL_INFO, ai);
121 ASSERT_NE(NULL_ADDR, ai->ai_addr);
122 in = (struct sockaddr_in*)ai->ai_addr;
123 uint16_t expected_port = htons(0);
124 ASSERT_EQ(expected_port, in->sin_port);
125 ASSERT_EQ(NULL_INFO, ai->ai_next);
126 ki_freeaddrinfo(ai);
127
128 ASSERT_EQ(0, ki_getaddrinfo("1.2.3.4", "65000", &hints, &ai));
129 ASSERT_NE(NULL_INFO, ai);
130 ASSERT_NE(NULL_ADDR, ai->ai_addr);
131 in = (struct sockaddr_in*)ai->ai_addr;
132 expected_port = htons(65000);
133 ASSERT_EQ(expected_port, in->sin_port);
134 ASSERT_EQ(NULL_INFO, ai->ai_next);
135 ki_freeaddrinfo(ai);
136 }
137
110 TEST_F(HostResolverTest, Getaddrinfo_MissingPPAPI) { 138 TEST_F(HostResolverTest, Getaddrinfo_MissingPPAPI) {
111 // Verify that full lookups fail due to lack of PPAPI interfaces 139 // Verify that full lookups fail due to lack of PPAPI interfaces
112 struct addrinfo* ai = NULL; 140 struct addrinfo* ai = NULL;
113 ASSERT_EQ(EAI_SYSTEM, ki_getaddrinfo("google.com", NULL, NULL, &ai)); 141 ASSERT_EQ(EAI_SYSTEM, ki_getaddrinfo("google.com", NULL, NULL, &ai));
114 } 142 }
115 143
116 TEST_F(HostResolverTest, Getaddrinfo_Passive) { 144 TEST_F(HostResolverTest, Getaddrinfo_Passive) {
117 struct addrinfo* ai = NULL; 145 struct addrinfo* ai = NULL;
118 struct sockaddr_in* in; 146 struct sockaddr_in* in;
119 struct sockaddr_in6* in6; 147 struct sockaddr_in6* in6;
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 394
367 TEST(SocketUtilityFunctions, Hstrerror) { 395 TEST(SocketUtilityFunctions, Hstrerror) {
368 EXPECT_STREQ("Unknown error in gethostbyname: 2718.", hstrerror(2718)); 396 EXPECT_STREQ("Unknown error in gethostbyname: 2718.", hstrerror(2718));
369 } 397 }
370 398
371 TEST(SocketUtilityFunctions, Gai_Strerror) { 399 TEST(SocketUtilityFunctions, Gai_Strerror) {
372 EXPECT_STREQ("Unknown error in getaddrinfo: 2719.", gai_strerror(2719)); 400 EXPECT_STREQ("Unknown error in getaddrinfo: 2719.", gai_strerror(2719));
373 } 401 }
374 402
375 #endif // !defined(__GLIBC__) 403 #endif // !defined(__GLIBC__)
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/host_resolver.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698