GDB (xrefs)
rsp-low-selftests.c
Go to the documentation of this file.
1 /* Unit tests for the rsp-low.c file.
2 
3  Copyright (C) 2017-2018 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 "selftest.h"
22 #include "common/rsp-low.h"
23 
24 namespace selftests {
25 namespace rsp_low {
26 
27 /* Test the variant of hex2bin that returns a byte_vector. */
28 
30 {
32 
33  /* Test an empty string. */
34  bv = hex2bin ("");
35  SELF_CHECK (bv.size () == 0);
36 
37  /* Test a well-formated 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 } /* namespace rsp_low */
52 } /* namespace selftests */
53 
54 void
56 {
57  selftests::register_test ("hex2bin_byte_vector",
59 }
static void test_hex2bin_byte_vector()
void _initialize_rsp_low_selftests()
gdb::def_vector< gdb_byte > byte_vector
Definition: byte-vector.h:58
int hex2bin(const char *hex, gdb_byte *bin, int count)
Definition: rsp-low.c:115
void register_test(const std::string &name, selftest *test)
Definition: selftest.c:52
#define SELF_CHECK(VALUE)
Definition: selftest.h:67