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

Unified Diff: native_client_sdk/src/libraries/nacl_io_test/socket_test.cc

Issue 22625004: Adds htonl, htons, ntohl, and ntohs to newlib (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gethostbyname
Patch Set: Review changes Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/nacl_io_test/socket_test.cc
diff --git a/native_client_sdk/src/libraries/nacl_io_test/socket_test.cc b/native_client_sdk/src/libraries/nacl_io_test/socket_test.cc
index 893975100ce72a0c4db346c42edd6eb670b0cdab..b7dbda063e67a8154232412ef174d28a5110136d 100644
--- a/native_client_sdk/src/libraries/nacl_io_test/socket_test.cc
+++ b/native_client_sdk/src/libraries/nacl_io_test/socket_test.cc
@@ -266,7 +266,27 @@ TEST_F(SocketTest, Socketpair) {
// These utility functions are only used for newlib (glibc provides its own
// implementations of these functions).
-#if !defined(__GLIBC__)
+#if !defined(__GLIBC__)
+
+TEST(SocketUtilityFunctions, Htonl) {
+ uint32_t host_long = 0x44332211;
+ uint32_t network_long = htonl(host_long);
+ uint8_t network_bytes[4];
+ memcpy(network_bytes, &network_long, 4);
+ EXPECT_EQ(network_bytes[0], 0x44);
+ EXPECT_EQ(network_bytes[1], 0x33);
+ EXPECT_EQ(network_bytes[2], 0x22);
+ EXPECT_EQ(network_bytes[3], 0x11);
+}
+
+TEST(SocketUtilityFunctions, Htons) {
+ uint16_t host_short = 0x2211;
+ uint16_t network_short = htons(host_short);
+ uint8_t network_bytes[2];
+ memcpy(network_bytes, &network_short, 2);
+ EXPECT_EQ(network_bytes[0], 0x22);
+ EXPECT_EQ(network_bytes[1], 0x11);
+}
static struct in_addr generate_ipv4_addr(int tuple1, int tuple2,
int tuple3, int tuple4) {
@@ -372,5 +392,19 @@ TEST(SocketUtilityFunctions, Inet_ntop_failure) {
EXPECT_EQ(errno, ENOSPC);
}
+TEST(SocketUtilityFunctions, Ntohs) {
+ uint8_t network_bytes[2] = { 0x22, 0x11 };
+ uint16_t *network_short = reinterpret_cast<uint16_t*>(network_bytes);
binji 2013/08/08 17:56:44 same issue here, no?
torinmr 2013/08/08 19:09:38 Darn, you're right! On 2013/08/08 17:56:44, binji
+ uint16_t host_short = ntohs(*network_short);
+ EXPECT_EQ(host_short, 0x2211);
+}
+
+TEST(SocketUtilityFunctions, Ntohl) {
+ uint8_t network_bytes[4] = { 0x44, 0x33, 0x22, 0x11 };
+ uint32_t *network_long = reinterpret_cast<uint32_t*>(network_bytes);
binji 2013/08/08 17:56:44 and here
torinmr 2013/08/08 19:09:38 Done.
+ uint32_t host_long = ntohl(*network_long);
+ EXPECT_EQ(host_long, 0x44332211);
+}
+
#endif // !defined(__GLIBC__)
#endif // PROVIDES_SOCKETPAIR_API

Powered by Google App Engine
This is Rietveld 408576698