1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

test: add test for invalid keymap setting

This commit is contained in:
Yu Watanabe 2023-02-02 04:29:43 +09:00
parent 566aba0bca
commit fcf8b80d1d

View File

@ -552,6 +552,102 @@ test_convert() {
assert_not_in "X11 Options:" "$output"
}
test_validate() {
if [[ -z "$(localectl list-keymaps)" ]]; then
echo "No vconsole keymap installed, skipping test."
return
fi
if [[ -z "$(localectl list-x11-keymap-layouts)" ]]; then
echo "No x11 keymap installed, skipping test."
return
fi
backup_keymap
trap restore_keymap RETURN
# clear previous settings
systemctl stop systemd-localed.service
wait_vconsole_setup
rm -f /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
# create invalid configs
cat >/etc/vconsole.conf <<EOF
KEYMAP=foobar
XKBLAYOUT=hogehoge
EOF
# confirm that the invalid settings are not shown
output=$(localectl)
assert_in "VC Keymap: .unset." "$output"
if [[ "$output" =~ "X11 Layout: hogehoge" ]]; then
# Debian/Ubuntu build systemd without xkbcommon.
echo "systemd built without xkbcommon, skipping test."
return
fi
assert_in "X11 Layout: .unset." "$output"
# only update the virtual console keymap
assert_rc 0 localectl --no-convert set-keymap us
output=$(localectl)
assert_in "VC Keymap: us" "$output"
assert_in "X11 Layout: .unset." "$output"
output=$(cat /etc/vconsole.conf)
assert_in "KEYMAP=us" "$output"
assert_not_in "XKBLAYOUT=" "$output"
# clear previous settings
systemctl stop systemd-localed.service
wait_vconsole_setup
rm -f /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
# create invalid configs
cat >/etc/vconsole.conf <<EOF
KEYMAP=foobar
XKBLAYOUT=hogehoge
EOF
# confirm that the invalid settings are not shown
output=$(localectl)
assert_in "VC Keymap: .unset." "$output"
assert_in "X11 Layout: .unset." "$output"
# only update the X11 keyboard layout
assert_rc 0 localectl --no-convert set-x11-keymap us
output=$(localectl)
assert_in "VC Keymap: .unset." "$output"
assert_in "X11 Layout: us" "$output"
output=$(cat /etc/vconsole.conf)
assert_not_in "KEYMAP=" "$output"
assert_in "XKBLAYOUT=us" "$output"
# clear previous settings
systemctl stop systemd-localed.service
wait_vconsole_setup
rm -f /etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard
# create invalid configs
cat >/etc/vconsole.conf <<EOF
KEYMAP=foobar
XKBLAYOUT=hogehoge
EOF
# update the virtual console keymap with conversion
assert_rc 0 localectl set-keymap us
output=$(localectl)
assert_in "VC Keymap: us" "$output"
assert_in "X11 Layout: us" "$output"
output=$(cat /etc/vconsole.conf)
assert_in "KEYMAP=us" "$output"
assert_in "XKBLAYOUT=us" "$output"
}
: >/failed
enable_debug
@ -559,6 +655,7 @@ test_locale
test_vc_keymap
test_x11_keymap
test_convert
test_validate
touch /testok
rm /failed