]> git.ipfire.org Git - thirdparty/u-boot.git/blob - lib/efi_selftest/efi_selftest_textoutput.c
efi_selftest: Add international characters test
[thirdparty/u-boot.git] / lib / efi_selftest / efi_selftest_textoutput.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * efi_selftest_textoutput
4 *
5 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
6 *
7 * Test the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL.
8 *
9 * The following services are tested:
10 * OutputString, TestString, SetAttribute.
11 */
12
13 #include <efi_selftest.h>
14
15 /*
16 * Execute unit test.
17 *
18 * Return: EFI_ST_SUCCESS for success
19 */
20 static int execute(void)
21 {
22 size_t foreground;
23 size_t background;
24 size_t attrib;
25 efi_status_t ret;
26 s16 col;
27 u16 cr[] = { 0x0d, 0x00 };
28 u16 lf[] = { 0x0a, 0x00 };
29 u16 brahmi[] = { /* 2 Brahmi letters */
30 0xD804, 0xDC05,
31 0xD804, 0xDC22,
32 0};
33
34 const u16 text[] =
35 u"This should render international characters as described\n"
36 u"U+00D6 \u00D6 - Latin capital letter O with diaresis\n"
37 u"U+00DF \u00DF - Latin small letter sharp s\n"
38 u"U+00E5 \u00E5 - Latin small letter a with ring above\n"
39 u"U+00E9 \u00E9 - Latin small letter e with acute\n"
40 u"U+00F1 \u00F1 - Latin small letter n with tilde\n"
41 u"U+00F6 \u00F6 - Latin small letter o with diaresis\n"
42 u"The following characters will render as '?' with bitmap fonts\n"
43 u"U+00F8 \u00F8 - Latin small letter o with stroke\n"
44 u"U+03AC \u03AC - Greek small letter alpha with tonus\n"
45 u"U+03BB \u03BB - Greek small letter lambda\n"
46 u"U+03C2 \u03C2 - Greek small letter final sigma\n"
47 u"U+1F19 \u1F19 - Greek capital letter epsilon with dasia\n";
48
49 /* SetAttribute */
50 efi_st_printf("\nColor palette\n");
51 for (foreground = 0; foreground < 0x10; ++foreground) {
52 for (background = 0; background < 0x80; background += 0x10) {
53 attrib = foreground | background;
54 con_out->set_attribute(con_out, attrib);
55 efi_st_printf("%p", (void *)attrib);
56 }
57 con_out->set_attribute(con_out, 0);
58 efi_st_printf("\n");
59 }
60 /* TestString */
61 ret = con_out->test_string(con_out,
62 u" !\"#$%&'()*+,-./0-9:;<=>?@A-Z[\\]^_`a-z{|}~\n");
63 if (ret != EFI_ST_SUCCESS) {
64 efi_st_error("TestString failed for ANSI characters\n");
65 return EFI_ST_FAILURE;
66 }
67 /* OutputString */
68 ret = con_out->output_string(con_out,
69 u"Testing cursor column update\n");
70 if (ret != EFI_ST_SUCCESS) {
71 efi_st_error("OutputString failed for ANSI characters");
72 return EFI_ST_FAILURE;
73 }
74 col = con_out->mode->cursor_column;
75 ret = con_out->output_string(con_out, lf);
76 if (ret != EFI_ST_SUCCESS) {
77 efi_st_error("OutputString failed for line feed\n");
78 return EFI_ST_FAILURE;
79 }
80 if (con_out->mode->cursor_column != col) {
81 efi_st_error("Cursor column changed by line feed\n");
82 return EFI_ST_FAILURE;
83 }
84 ret = con_out->output_string(con_out, cr);
85 if (ret != EFI_ST_SUCCESS) {
86 efi_st_error("OutputString failed for carriage return\n");
87 return EFI_ST_FAILURE;
88 }
89 if (con_out->mode->cursor_column) {
90 efi_st_error("Cursor column not 0 at beginning of line\n");
91 return EFI_ST_FAILURE;
92 }
93 ret = con_out->output_string(con_out, u"123");
94 if (ret != EFI_ST_SUCCESS) {
95 efi_st_error("OutputString failed for ANSI characters\n");
96 return EFI_ST_FAILURE;
97 }
98 if (con_out->mode->cursor_column != 3) {
99 efi_st_error("Cursor column not incremented properly\n");
100 return EFI_ST_FAILURE;
101 }
102 ret = con_out->output_string(con_out, u"\b");
103 if (ret != EFI_ST_SUCCESS) {
104 efi_st_error("OutputString failed for backspace\n");
105 return EFI_ST_FAILURE;
106 }
107 if (con_out->mode->cursor_column != 2) {
108 efi_st_error("Cursor column not decremented properly\n");
109 return EFI_ST_FAILURE;
110 }
111 ret = con_out->output_string(con_out, u"\b\b");
112 if (ret != EFI_ST_SUCCESS) {
113 efi_st_error("OutputString failed for backspace\n");
114 return EFI_ST_FAILURE;
115 }
116 if (con_out->mode->cursor_column) {
117 efi_st_error("Cursor column not decremented properly\n");
118 return EFI_ST_FAILURE;
119 }
120 ret = con_out->output_string(con_out, u"\b\b");
121 if (ret != EFI_ST_SUCCESS) {
122 efi_st_error("OutputString failed for backspace\n");
123 return EFI_ST_FAILURE;
124 }
125 if (con_out->mode->cursor_column) {
126 efi_st_error("Cursor column decremented past zero\n");
127 return EFI_ST_FAILURE;
128 }
129 ret = con_out->output_string(con_out, brahmi);
130 if (ret != EFI_ST_SUCCESS) {
131 efi_st_todo("Unicode output not fully supported\n");
132 } else if (con_out->mode->cursor_column != 2) {
133 efi_st_printf("Unicode not handled properly\n");
134 return EFI_ST_FAILURE;
135 }
136 efi_st_printf("\n");
137 ret = con_out->output_string(con_out, text);
138 if (ret != EFI_ST_SUCCESS) {
139 efi_st_error("OutputString failed for international chars\n");
140 return EFI_ST_FAILURE;
141 }
142 efi_st_printf("\n");
143
144 return EFI_ST_SUCCESS;
145 }
146
147 EFI_UNIT_TEST(textoutput) = {
148 .name = "text output",
149 .phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
150 .execute = execute,
151 };