backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / virendiantest.c
blob263acc8e52baa7a75986bdcb7dcb298f5bfbea9c
1 /*
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/>.
20 #include <config.h>
22 #include "testutils.h"
24 #include "virendian.h"
26 static int
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 };
33 int ret = -1;
35 if (virReadBufInt64BE(array) != 0x0102030405060708ULL)
36 goto cleanup;
37 if (virReadBufInt64BE(array + 5) != 0x060708898a8b8c8dULL)
38 goto cleanup;
39 if (virReadBufInt64LE(array) != 0x0807060504030201ULL)
40 goto cleanup;
41 if (virReadBufInt64LE(array + 5) != 0x8d8c8b8a89080706ULL)
42 goto cleanup;
44 if (virReadBufInt32BE(array) != 0x01020304U)
45 goto cleanup;
46 if (virReadBufInt32BE(array + 9) != 0x8a8b8c8dU)
47 goto cleanup;
48 if (virReadBufInt32LE(array) != 0x04030201U)
49 goto cleanup;
50 if (virReadBufInt32LE(array + 9) != 0x8d8c8b8aU)
51 goto cleanup;
53 if (virReadBufInt16BE(array) != 0x0102U)
54 goto cleanup;
55 if (virReadBufInt16BE(array + 11) != 0x8c8dU)
56 goto cleanup;
57 if (virReadBufInt16LE(array) != 0x0201U)
58 goto cleanup;
59 if (virReadBufInt16LE(array + 11) != 0x8d8cU)
60 goto cleanup;
62 ret = 0;
63 cleanup:
64 return ret;
67 static int
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 };
73 int ret = -1;
75 if (virReadBufInt64BE(array) != 0x0102030405060708ULL)
76 goto cleanup;
77 if (virReadBufInt64BE(array + 5) != 0x060708898a8b8c8dULL)
78 goto cleanup;
79 if (virReadBufInt64LE(array) != 0x0807060504030201ULL)
80 goto cleanup;
81 if (virReadBufInt64LE(array + 5) != 0x8d8c8b8a89080706ULL)
82 goto cleanup;
84 if (virReadBufInt32BE(array) != 0x01020304U)
85 goto cleanup;
86 if (virReadBufInt32BE(array + 9) != 0x8a8b8c8dU)
87 goto cleanup;
88 if (virReadBufInt32LE(array) != 0x04030201U)
89 goto cleanup;
90 if (virReadBufInt32LE(array + 9) != 0x8d8c8b8aU)
91 goto cleanup;
93 if (virReadBufInt16BE(array) != 0x0102U)
94 goto cleanup;
95 if (virReadBufInt16BE(array + 11) != 0x8c8dU)
96 goto cleanup;
97 if (virReadBufInt16LE(array) != 0x0201U)
98 goto cleanup;
99 if (virReadBufInt16LE(array + 11) != 0x8d8cU)
100 goto cleanup;
102 ret = 0;
103 cleanup:
104 return ret;
107 static int
108 mymain(void)
110 int ret = 0;
112 if (virTestRun("test1", test1, NULL) < 0)
113 ret = -1;
114 if (virTestRun("test2", test2, NULL) < 0)
115 ret = -1;
117 return ret;
120 VIR_TEST_MAIN(mymain)