vaseboot/VasEBoot-core/tests/gfxterm_menu.c

181 lines
5.3 KiB
C

/*
* VasEBoot -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* VasEBoot is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VasEBoot is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VasEBoot. If not, see <http://www.gnu.org/licenses/>.
*/
/* All tests need to include test.h for VasEBoot testing framework. */
#include <VasEBoot/test.h>
#include <VasEBoot/dl.h>
#include <VasEBoot/video.h>
#include <VasEBoot/video_fb.h>
#include <VasEBoot/command.h>
#include <VasEBoot/font.h>
#include <VasEBoot/procfs.h>
#include <VasEBoot/env.h>
#include <VasEBoot/normal.h>
#include <VasEBoot/time.h>
VasEBoot_MOD_LICENSE ("GPLv3+");
static const char testfile[] =
"menuentry \"test\" {\n"
"\ttrue\n"
"}\n"
"menuentry \"s̛ ơ t o̒ s̒ u o̕̚ 8.04 m̂ñåh̊z̆x̣ a̡ b̢g̢ u᷎ô᷎ ô᷎ O̷ a̖̣ ȃ̐\" --class ubuntu --class linux --class os {\n"
"\ttrue\n"
"}\n"
"menuentry \" הַרמלל(טוֹבָ) לֶךְ\" --class opensuse --class linux --class os {\n"
"\ttrue\n"
"}\n"
"menuentry \"الرملل جِداً لِكَ\" --class gentoo --class linux --class os {\n"
"\ttrue\n"
"}\n"
"menuentry \"ὑπόγυͅον\" --class kubuntu --class linux --class os {\n"
"\ttrue\n"
"}\n"
"menuentry \"سَّ نِّ نَّ نٌّ نّْ\" --class linuxmint --class linux --class os {\n"
"\ttrue\n"
"}\n"
/* Chinese & UTF-8 test from Carbon Jiao. */
"menuentry \"从硬盘的第一主分区启动\" --class \"windows xp\" --class windows --class os {\n"
"\ttrue\n"
"}\n"
"timeout=3\n";
static char *
get_test_cfg (VasEBoot_size_t *sz)
{
*sz = VasEBoot_strlen (testfile);
return VasEBoot_strdup (testfile);
}
struct VasEBoot_procfs_entry test_cfg =
{
.name = "test.cfg",
.get_contents = get_test_cfg
};
struct
{
const char *name;
const char *var;
const char *val;
} tests[] =
{
{ "gfxterm_menu", NULL, NULL },
{ "gfxmenu", "theme", "starfield/theme.txt" },
{ "gfxterm_ar", "lang", "en@arabic" },
{ "gfxterm_cyr", "lang", "en@cyrillic" },
{ "gfxterm_heb", "lang", "en@hebrew" },
{ "gfxterm_gre", "lang", "en@greek" },
{ "gfxterm_ru", "lang", "ru" },
{ "gfxterm_fr", "lang", "fr" },
{ "gfxterm_quot", "lang", "en@quot" },
{ "gfxterm_piglatin", "lang", "en@piglatin" },
{ "gfxterm_ch", "lang", "de_CH" },
{ "gfxterm_red", "menu_color_normal", "red/blue" },
{ "gfxterm_high", "menu_color_highlight", "blue/red" },
};
#define FONT_NAME "Unknown Regular 16"
/* Functional test main method. */
static void
gfxterm_menu (void)
{
unsigned i, j;
VasEBoot_font_t font;
VasEBoot_dl_load ("png");
VasEBoot_dl_load ("gettext");
VasEBoot_dl_load ("gfxterm");
VasEBoot_errno = VasEBoot_ERR_NONE;
VasEBoot_dl_load ("gfxmenu");
font = VasEBoot_font_get (FONT_NAME);
if (font && VasEBoot_strcmp (font->name, FONT_NAME) != 0)
font = 0;
if (!font)
font = VasEBoot_font_load ("unicode");
if (!font)
{
VasEBoot_test_assert (0, "unicode font not found: %s", VasEBoot_errmsg);
return;
}
VasEBoot_procfs_register ("test.cfg", &test_cfg);
for (j = 0; j < ARRAY_SIZE (tests); j++)
for (i = 0; i < VasEBoot_TEST_VIDEO_SMALL_N_MODES; i++)
{
VasEBoot_uint64_t start;
#if defined (VasEBoot_MACHINE_MIPS_QEMU_MIPS) || defined (VasEBoot_MACHINE_IEEE1275)
if (VasEBoot_test_video_modes[i].width > 1024)
continue;
if (VasEBoot_strcmp (tests[j].name, "gfxmenu") == 0
&& VasEBoot_test_video_modes[i].width > 800)
continue;
#endif
start = VasEBoot_get_time_ms ();
VasEBoot_video_capture_start (&VasEBoot_test_video_modes[i],
VasEBoot_video_fbstd_colors,
VasEBoot_test_video_modes[i].number_of_colors);
if (VasEBoot_errno)
{
VasEBoot_test_assert (0, "can't start capture: %d: %s",
VasEBoot_errno, VasEBoot_errmsg);
return;
}
VasEBoot_terminal_input_fake_sequence ((int []) { -1, -1, -1, VasEBoot_TERM_KEY_DOWN, -1, 'e',
-1, VasEBoot_TERM_KEY_RIGHT, -1, 'x', -1, '\e', -1, '\e' }, 14);
VasEBoot_video_checksum (tests[j].name);
if (VasEBoot_test_use_gfxterm ())
return;
VasEBoot_env_context_open ();
if (tests[j].var)
VasEBoot_env_set (tests[j].var, tests[j].val);
VasEBoot_normal_execute ("(proc)/test.cfg", 1, 0);
VasEBoot_env_context_close ();
VasEBoot_test_use_gfxterm_end ();
VasEBoot_terminal_input_fake_sequence_end ();
VasEBoot_video_checksum_end ();
VasEBoot_video_capture_end ();
if (tests[j].var)
VasEBoot_env_unset (tests[j].var);
VasEBoot_printf ("%s %dx%dx%s done %lld ms\n", tests[j].name,
VasEBoot_test_video_modes[i].width,
VasEBoot_test_video_modes[i].height,
VasEBoot_video_checksum_get_modename (), (long long) (VasEBoot_get_time_ms () - start));
}
VasEBoot_procfs_unregister (&test_cfg);
}
/* Register example_test method as a functional test. */
VasEBoot_FUNCTIONAL_TEST (gfxterm_menu, gfxterm_menu);