diff options
author | wtc%netscape.com <devnull@localhost> | 2000-02-17 03:52:25 +0000 |
---|---|---|
committer | wtc%netscape.com <devnull@localhost> | 2000-02-17 03:52:25 +0000 |
commit | 52c82bebb7f681e47f29a5fc4cb81272b4772dc5 (patch) | |
tree | 27610b5fdac43d670719b62471a6b77499cbcbfc | |
parent | a0a58b42e9221d0765dcac0039037f32b6b7149e (diff) | |
download | nspr-hg-52c82bebb7f681e47f29a5fc4cb81272b4772dc5.tar.gz |
Added new test ntoh.c.
Modified files: pr/tests/Makefile, pr/tests/Makefile.in, runtests.ksh
Added file: pr/tests/ntoh.c
(NSPRPUB_RELEASE_4_0_BRANCH)
-rw-r--r-- | pr/tests/Makefile | 1 | ||||
-rw-r--r-- | pr/tests/Makefile.in | 1 | ||||
-rw-r--r-- | pr/tests/ntoh.c | 106 | ||||
-rwxr-xr-x | pr/tests/runtests.ksh | 1 |
4 files changed, 109 insertions, 0 deletions
diff --git a/pr/tests/Makefile b/pr/tests/Makefile index 5d2155f4..d1851723 100644 --- a/pr/tests/Makefile +++ b/pr/tests/Makefile @@ -94,6 +94,7 @@ CSRCS = \ nblayer.c \ nonblock.c \ ntioto.c \ + ntoh.c \ op_2long.c \ op_excl.c \ op_filnf.c \ diff --git a/pr/tests/Makefile.in b/pr/tests/Makefile.in index 650f738f..720dc68a 100644 --- a/pr/tests/Makefile.in +++ b/pr/tests/Makefile.in @@ -98,6 +98,7 @@ CSRCS = \ nblayer.c \ nonblock.c \ ntioto.c \ + ntoh.c \ op_2long.c \ op_excl.c \ op_filnf.c \ diff --git a/pr/tests/ntoh.c b/pr/tests/ntoh.c new file mode 100644 index 00000000..006f5b92 --- /dev/null +++ b/pr/tests/ntoh.c @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.1 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 2000 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + * A test program for PR_htons, PR_ntohs, PR_htonl, PR_ntohl, + * PR_htonll, and PR_ntohll. + */ + +#include "prnetdb.h" + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +/* Byte sequence in network byte order */ +static unsigned char bytes_n[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + +/* Integers in host byte order */ +static PRUint16 s_h = 0x0102; +static PRUint32 l_h = 0x01020304; +static PRUint64 ll_h = LL_INIT(0x01020304, 0x05060708); + +int main() +{ + union { + PRUint16 s; + PRUint32 l; + PRUint64 ll; + unsigned char bytes[8]; + } un; + + un.s = s_h; + printf("%u %u\n", + un.bytes[0], un.bytes[1]); + un.s = PR_htons(un.s); + printf("%u %u\n", + un.bytes[0], un.bytes[1]); + if (memcmp(un.bytes, bytes_n, 2)) { + fprintf(stderr, "PR_htons failed\n"); + exit(1); + } + un.s = PR_ntohs(un.s); + printf("%u %u\n", + un.bytes[0], un.bytes[1]); + if (un.s != s_h) { + fprintf(stderr, "PR_ntohs failed\n"); + exit(1); + } + + un.l = l_h; + printf("%u %u %u %u\n", + un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3]); + un.l = PR_htonl(un.l); + printf("%u %u %u %u\n", + un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3]); + if (memcmp(un.bytes, bytes_n, 4)) { + fprintf(stderr, "PR_htonl failed\n"); + exit(1); + } + un.l = PR_ntohl(un.l); + printf("%u %u %u %u\n", + un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3]); + if (un.l != l_h) { + fprintf(stderr, "PR_ntohl failed\n"); + exit(1); + } + + un.ll = ll_h; + printf("%u %u %u %u %u %u %u %u\n", + un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3], + un.bytes[4], un.bytes[5], un.bytes[6], un.bytes[7]); + un.ll = PR_htonll(un.ll); + printf("%u %u %u %u %u %u %u %u\n", + un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3], + un.bytes[4], un.bytes[5], un.bytes[6], un.bytes[7]); + if (memcmp(un.bytes, bytes_n, 8)) { + fprintf(stderr, "PR_htonll failed\n"); + exit(1); + } + un.ll = PR_ntohll(un.ll); + printf("%u %u %u %u %u %u %u %u\n", + un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3], + un.bytes[4], un.bytes[5], un.bytes[6], un.bytes[7]); + if (LL_NE(un.ll, ll_h)) { + fprintf(stderr, "PR_ntohll failed\n"); + exit(1); + } + + printf("PASS\n"); + return 0; +} diff --git a/pr/tests/runtests.ksh b/pr/tests/runtests.ksh index 10eb8d32..2e102f52 100755 --- a/pr/tests/runtests.ksh +++ b/pr/tests/runtests.ksh @@ -125,6 +125,7 @@ nameshm1 nblayer nonblock ntioto +ntoh op_2long op_excl op_filnf |