]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/unittests/unpack-selftests.c
51e8c3942b49d76c388fa7b03843bcdf43afec3d
[thirdparty/binutils-gdb.git] / gdb / unittests / unpack-selftests.c
1 /* Self tests for unpack_field_as_long
2
3 Copyright (C) 2018-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "gdbsupport/selftest.h"
22 #include "selftest-arch.h"
23 #include "value.h"
24 #include "gdbtypes.h"
25 #include "arch-utils.h"
26
27 namespace selftests {
28 namespace unpack {
29
30 static void
31 unpack_field_as_long_tests (struct gdbarch *arch)
32 {
33 gdb_byte buffer[8];
34 const struct builtin_type *bt = builtin_type (arch);
35 struct type *struct_type = arch_composite_type (arch, "<<selftest>>",
36 TYPE_CODE_STRUCT);
37
38 append_composite_type_field (struct_type, "field0", bt->builtin_int8);
39 append_composite_type_field_aligned (struct_type, "field1",
40 bt->builtin_uint32, 4);
41
42 memset (buffer, 0, sizeof (buffer));
43 buffer[0] = 255;
44 if (gdbarch_byte_order (arch) == BFD_ENDIAN_BIG)
45 buffer[7] = 23;
46 else
47 buffer[4] = 23;
48
49 SELF_CHECK (unpack_field_as_long (struct_type, buffer, 0) == -1);
50 SELF_CHECK (unpack_field_as_long (struct_type, buffer, 1) == 23);
51 }
52
53 }
54 }
55
56 void _initialize_unpack_selftests ();
57 void
58 _initialize_unpack_selftests ()
59 {
60 selftests::register_test_foreach_arch
61 ("unpack_field_as_long", selftests::unpack::unpack_field_as_long_tests);
62 }