Line data Source code
1 : /* Selftests for text art.
2 : Copyright (C) 2023-2026 Free Software Foundation, Inc.
3 : Contributed by David Malcolm <dmalcolm@redhat.com>.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 : #include "config.h"
22 : #define INCLUDE_VECTOR
23 : #include "system.h"
24 : #include "coretypes.h"
25 : #include "selftest.h"
26 : #include "pretty-print.h"
27 : #include "text-art/selftests.h"
28 : #include "text-art/canvas.h"
29 :
30 : #if CHECKING_P
31 :
32 : /* Run all tests, aborting if any fail. */
33 :
34 : void
35 4 : selftest::text_art_tests ()
36 : {
37 4 : text_art_style_cc_tests ();
38 4 : text_art_styled_string_cc_tests ();
39 :
40 4 : text_art_box_drawing_cc_tests ();
41 4 : text_art_canvas_cc_tests ();
42 4 : text_art_ruler_cc_tests ();
43 4 : text_art_table_cc_tests ();
44 4 : text_art_widget_cc_tests ();
45 4 : text_art_tree_widget_cc_tests ();
46 4 : }
47 :
48 : /* Implementation detail of ASSERT_CANVAS_STREQ. */
49 :
50 : void
51 256 : selftest::assert_canvas_streq (const location &loc,
52 : const text_art::canvas &canvas,
53 : pretty_printer *pp,
54 : const char *expected_str)
55 : {
56 256 : canvas.print_to_pp (pp);
57 256 : if (0)
58 : fprintf (stderr, "%s\n", pp_formatted_text (pp));
59 256 : ASSERT_STREQ_AT (loc, pp_formatted_text (pp), expected_str);
60 256 : }
61 :
62 : /* Implementation detail of ASSERT_CANVAS_STREQ. */
63 :
64 : void
65 248 : selftest::assert_canvas_streq (const location &loc,
66 : const text_art::canvas &canvas,
67 : bool styled,
68 : const char *expected_str)
69 : {
70 248 : pretty_printer pp;
71 248 : if (styled)
72 : {
73 92 : pp_show_color (&pp) = true;
74 92 : pp.set_url_format (URL_FORMAT_DEFAULT);
75 : }
76 248 : assert_canvas_streq (loc, canvas, &pp, expected_str);
77 248 : }
78 :
79 : #endif /* #if CHECKING_P */
|