C++ify xml-syscall.c
[deliverable/binutils-gdb.git] / gdb / unittests / common-utils-selftests.c
CommitLineData
d4081a38
PA
1/* Self tests for general utility routines for GDB, the GNU debugger.
2
61baf725 3 Copyright (C) 2016-2017 Free Software Foundation, Inc.
d4081a38
PA
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
b2f8eb7a 20#include "common-defs.h"
d4081a38
PA
21#include "selftest.h"
22
d4081a38
PA
23namespace selftests {
24
d4081a38 25static void
b2f8eb7a 26string_printf_tests ()
d4081a38
PA
27{
28 SELF_CHECK (string_printf ("%s", "") == "");
29 SELF_CHECK (string_printf ("%d comes before 2", 1) == "1 comes before 2");
30 SELF_CHECK (string_printf ("hello %s", "world") == "hello world");
31
32#define X10 "0123456789"
33#define X100 X10 X10 X10 X10 X10 X10 X10 X10 X10 X10
34#define X1000 X100 X100 X100 X100 X100 X100 X100 X100 X100 X100
35#define X10000 X1000 X1000 X1000 X1000 X1000 X1000 X1000 X1000 X1000 X1000
36#define X100000 X10000 X10000 X10000 X10000 X10000 X10000 X10000 X10000 X10000 X10000
37 SELF_CHECK (string_printf ("%s", X10) == X10);
38 SELF_CHECK (string_printf ("%s", X100) == X100);
39 SELF_CHECK (string_printf ("%s", X1000) == X1000);
40 SELF_CHECK (string_printf ("%s", X10000) == X10000);
41 SELF_CHECK (string_printf ("%s", X100000) == X100000);
42}
43
bd413795
TT
44static std::string
45format (const char *fmt, ...)
46{
47 va_list vp;
48
49 va_start (vp, fmt);
50 std::string result = string_vprintf (fmt, vp);
51 va_end (vp);
52 return result;
53}
54
55static void
56string_vprintf_tests ()
57{
58 /* Basic smoke tests. */
59 SELF_CHECK (format ("%s", "test") == "test");
60 SELF_CHECK (format ("%d", 23) == "23");
61 SELF_CHECK (format ("%s %d %s", "test", 23, "done")
62 == "test 23 done");
63 SELF_CHECK (format ("nothing") == "nothing");
64}
65
d4081a38
PA
66} /* namespace selftests */
67
d4081a38 68void
b2f8eb7a 69_initialize_common_utils_selftests ()
d4081a38 70{
b2f8eb7a 71 selftests::register_test ("string_printf", selftests::string_printf_tests);
bd413795 72 selftests::register_test ("string_vprintf", selftests::string_vprintf_tests);
d4081a38 73}
This page took 0.133945 seconds and 4 git commands to generate.