gdb: Use -Werror when checking for (un)supported warning flags
[external/binutils.git] / gdb / utils-selftests.c
1 /* Self tests for general utility routines for GDB, the GNU debugger.
2
3    Copyright (C) 2016-2017 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
23 #if GDB_SELF_TEST
24
25 namespace selftests {
26
27 /* common-utils self tests.  Defined here instead of in
28    common/common-utils.c because that file is shared with
29    gdbserver.  */
30
31 static void
32 common_utils_tests (void)
33 {
34   SELF_CHECK (string_printf ("%s", "") == "");
35   SELF_CHECK (string_printf ("%d comes before 2", 1) == "1 comes before 2");
36   SELF_CHECK (string_printf ("hello %s", "world") == "hello world");
37
38 #define X10 "0123456789"
39 #define X100 X10 X10 X10 X10 X10 X10 X10 X10 X10 X10
40 #define X1000 X100 X100 X100 X100 X100 X100 X100 X100 X100 X100
41 #define X10000 X1000 X1000 X1000 X1000 X1000 X1000 X1000 X1000 X1000 X1000
42 #define X100000 X10000 X10000 X10000 X10000 X10000 X10000 X10000 X10000 X10000 X10000
43   SELF_CHECK (string_printf ("%s", X10) == X10);
44   SELF_CHECK (string_printf ("%s", X100) == X100);
45   SELF_CHECK (string_printf ("%s", X1000) == X1000);
46   SELF_CHECK (string_printf ("%s", X10000) == X10000);
47   SELF_CHECK (string_printf ("%s", X100000) == X100000);
48 }
49
50 } /* namespace selftests */
51
52 #endif
53
54 void
55 _initialize_utils_selftests (void)
56 {
57 #if GDB_SELF_TEST
58   register_self_test (selftests::common_utils_tests);
59 #endif
60 }