2 * Copyright (C) 2013 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
22 #include "testutils.h"
24 #include "virendian.h"
27 test1(const void *data ATTRIBUTE_UNUSED)
29 /* Regular char should work, even if signed, and even with
30 * unaligned access. */
31 char array[] = { 1, 2, 3, 4, 5, 6, 7, 8,
32 0x89, 0x8a, 0x8b, 0x8c, 0x8d };
35 if (virReadBufInt64BE(array) != 0x0102030405060708ULL)
37 if (virReadBufInt64BE(array + 5) != 0x060708898a8b8c8dULL)
39 if (virReadBufInt64LE(array) != 0x0807060504030201ULL)
41 if (virReadBufInt64LE(array + 5) != 0x8d8c8b8a89080706ULL)
44 if (virReadBufInt32BE(array) != 0x01020304U)
46 if (virReadBufInt32BE(array + 9) != 0x8a8b8c8dU)
48 if (virReadBufInt32LE(array) != 0x04030201U)
50 if (virReadBufInt32LE(array + 9) != 0x8d8c8b8aU)
59 test2(const void *data ATTRIBUTE_UNUSED)
61 /* Unsigned char should work without cast, even if unaligned access. */
62 unsigned char array[] = { 1, 2, 3, 4, 5, 6, 7, 8,
63 0x89, 0x8a, 0x8b, 0x8c, 0x8d };
66 if (virReadBufInt64BE(array) != 0x0102030405060708ULL)
68 if (virReadBufInt64BE(array + 5) != 0x060708898a8b8c8dULL)
70 if (virReadBufInt64LE(array) != 0x0807060504030201ULL)
72 if (virReadBufInt64LE(array + 5) != 0x8d8c8b8a89080706ULL)
75 if (virReadBufInt32BE(array) != 0x01020304U)
77 if (virReadBufInt32BE(array + 9) != 0x8a8b8c8dU)
79 if (virReadBufInt32LE(array) != 0x04030201U)
81 if (virReadBufInt32LE(array + 9) != 0x8d8c8b8aU)
94 if (virtTestRun("test1", test1, NULL) < 0)
96 if (virtTestRun("test2", test2, NULL) < 0)
102 VIRT_TEST_MAIN(mymain)