21#include "gdbsupport/format.h"
22#include "gdbsupport/selftest.h"
31namespace format_pieces {
36check (
const char *str,
const std::vector<format_piece> &expected_pieces,
37 bool gdb_format =
false)
39 ::format_pieces pieces (&str, gdb_format);
41 SELF_CHECK ((pieces.end () - pieces.begin ()) == expected_pieces.size ());
42 SELF_CHECK (std::equal (pieces.begin (), pieces.end (),
43 expected_pieces.begin ()));
49 check (
"This is an escape sequence: \\e",
51 format_piece (
"This is an escape sequence: \e", literal_piece, 0),
60 check (
"Hello\\t %d%llx%%d%d",
62 format_piece (
"Hello\t ", literal_piece, 0),
63 format_piece (
"%d", int_arg, 0),
64 format_piece (
"%" LL "x", long_long_arg, 0),
65 format_piece (
"%%d", literal_piece, 0),
66 format_piece (
"%d", int_arg, 0),
73 check (
"Hello\\t \"%p[%pF%ps%*.*d%p]\"",
75 format_piece (
"Hello\\t \"", literal_piece, 0),
76 format_piece (
"%p[", ptr_arg, 0),
77 format_piece (
"%pF", ptr_arg, 0),
78 format_piece (
"%ps", ptr_arg, 0),
79 format_piece (
"%*.*d", int_arg, 2),
80 format_piece (
"%p]", ptr_arg, 0),
81 format_piece (
"\"", literal_piece, 0),
91 check (
"Hello\\t %hu%lu%llu%zu",
93 format_piece (
"Hello\t ", literal_piece, 0),
94 format_piece (
"%hu", int_arg, 0),
95 format_piece (
"%lu", long_arg, 0),
96 format_piece (
"%" LL "u", long_long_arg, 0),
97 format_piece (
"%zu", size_t_arg, 0)
100 check (
"Hello\\t %hx%lx%llx%zx",
102 format_piece (
"Hello\t ", literal_piece, 0),
103 format_piece (
"%hx", int_arg, 0),
104 format_piece (
"%lx", long_arg, 0),
105 format_piece (
"%" LL "x", long_long_arg, 0),
106 format_piece (
"%zx", size_t_arg, 0)
109 check (
"Hello\\t %ho%lo%llo%zo",
111 format_piece (
"Hello\t ", literal_piece, 0),
112 format_piece (
"%ho", int_arg, 0),
113 format_piece (
"%lo", long_arg, 0),
114 format_piece (
"%" LL "o", long_long_arg, 0),
115 format_piece (
"%zo", size_t_arg, 0)
118 check (
"Hello\\t %hd%ld%lld%zd",
120 format_piece (
"Hello\t ", literal_piece, 0),
121 format_piece (
"%hd", int_arg, 0),
122 format_piece (
"%ld", long_arg, 0),
123 format_piece (
"%" LL "d", long_long_arg, 0),
124 format_piece (
"%zd", size_t_arg, 0)
133 format_piece (
"rc", literal_piece, 0),
134 format_piece (
"%I64d", long_long_arg, 0),
155 selftests::register_test (
"format_pieces",