]>
Commit | Line | Data |
---|---|---|
965f03d8 | 1 | /* |
e0edde6f | 2 | * Copyright (c) 2010, 2011 Nicira, Inc. |
965f03d8 BP |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at: | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | #include <config.h> | |
10a24935 | 18 | #include "byte-order.h" |
965f03d8 BP |
19 | #include <assert.h> |
20 | #include <inttypes.h> | |
21 | ||
22 | int | |
23 | main(void) | |
24 | { | |
6506f45c | 25 | #ifndef __CHECKER__ |
965f03d8 BP |
26 | /* I picked some random numbers. */ |
27 | const uint16_t s = 0xc9bd; | |
28 | const uint32_t l = 0xffe56ae8; | |
29 | const uint64_t ll = UINT64_C(0xb6fe878a9117ecdb); | |
30 | ||
31 | assert(htons(ntohs(s)) == s); | |
32 | assert(ntohs(htons(s)) == s); | |
33 | assert(CONSTANT_HTONS(ntohs(s)) == s); | |
34 | assert(ntohs(CONSTANT_HTONS(s)) == s); | |
35 | assert(ntohs(CONSTANT_HTONS(l)) == (uint16_t) l); | |
36 | assert(ntohs(CONSTANT_HTONS(ll)) == (uint16_t) ll); | |
37 | ||
38 | assert(htonl(ntohl(l)) == l); | |
39 | assert(ntohl(htonl(l)) == l); | |
40 | assert(CONSTANT_HTONL(ntohl(l)) == l); | |
41 | assert(ntohl(CONSTANT_HTONL(l)) == l); | |
42 | assert(ntohl(CONSTANT_HTONL(ll)) == (uint32_t) ll); | |
43 | ||
44 | assert(htonll(ntohll(ll)) == ll); | |
45 | assert(ntohll(htonll(ll)) == ll); | |
46 | assert(CONSTANT_HTONLL(ntohll(ll)) == ll); | |
47 | assert(ntohll(CONSTANT_HTONLL(ll))); | |
6506f45c BP |
48 | #else /* __CHECKER__ */ |
49 | /* Making sparse happy with this code makes it unreadable, so don't bother. */ | |
50 | #endif | |
965f03d8 BP |
51 | |
52 | return 0; | |
53 | } |