s4:torture: Initialize param arrays
[Samba.git] / lib / util / tests / test_byteorder_verify.c
bloba18ddad72273da24ae875e2261bceea8ff94906a
1 /*
2 * Unix SMB/CIFS implementation.
4 * Copyright (C) 2018-2019 Andreas Schneider <asn@samba.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdarg.h>
21 #include <stddef.h>
22 #include <stdint.h>
23 #include <setjmp.h>
24 #include <cmocka.h>
26 #include "lib/replace/replace.h"
27 #include "lib/util/bytearray.h"
28 #include "lib/util/byteorder.h"
30 static void torture_le_u8(void **state)
32 uint8_t data[2] = {0};
33 uint8_t result;
35 (void)state;
37 /* Test CVAL and SCVAL */
38 PUSH_LE_U8(data, 0, 23);
39 PUSH_LE_U8(data, 1, 42);
41 result = CVAL(data, 0);
42 assert_int_equal(result, 23);
44 result = CVAL(data, 1);
45 assert_int_equal(result, 42);
47 /* Test CVAL_NC and PVAL */
48 PUSH_LE_U8(data, 0, 23);
49 PUSH_LE_U8(data, 1, 42);
51 result = CVAL_NC(data, 0);
52 assert_int_equal(result, 23);
54 result = PVAL(data, 1);
55 assert_int_equal(result, 42);
57 /* Test SCVAL */
58 SCVAL(data, 0, 42);
59 SCVAL(data, 1, 23);
61 result = PULL_LE_U8(data, 0);
62 assert_int_equal(result, 42);
64 result = PULL_LE_U8(data, 1);
65 assert_int_equal(result, 23);
68 static void torture_le_u16(void **state)
70 uint8_t data[2] = {0};
71 uint16_t result;
73 (void)state;
75 /* Test SVAL */
76 PUSH_LE_U16(data, 0, 0xff00);
77 result = SVAL(data, 0);
78 assert_int_equal(result, 0xff00);
80 /* Test SSVAL */
81 SSVAL(data, 0, 0x00ff);
82 result = PULL_LE_U16(data, 0);
83 assert_int_equal(result, 0x00ff);
85 /* Test SSVALX */
86 SSVALX(data, 0, 0x00fa);
87 result = PULL_LE_U16(data, 0);
88 assert_int_equal(result, 0x00fa);
90 /* Test SSVALS */
91 SSVALS(data, 0, 0x00fb);
92 result = PULL_LE_U16(data, 0);
93 assert_int_equal(result, 0x00fb);
96 static void torture_le_u32(void **state)
98 uint8_t data[4] = {0};
99 uint32_t result;
101 (void)state;
103 /* Test IVAL */
104 PUSH_LE_U32(data, 0, 0xff000000);
105 result = IVAL(data, 0);
106 assert_int_equal(result, 0xff000000);
108 /* Test SIVAL */
109 SIVAL(data, 0, 0xffaabbcc);
110 result = PULL_LE_U32(data, 0);
111 assert_int_equal(result, 0xffaabbcc);
113 /* Test SIVALX */
114 SIVALX(data, 0, 0xffbbccdd);
115 result = PULL_LE_U32(data, 0);
116 assert_int_equal(result, 0xffbbccdd);
118 /* Test SIVALS */
119 SIVALS(data, 0, 0xffccddee);
120 result = PULL_LE_U32(data, 0);
121 assert_int_equal(result, 0xffccddee);
124 static void torture_le_u64(void **state)
126 uint8_t data[8] = {0};
127 uint64_t result;
129 (void)state;
131 PUSH_LE_U64(data, 0, 0xfffefffefffefffeUL);
132 result = BVAL(data, 0);
133 assert_int_equal(result, 0xfffefffefffefffeUL);
135 SBVAL(data, 0, 0xfffafffafffafffaUL);
136 result = PULL_LE_U64(data, 0);
137 assert_int_equal(result, 0xfffafffafffafffaUL);
140 static void torture_be_u8(void **state)
142 uint8_t data[2] = {0};
143 uint8_t result;
145 (void)state;
147 PUSH_BE_U8(data, 0, 23);
148 PUSH_BE_U8(data, 1, 42);
150 result = CVAL(data, 0);
151 assert_int_equal(result, 23);
153 result = CVAL(data, 1);
154 assert_int_equal(result, 42);
156 SCVAL(data, 0, 42);
157 SCVAL(data, 1, 23);
159 result = PULL_BE_U8(data, 0);
160 assert_int_equal(result, 42);
162 result = PULL_BE_U8(data, 1);
163 assert_int_equal(result, 23);
166 static void torture_be_u16(void **state)
168 uint8_t data[2] = {0};
169 uint16_t result;
171 (void)state;
173 /* Test RSVAL */
174 PUSH_BE_U16(data, 0, 0xff00);
175 result = RSVAL(data, 0);
176 assert_int_equal(result, 0xff00);
178 /* Test RSVALS */
179 PUSH_BE_U16(data, 0, 0xffaa);
180 result = RSVALS(data, 0);
181 assert_int_equal(result, 0xffaa);
183 /* Test RSSVAL */
184 RSSVAL(data, 0, 0x00ff);
185 result = PULL_BE_U16(data, 0);
186 assert_int_equal(result, 0x00ff);
188 /* Test RSSVALS */
189 RSSVALS(data, 0, 0x00fa);
190 result = PULL_BE_U16(data, 0);
191 assert_int_equal(result, 0x00fa);
194 static void torture_be_u32(void **state)
196 uint8_t data[4] = {0};
197 uint32_t result;
199 (void)state;
201 /* Test RIVAL */
202 PUSH_BE_U32(data, 0, 0xff000000);
203 result = RIVAL(data, 0);
204 assert_int_equal(result, 0xff000000);
206 /* Test RIVALS */
207 PUSH_BE_U32(data, 0, 0xff0000aa);
208 result = RIVALS(data, 0);
209 assert_int_equal(result, 0xff0000aa);
211 /* Test RSIVAL */
212 RSIVAL(data, 0, 0xffeeddcc);
213 result = PULL_BE_U32(data, 0);
214 assert_int_equal(result, 0xffeeddcc);
216 /* Test RSIVALS */
217 RSIVALS(data, 0, 0xffaaddcc);
218 result = PULL_BE_U32(data, 0);
219 assert_int_equal(result, 0xffaaddcc);
222 static void torture_be_u64(void **state)
224 uint8_t data[8] = {0};
225 uint64_t result;
227 (void)state;
229 /* Test RBVAL */
230 PUSH_BE_U64(data, 0, 0xfffefffefffefffeUL);
231 result = RBVAL(data, 0);
232 assert_int_equal(result, 0xfffefffefffefffeUL);
234 /* Test RBVALS */
235 PUSH_BE_U64(data, 0, 0xfffafffafffafffaUL);
236 result = RBVALS(data, 0);
237 assert_int_equal(result, 0xfffafffafffafffaUL);
239 /* Test RSBVAL */
240 RSBVAL(data, 0, 0xfffbfffbfffbfffbUL);
241 result = PULL_BE_U64(data, 0);
242 assert_int_equal(result, 0xfffbfffbfffbfffbUL);
244 /* Test RSBVALS */
245 RSBVALS(data, 0, 0xfffcfffcfffcfffcUL);
246 result = PULL_BE_U64(data, 0);
247 assert_int_equal(result, 0xfffcfffcfffcfffcUL);
250 int main(int argc, char *argv[])
252 int rc;
253 const struct CMUnitTest tests[] = {
254 cmocka_unit_test(torture_le_u8),
255 cmocka_unit_test(torture_le_u16),
256 cmocka_unit_test(torture_le_u32),
257 cmocka_unit_test(torture_le_u64),
259 cmocka_unit_test(torture_be_u8),
260 cmocka_unit_test(torture_be_u16),
261 cmocka_unit_test(torture_be_u32),
262 cmocka_unit_test(torture_be_u64),
265 if (argc == 2) {
266 cmocka_set_test_filter(argv[1]);
268 cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
270 rc = cmocka_run_group_tests(tests, NULL, NULL);
272 return rc;