diff options
-rw-r--r-- | tests/include/testassertions.sh | 19 | ||||
-rwxr-xr-x | tests/xdg-icon-resource/t.icon_system_as_nonroot | 43 | ||||
-rwxr-xr-x | tests/xdg-icon-resource/t.icon_user_install | 40 |
3 files changed, 102 insertions, 0 deletions
diff --git a/tests/include/testassertions.sh b/tests/include/testassertions.sh index 63c663c..9f57e1b 100644 --- a/tests/include/testassertions.sh +++ b/tests/include/testassertions.sh @@ -23,6 +23,25 @@ assert_exit() # execute command (saving output) and check exit code fi } +assert_file_in_path() { + search_dirs=`echo "$2" | tr ':' ' '` + found_files=`find $search_dirs -name "$1" 2>/dev/null` + + if [ -z "$found_files" ] ; then + test_fail "Did not find '$1' in '$2'" + fi +} + +assert_file_not_in_path() { + search_dirs=`echo "$2" | tr ':' ' '` + found_files=`find $search_dirs -name "$1" 2>/dev/null` + + if [ ! -z "$found_files" ] ; then + test_fail "Found '$found_files' in $2" + fi +} + + assert_file() { if [ ! -e "$1" ] ; then test_fail "'$1' does not exist" diff --git a/tests/xdg-icon-resource/t.icon_system_as_nonroot b/tests/xdg-icon-resource/t.icon_system_as_nonroot new file mode 100755 index 0000000..ed74ba8 --- /dev/null +++ b/tests/xdg-icon-resource/t.icon_system_as_nonroot @@ -0,0 +1,43 @@ +#!/bin/bash + +## Include utility functions. +. "$TEST_CODE_DIR/include/testassertions.sh" +. "$TEST_CODE_DIR/include/testdep.sh" +. "$TEST_CODE_DIR/include/testcontrol.sh" + +## Test function +test_icon_system_as_nonroot() { +iconfile="red-32.png" +icondir="$TEST_CODE_DIR/icons" +ICON_PATH="$HOME/.icons:$XDG_DATA_DIRS:/usr/share/pixmaps:$HOME/.local/icons:$XDG_DATA_HOME" + +## Begin the test. +test_start "$FUNCNAME: verify error for --system when run as a normal user" + +# Dependencies section +test_init + +assert_exit 0 test `whoami` != root + +set_no_display +assert_file "$icondir/$iconfile" + +# Verify the test icon is not installed already. +assert_file_not_in_path "$iconfile" "$ICON_PATH" + +# Test steps section +test_procedure + +assert_exit 3 xdg-icon-resource install --system --size 32 "$icondir/$iconfile" +assert_nostdout +assert_stderr + +assert_file_not_in_path "$iconfile" "$ICON_PATH" + +assert_exit 3 xdg-icon-resource uninstall --system --size 32 "$iconfile" +assert_nostdout +assert_stderr + +test_result +} +run_test test_icon_system_as_nonroot diff --git a/tests/xdg-icon-resource/t.icon_user_install b/tests/xdg-icon-resource/t.icon_user_install new file mode 100755 index 0000000..0570519 --- /dev/null +++ b/tests/xdg-icon-resource/t.icon_user_install @@ -0,0 +1,40 @@ +#!/bin/bash + +## Include utility functions. +. "$TEST_CODE_DIR/include/testassertions.sh" +. "$TEST_CODE_DIR/include/testdep.sh" +. "$TEST_CODE_DIR/include/testcontrol.sh" + +## Test function +test_icon_user_install() { +test_start "$FUNCNAME: verify $ICON is installed correctly" + +## Begin the test. +icondir="$TEST_CODE_DIR/icons" +userpath="$HOME/.icons:$HOME/.local:$XDG_DATA_HOME" +systempath="$XDG_DATA_DIRS:/usr/share/pixmaps" + +# Dependencies section +test_init + +set_no_display +assert_file "$icondir/$ICON" + +# Verify the test icon is not installed already. +assert_file_not_in_path "$ICON" "$userpath" + +# Test steps section +test_procedure + +assert_exit 0 xdg-icon-resource install --user --size "$SIZE" "$icondir/$ICON" +assert_nostdout +assert_nostderr + +assert_file_in_path "$ICON" "$userpath" + +assert_exit 0 xdg-icon-resource uninstall --user --size "$SIZE" "$icondir/$ICON" + +test_result +} + +repeat_test test_icon_user_install 2 ICON SIZE 'red-16.png' 'red-22.png' 'red-24.png' 'red-32.png' 'red-48.png' 'red-64.png' 'red-128.png' 16 22 24 32 48 64 128 |