gdb: Convert language la_pass_by_reference field to a method
[deliverable/binutils-gdb.git] / gdb / unittests / rsp-low-selftests.c
1 /* Unit tests for the rsp-low.c file.
2
3 Copyright (C) 2017-2020 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 "gdbsupport/rsp-low.h"
23
24 namespace selftests {
25 namespace rsp_low {
26
27 /* Test the variant of hex2bin that returns a byte_vector. */
28
29 static void test_hex2bin_byte_vector ()
30 {
31 gdb::byte_vector bv;
32
33 /* Test an empty string. */
34 bv = hex2bin ("");
35 SELF_CHECK (bv.size () == 0);
36
37 /* Test a well-formatted hex string. */
38 bv = hex2bin ("abcd01");
39 SELF_CHECK (bv.size () == 3);
40 SELF_CHECK (bv[0] == 0xab);
41 SELF_CHECK (bv[1] == 0xcd);
42 SELF_CHECK (bv[2] == 0x01);
43
44 /* Test an odd-length hex string. */
45 bv = hex2bin ("0123c");
46 SELF_CHECK (bv.size () == 2);
47 SELF_CHECK (bv[0] == 0x01);
48 SELF_CHECK (bv[1] == 0x23);
49 }
50
51 static void test_hex2str ()
52 {
53 SELF_CHECK (hex2str ("666f6f") == "foo");
54 SELF_CHECK (hex2str ("666f6fa") == "foo");
55 SELF_CHECK (hex2str ("666f6f", 2) == "fo");
56 SELF_CHECK (hex2str ("666", 2) == "f");
57 SELF_CHECK (hex2str ("666", 6) == "f");
58 SELF_CHECK (hex2str ("") == "");
59 }
60
61 } /* namespace rsp_low */
62 } /* namespace selftests */
63
64 void _initialize_rsp_low_selftests ();
65 void
66 _initialize_rsp_low_selftests ()
67 {
68 selftests::register_test ("hex2bin_byte_vector",
69 selftests::rsp_low::test_hex2bin_byte_vector);
70 selftests::register_test ("hex2str",
71 selftests::rsp_low::test_hex2str);
72 }
This page took 0.030072 seconds and 4 git commands to generate.