cmdline_cat_test.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. /* All tests need to include test.h for GRUB testing framework. */
  19. #include <grub/test.h>
  20. #include <grub/dl.h>
  21. #include <grub/video.h>
  22. #include <grub/video_fb.h>
  23. #include <grub/command.h>
  24. #include <grub/font.h>
  25. #include <grub/procfs.h>
  26. #include <grub/env.h>
  27. #include <grub/normal.h>
  28. #include <grub/time.h>
  29. GRUB_MOD_LICENSE ("GPLv3+");
  30. static const char testfile[] =
  31. /* Chinese & UTF-8 test from Carbon Jiao. */
  32. "从硬盘的第一主分区启动\n"
  33. "The quick brown fox jumped over the lazy dog.\n"
  34. /* Characters used:
  35. Code point Description UTF-8 encoding
  36. ----------- ------------------------------ --------------
  37. U+263A unfilled smiley face E2 98 BA
  38. U+00A1 inverted exclamation point C2 A1
  39. U+00A3 British pound currency symbol C2 A3
  40. U+03C4 Greek tau CF 84
  41. U+00E4 lowercase letter a with umlaut C3 A4
  42. U+2124 set 'Z' symbol (integers) E2 84 A4
  43. U+2286 subset symbol E2 8A 86
  44. U+211D set 'R' symbol (real numbers) E2 84 9D */
  45. "Unicode test: happy\xE2\x98\xBA \xC2\xA3 5.00"
  46. " \xC2\xA1\xCF\x84\xC3\xA4u! "
  47. " \xE2\x84\xA4\xE2\x8A\x86\xE2\x84\x9D\n"
  48. /* Test handling of bad (non-UTF8) sequences*/
  49. "\x99Hello\xc2Hello\xc1\x81Hello\n";
  50. ;
  51. static char *
  52. get_test_txt (grub_size_t *sz)
  53. {
  54. *sz = grub_strlen (testfile);
  55. return grub_strdup (testfile);
  56. }
  57. struct grub_procfs_entry test_txt =
  58. {
  59. .name = "test.txt",
  60. .get_contents = get_test_txt
  61. };
  62. #define FONT_NAME "Unknown Regular 16"
  63. /* Functional test main method. */
  64. static void
  65. cmdline_cat_test (void)
  66. {
  67. unsigned i;
  68. grub_font_t font;
  69. grub_dl_load ("gfxterm");
  70. grub_errno = GRUB_ERR_NONE;
  71. font = grub_font_get (FONT_NAME);
  72. if (font && grub_strcmp (font->name, FONT_NAME) != 0)
  73. font = 0;
  74. if (!font)
  75. font = grub_font_load ("unicode");
  76. if (!font)
  77. {
  78. grub_test_assert (0, "unicode font not found: %s", grub_errmsg);
  79. return;
  80. }
  81. grub_procfs_register ("test.txt", &test_txt);
  82. for (i = 0; i < GRUB_TEST_VIDEO_SMALL_N_MODES; i++)
  83. {
  84. grub_video_capture_start (&grub_test_video_modes[i],
  85. grub_video_fbstd_colors,
  86. grub_test_video_modes[i].number_of_colors);
  87. grub_terminal_input_fake_sequence ((int [])
  88. { 'c', 'a', 't', ' ',
  89. '(', 'p', 'r', 'o', 'c', ')',
  90. '/', 't', 'e', 's', 't', '.',
  91. 't', 'x', 't', '\n',
  92. GRUB_TERM_NO_KEY,
  93. GRUB_TERM_NO_KEY, '\e'},
  94. 23);
  95. grub_video_checksum ("cmdline_cat");
  96. if (!grub_test_use_gfxterm ())
  97. grub_cmdline_run (1, 0);
  98. grub_test_use_gfxterm_end ();
  99. grub_terminal_input_fake_sequence_end ();
  100. grub_video_checksum_end ();
  101. grub_video_capture_end ();
  102. }
  103. grub_procfs_unregister (&test_txt);
  104. }
  105. /* Register example_test method as a functional test. */
  106. GRUB_FUNCTIONAL_TEST (cmdline_cat_test, cmdline_cat_test);