core: use GRUB_TERM_ definitions when handling term characters
[grub.git] / grub-core / tests / cmdline_cat_test.c
1 /*
2  *  GRUB  --  GRand Unified Bootloader
3  *  Copyright (C) 2013 Free Software Foundation, Inc.
4  *
5  *  GRUB is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  GRUB is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 /* All tests need to include test.h for GRUB testing framework.  */
20 #include <grub/test.h>
21 #include <grub/dl.h>
22 #include <grub/video.h>
23 #include <grub/video_fb.h>
24 #include <grub/command.h>
25 #include <grub/font.h>
26 #include <grub/procfs.h>
27 #include <grub/env.h>
28 #include <grub/normal.h>
29 #include <grub/time.h>
30
31 GRUB_MOD_LICENSE ("GPLv3+");
32
33
34 static const char testfile[] =
35   /* Chinese & UTF-8 test from Carbon Jiao. */
36   "从硬盘的第一主分区启动\n"
37   "The quick brown fox jumped over the lazy dog.\n"
38   /* Characters used:
39      Code point  Description                    UTF-8 encoding
40      ----------- ------------------------------ --------------
41      U+263A      unfilled smiley face           E2 98 BA
42      U+00A1      inverted exclamation point     C2 A1
43      U+00A3      British pound currency symbol  C2 A3
44      U+03C4      Greek tau                      CF 84
45      U+00E4      lowercase letter a with umlaut C3 A4
46      U+2124      set 'Z' symbol (integers)      E2 84 A4
47      U+2286      subset symbol                  E2 8A 86
48      U+211D      set 'R' symbol (real numbers)  E2 84 9D  */
49   "Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00"
50   " \xC2\xA1\xCF\x84\xC3\xA4u! "
51   " \xE2\x84\xA4\xE2\x8A\x86\xE2\x84\x9D\n"
52   /* Test handling of bad (non-UTF8) sequences*/
53   "\x99Hello\xc2Hello\xc1\x81Hello\n";
54 ;
55
56 static char *
57 get_test_txt (grub_size_t *sz)
58 {
59   *sz = grub_strlen (testfile);
60   return grub_strdup (testfile);
61 }
62
63 struct grub_procfs_entry test_txt = 
64 {
65   .name = "test.txt",
66   .get_contents = get_test_txt
67 };
68
69 #define FONT_NAME "Unknown Regular 16"
70
71 /* Functional test main method.  */
72 static void
73 cmdline_cat_test (void)
74 {
75   unsigned i;
76   grub_font_t font;
77
78   grub_dl_load ("gfxterm");
79   grub_errno = GRUB_ERR_NONE;
80
81   font = grub_font_get (FONT_NAME);
82   if (font && grub_strcmp (font->name, FONT_NAME) != 0)
83     font = 0;
84   if (!font)
85     font = grub_font_load ("unicode");
86
87   if (!font)
88     {
89       grub_test_assert (0, "unicode font not found: %s", grub_errmsg);
90       return;
91     }
92
93   grub_procfs_register ("test.txt", &test_txt);
94   
95   for (i = 0; i < GRUB_TEST_VIDEO_SMALL_N_MODES; i++)
96     {
97       grub_video_capture_start (&grub_test_video_modes[i],
98                                 grub_video_fbstd_colors,
99                                 grub_test_video_modes[i].number_of_colors);
100       grub_terminal_input_fake_sequence ((int []) 
101                                          {  'c', 'a', 't', ' ', 
102                                              '(', 'p', 'r', 'o', 'c', ')',
103                                              '/', 't', 'e', 's', 't', '.',
104                                              't', 'x', 't', '\n',
105                                              GRUB_TERM_NO_KEY,
106                                              GRUB_TERM_NO_KEY, GRUB_TERM_ESC},
107                                          23);
108
109       grub_video_checksum ("cmdline_cat");
110
111       if (!grub_test_use_gfxterm ())
112         grub_cmdline_run (1, 0);
113
114       grub_test_use_gfxterm_end ();
115
116       grub_terminal_input_fake_sequence_end ();
117       grub_video_checksum_end ();
118       grub_video_capture_end ();
119     }
120
121   grub_procfs_unregister (&test_txt);
122 }
123
124 /* Register example_test method as a functional test.  */
125 GRUB_FUNCTIONAL_TEST (cmdline_cat_test, cmdline_cat_test);