diff options
| author | Ben Pfaff <blp@nicira.com> | 2010-10-28 17:13:18 -0700 |
|---|---|---|
| committer | Ben Pfaff <blp@nicira.com> | 2010-10-29 09:48:47 -0700 |
| commit | 10a24935c9d382e4d85b05d9616843f3d3bb4983 (patch) | |
| tree | 20157e20f0f2ddd2e93d66428f23663da7a78c4f /tests/test-byte-order.c | |
| parent | 965f03d85ff6288eec3919edb67d5a2d247a6625 (diff) | |
| download | openvswitch-10a24935c9d382e4d85b05d9616843f3d3bb4983.tar.gz | |
xtoxll: Rename "byte-order" since it now include more than xtoxll.
Suggested-by: Justin Pettit <jpettit@nicira.com>
Diffstat (limited to 'tests/test-byte-order.c')
| -rw-r--r-- | tests/test-byte-order.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test-byte-order.c b/tests/test-byte-order.c new file mode 100644 index 000000000..187075457 --- /dev/null +++ b/tests/test-byte-order.c @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2010 Nicira Networks. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <config.h> +#include "byte-order.h" +#include <assert.h> +#include <inttypes.h> + +int +main(void) +{ + /* I picked some random numbers. */ + const uint16_t s = 0xc9bd; + const uint32_t l = 0xffe56ae8; + const uint64_t ll = UINT64_C(0xb6fe878a9117ecdb); + + assert(htons(ntohs(s)) == s); + assert(ntohs(htons(s)) == s); + assert(CONSTANT_HTONS(ntohs(s)) == s); + assert(ntohs(CONSTANT_HTONS(s)) == s); + assert(ntohs(CONSTANT_HTONS(l)) == (uint16_t) l); + assert(ntohs(CONSTANT_HTONS(ll)) == (uint16_t) ll); + + assert(htonl(ntohl(l)) == l); + assert(ntohl(htonl(l)) == l); + assert(CONSTANT_HTONL(ntohl(l)) == l); + assert(ntohl(CONSTANT_HTONL(l)) == l); + assert(ntohl(CONSTANT_HTONL(ll)) == (uint32_t) ll); + + assert(htonll(ntohll(ll)) == ll); + assert(ntohll(htonll(ll)) == ll); + assert(CONSTANT_HTONLL(ntohll(ll)) == ll); + assert(ntohll(CONSTANT_HTONLL(ll))); + + return 0; +} |
