]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: add test for invalid keymap setting 26294/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 1 Feb 2023 19:29:43 +0000 (04:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 25 Mar 2023 06:36:53 +0000 (15:36 +0900)
test/units/testsuite-73.sh

index 4f33cab8482feb9be9aa04cd501b8fe195807cb6..2aef7c779a4a55f0923407fe5c41ae787e5fe0a2 100755 (executable)
@@ -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