Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/openlaunchd
Path: blob/master/liblaunch/test/byteswap_tests.c
374 views
1
/*
2
* Copyright (c) 2013 R. Tyler Croy, All rights reserved.
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
18
#include "liblaunch_test.h"
19
20
/*
21
* TEST: host2wire
22
*****************************************************/
23
void test_host2wire_64(void **state) {
24
/*
25
uint64_t host_int = 1024;
26
uint64_t wire_int = host2wire(host_int);
27
*/
28
/* Nothing to test here on a big-endian system, and we can't verify because
29
* htonll() doesn't exist */
30
};
31
32
void test_host2wire_32(void **state) {
33
uint32_t host_int = 1024;
34
uint32_t wire_int = htonl(host_int);
35
assert_true(wire_int == host2wire(host_int));
36
};
37
38
void test_host2wire_16(void **state) {
39
uint16_t host_int = 32;
40
uint16_t wire_int = htons(host_int);
41
assert_true(wire_int == host2wire(host_int));
42
};
43
44
void test_host2wire_8(void **state) {
45
uint8_t host_int = 8;
46
assert_true(host_int == host2wire(host_int));
47
};
48
/*****************************************************/
49
50
#include <stdio.h>
51
/*
52
* TEST: wire2host
53
*****************************************************/
54
void test_wire2host_64(void **s) {
55
uint64_t wire_int = htobe64(1024);
56
uint64_t host_int = 1024;
57
assert_true(host_int == wire2host(wire_int));
58
};
59
60
void test_wire2host_32(void **s) {
61
uint32_t wire_int = htonl(32);
62
uint32_t host_int = 32;
63
assert_true(host_int == wire2host(wire_int));
64
};
65
66
void test_wire2host_16(void **s) {
67
uint16_t wire_int = htons(32);
68
uint16_t host_int = 32;
69
assert_true(host_int == wire2host(wire_int));
70
};
71
72
void test_wire2host_8(void **s) {
73
uint8_t host_int = 8;
74
assert_true(host_int = wire2host(host_int));
75
};
76
/****************************************************/
77
78