]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/unittests/style-selftests.c
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / unittests / style-selftests.c
1 /* Self tests for ui_file_style
2
3 Copyright (C) 2018-2021 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 "gdbsupport/selftest.h"
22 #include "ui-style.h"
23
24 namespace selftests {
25 namespace style {
26
27 #define CHECK_RGB(R, G, B) \
28 SELF_CHECK (rgb[0] == (R) && rgb[1] == (G) && rgb[2] == (B))
29
30 static void
31 run_tests ()
32 {
33 ui_file_style style;
34 size_t n_read;
35 uint8_t rgb[3];
36
37 SELF_CHECK (style.parse ("\033[m", &n_read));
38 SELF_CHECK (n_read == 3);
39 SELF_CHECK (style.get_foreground ().is_none ());
40 SELF_CHECK (style.get_background ().is_none ());
41 SELF_CHECK (style.get_intensity () == ui_file_style::NORMAL);
42 SELF_CHECK (!style.is_reverse ());
43 SELF_CHECK (style.to_ansi () == "\033[m");
44
45 style = ui_file_style ();
46 SELF_CHECK (style.parse ("\033[0m", &n_read));
47 SELF_CHECK (n_read == 4);
48 SELF_CHECK (style.get_foreground ().is_none ());
49 SELF_CHECK (style.get_background ().is_none ());
50 SELF_CHECK (style.get_intensity () == ui_file_style::NORMAL);
51 SELF_CHECK (!style.is_reverse ());
52 /* This particular case does not round-trip identically, but the
53 difference is unimportant. */
54 SELF_CHECK (style.to_ansi () == "\033[m");
55
56 SELF_CHECK (style.parse ("\033[7m", &n_read));
57 SELF_CHECK (n_read == 4);
58 SELF_CHECK (style.get_foreground ().is_none ());
59 SELF_CHECK (style.get_background ().is_none ());
60 SELF_CHECK (style.get_intensity () == ui_file_style::NORMAL);
61 SELF_CHECK (style.is_reverse ());
62 SELF_CHECK (style.to_ansi () == "\033[7m");
63
64 style = ui_file_style ();
65 SELF_CHECK (style.parse ("\033[32;1m", &n_read));
66 SELF_CHECK (n_read == 7);
67 SELF_CHECK (style.get_foreground ().is_basic ());
68 SELF_CHECK (style.get_foreground ().get_value () == ui_file_style::GREEN);
69 SELF_CHECK (style.get_background ().is_none ());
70 SELF_CHECK (style.get_intensity () == ui_file_style::BOLD);
71 SELF_CHECK (!style.is_reverse ());
72 SELF_CHECK (style.to_ansi () == "\033[32;1m");
73
74 style = ui_file_style ();
75 SELF_CHECK (style.parse ("\033[38;5;112;48;5;249m", &n_read));
76 SELF_CHECK (n_read == 20);
77 SELF_CHECK (!style.get_foreground ().is_basic ());
78 style.get_foreground ().get_rgb (rgb);
79 CHECK_RGB (0x87, 0xd7, 0);
80 SELF_CHECK (!style.get_background ().is_basic ());
81 style.get_background ().get_rgb (rgb);
82 CHECK_RGB (0xb2, 0xb2, 0xb2);
83 SELF_CHECK (style.get_intensity () == ui_file_style::NORMAL);
84 SELF_CHECK (!style.is_reverse ());
85 SELF_CHECK (style.to_ansi () == "\033[38;5;112;48;5;249m");
86
87 style = ui_file_style ();
88 SELF_CHECK (style.parse ("\033[38;2;83;84;85;48;2;0;1;254;2;7m", &n_read));
89 SELF_CHECK (n_read == 33);
90 SELF_CHECK (!style.get_foreground ().is_basic ());
91 style.get_foreground ().get_rgb (rgb);
92 CHECK_RGB (83, 84, 85);
93 SELF_CHECK (!style.get_background ().is_basic ());
94 style.get_background ().get_rgb (rgb);
95 CHECK_RGB (0, 1, 254);
96 SELF_CHECK (style.get_intensity () == ui_file_style::DIM);
97 SELF_CHECK (style.is_reverse ());
98 SELF_CHECK (style.to_ansi () == "\033[38;2;83;84;85;48;2;0;1;254;2;7m");
99 }
100
101 } /* namespace style */
102 } /* namespace selftests */
103
104 void _initialize_style_selftest ();
105 void
106 _initialize_style_selftest ()
107 {
108 selftests::register_test ("style",
109 selftests::style::run_tests);
110 }