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
)
53 if (virReadBufInt16BE(array
) != 0x0102U
)
55 if (virReadBufInt16BE(array
+ 11) != 0x8c8dU
)
57 if (virReadBufInt16LE(array
) != 0x0201U
)
59 if (virReadBufInt16LE(array
+ 11) != 0x8d8cU
)
68 test2(const void *data ATTRIBUTE_UNUSED
)
70 /* Unsigned char should work without cast, even if unaligned access. */
71 unsigned char array
[] = { 1, 2, 3, 4, 5, 6, 7, 8,
72 0x89, 0x8a, 0x8b, 0x8c, 0x8d };
75 if (virReadBufInt64BE(array
) != 0x0102030405060708ULL
)
77 if (virReadBufInt64BE(array
+ 5) != 0x060708898a8b8c8dULL
)
79 if (virReadBufInt64LE(array
) != 0x0807060504030201ULL
)
81 if (virReadBufInt64LE(array
+ 5) != 0x8d8c8b8a89080706ULL
)
84 if (virReadBufInt32BE(array
) != 0x01020304U
)
86 if (virReadBufInt32BE(array
+ 9) != 0x8a8b8c8dU
)
88 if (virReadBufInt32LE(array
) != 0x04030201U
)
90 if (virReadBufInt32LE(array
+ 9) != 0x8d8c8b8aU
)
93 if (virReadBufInt16BE(array
) != 0x0102U
)
95 if (virReadBufInt16BE(array
+ 11) != 0x8c8dU
)
97 if (virReadBufInt16LE(array
) != 0x0201U
)
99 if (virReadBufInt16LE(array
+ 11) != 0x8d8cU
)
112 if (virTestRun("test1", test1
, NULL
) < 0)
114 if (virTestRun("test2", test2
, NULL
) < 0)
120 VIR_TEST_MAIN(mymain
)