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

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

Issue 275533002: Handle h_addr in a more libc independent way. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 7 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 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 314
315 // Verify the returned hostent structure 315 // Verify the returned hostent structure
316 ASSERT_NE(NULL_HOST, host); 316 ASSERT_NE(NULL_HOST, host);
317 ASSERT_EQ(AF_INET, host->h_addrtype); 317 ASSERT_EQ(AF_INET, host->h_addrtype);
318 ASSERT_EQ(sizeof(in_addr_t), host->h_length); 318 ASSERT_EQ(sizeof(in_addr_t), host->h_length);
319 ASSERT_STREQ(FAKE_HOSTNAME, host->h_name); 319 ASSERT_STREQ(FAKE_HOSTNAME, host->h_name);
320 320
321 in_addr_t** addr_list = reinterpret_cast<in_addr_t**>(host->h_addr_list); 321 in_addr_t** addr_list = reinterpret_cast<in_addr_t**>(host->h_addr_list);
322 ASSERT_NE(reinterpret_cast<in_addr_t**>(NULL), addr_list); 322 ASSERT_NE(reinterpret_cast<in_addr_t**>(NULL), addr_list);
323 ASSERT_EQ(NULL, addr_list[1]); 323 ASSERT_EQ(NULL, addr_list[1]);
324 in_addr_t exptected_addr = htonl(FAKE_IP); 324 in_addr_t expected_addr = htonl(FAKE_IP);
325 ASSERT_EQ(exptected_addr, *addr_list[0]); 325 ASSERT_EQ(expected_addr, *addr_list[0]);
326 // Check that h_addr also matches as in some libc's it may be a separate
327 // member.
328 in_addr_t* first_addr = reinterpret_cast<in_addr_t*>(host->h_addr);
329 ASSERT_EQ(expected_addr, *first_addr);
326 } 330 }
327 331
328 TEST_F(FakeHostResolverTest, Gethostbyname_Failure) { 332 TEST_F(FakeHostResolverTest, Gethostbyname_Failure) {
329 hostent* host = ki_gethostbyname("nosuchhost.com"); 333 hostent* host = ki_gethostbyname("nosuchhost.com");
330 ASSERT_EQ(NULL_HOST, host); 334 ASSERT_EQ(NULL_HOST, host);
331 ASSERT_EQ(HOST_NOT_FOUND, h_errno); 335 ASSERT_EQ(HOST_NOT_FOUND, h_errno);
332 } 336 }
333 337
334 // Looking up purely numeric hostnames should work without PPAPI 338 // Looking up purely numeric hostnames should work without PPAPI
335 // so we don't need the fakes for this test 339 // so we don't need the fakes for this test
336 TEST_F(HostResolverTest, Gethostbyname_Numeric) { 340 TEST_F(HostResolverTest, Gethostbyname_Numeric) {
337 struct hostent* host = ki_gethostbyname("8.8.8.8"); 341 struct hostent* host = ki_gethostbyname("8.8.8.8");
338 342
339 // Verify the returned hostent structure 343 // Verify the returned hostent structure
340 ASSERT_NE(NULL_HOST, host); 344 ASSERT_NE(NULL_HOST, host);
341 ASSERT_EQ(AF_INET, host->h_addrtype); 345 ASSERT_EQ(AF_INET, host->h_addrtype);
342 ASSERT_EQ(sizeof(in_addr_t), host->h_length); 346 ASSERT_EQ(sizeof(in_addr_t), host->h_length);
343 ASSERT_STREQ("8.8.8.8", host->h_name); 347 ASSERT_STREQ("8.8.8.8", host->h_name);
344 348
345 in_addr_t** addr_list = reinterpret_cast<in_addr_t**>(host->h_addr_list); 349 in_addr_t** addr_list = reinterpret_cast<in_addr_t**>(host->h_addr_list);
346 ASSERT_NE(reinterpret_cast<in_addr_t**>(NULL), addr_list); 350 ASSERT_NE(reinterpret_cast<in_addr_t**>(NULL), addr_list);
347 ASSERT_EQ(NULL, addr_list[1]); 351 ASSERT_EQ(NULL, addr_list[1]);
348 ASSERT_EQ(inet_addr("8.8.8.8"), *addr_list[0]); 352 ASSERT_EQ(inet_addr("8.8.8.8"), *addr_list[0]);
353 // Check that h_addr also matches as in some libc's it may be a separate
354 // member.
355 in_addr_t* first_addr = reinterpret_cast<in_addr_t*>(host->h_addr);
356 ASSERT_EQ(inet_addr("8.8.8.8"), *first_addr);
349 } 357 }
350 358
351 // These utility functions are only used for newlib (glibc provides its own 359 // These utility functions are only used for newlib (glibc provides its own
352 // implementations of these functions). 360 // implementations of these functions).
353 #if !defined(__GLIBC__) 361 #if !defined(__GLIBC__)
354 362
355 TEST(SocketUtilityFunctions, Hstrerror) { 363 TEST(SocketUtilityFunctions, Hstrerror) {
356 EXPECT_STREQ("Unknown error in gethostbyname: 2718.", hstrerror(2718)); 364 EXPECT_STREQ("Unknown error in gethostbyname: 2718.", hstrerror(2718));
357 } 365 }
358 366
359 TEST(SocketUtilityFunctions, Gai_Strerror) { 367 TEST(SocketUtilityFunctions, Gai_Strerror) {
360 EXPECT_STREQ("Unknown error in getaddrinfo: 2719.", gai_strerror(2719)); 368 EXPECT_STREQ("Unknown error in getaddrinfo: 2719.", gai_strerror(2719));
361 } 369 }
362 370
363 #endif // !defined(__GLIBC__) 371 #endif // !defined(__GLIBC__)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698