Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / unittests / rsp-low-selftests.c
CommitLineData
21fe1c75
SM
1/* Unit tests for the rsp-low.c file.
2
88b9d363 3 Copyright (C) 2017-2022 Free Software Foundation, Inc.
21fe1c75
SM
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"
268a13a5
TT
21#include "gdbsupport/selftest.h"
22#include "gdbsupport/rsp-low.h"
21fe1c75
SM
23
24namespace selftests {
25namespace rsp_low {
26
27/* Test the variant of hex2bin that returns a byte_vector. */
28
29static 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
30baf67b 37 /* Test a well-formatted hex string. */
21fe1c75
SM
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
5d9310c4
SM
51static 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
21fe1c75
SM
61} /* namespace rsp_low */
62} /* namespace selftests */
63
6c265988 64void _initialize_rsp_low_selftests ();
21fe1c75
SM
65void
66_initialize_rsp_low_selftests ()
67{
68 selftests::register_test ("hex2bin_byte_vector",
69 selftests::rsp_low::test_hex2bin_byte_vector);
5d9310c4
SM
70 selftests::register_test ("hex2str",
71 selftests::rsp_low::test_hex2str);
21fe1c75 72}
This page took 0.532886 seconds and 4 git commands to generate.