1#!/bin/bash
2
3## Include utility functions.
4. "$XDG_TEST_DIR/include/testassertions.sh"
5. "$XDG_TEST_DIR/include/testcontrol.sh"
6
7## Test function
8test_menu_system_install() {
9## Begin the test.
10test_start "$FUNCNAME: verify a system menu is created correctly"
11
12# Dependencies section
13test_init
14
15USERPATH="${XDG_DATA_DIRS-/usr/local/share:/usr/share}:${XDG_CONFIG_DIRS-/etc/xdg}"
16
17require_root
18set_no_display
19
20# Generate .desktop file
21use_file "$XDG_TEST_DIR/xdg-desktop-menu/data/menu_item_test.desktop" DESKTOP
22use_file "$XDG_TEST_DIR/xdg-desktop-menu/data/menu_item_dummy.desktop" DESKTOP2
23use_file "$XDG_TEST_DIR/xdg-desktop-menu/data/menu_install.directory" DIRECTORY
24
25edit_file "$DIRECTORY" 'XDG UTILS TEST' MENU_NAME "MENU $XDG_TEST_SHORTID"
26
27edit_file "$DESKTOP" 'xdg-test-menu-item-install.tmp' CREATEFILE
28edit_file "$DESKTOP" 'Test Menu Item Install' ITEM_TEXT "TEST $XDG_TEST_SHORTID"
29edit_file "$DESKTOP" '/tmp' WORK_DIR "$XDG_TEST_TMPDIR"
30
31assert_file "$DESKTOP"
32assert_file "$DIRECTORY"
33
34# Verify the test icon is not installed already.
35assert_file_not_in_path "$DESKTOP" "$USERPATH"
36assert_file_not_in_path "$DIRECTORY" "$USERPATH"
37
38# Test steps section
39test_procedure
40
41assert_exit 0 xdg-desktop-menu install --mode system "$DIRECTORY" "$DESKTOP" "$DESKTOP2"
42assert_nostdout
43assert_nostderr
44
45assert_file_in_path "$DESKTOP" "$USERPATH"
46assert_file_in_path "$DESKTOP2" "$USERPATH"
47assert_file_in_path "$DIRECTORY" "$USERPATH"
48
49
50if [ -z "$XDG_TEST_NO_INTERACTIVE" ]; then
51
52assert_interactive "Is there a menu in <main> called '$MENU_NAME'?\n\t(NOTE: If you are using KDE, it may take a few seconds for the menu to appear.)" y
53assert_interactive "Are there exactly 2 items in '<main>/$MENU_NAME' called 'EXTRA ITEM' and '$ITEM_TEXT'?" y
54assert_interactive "Please select the menu item '<main>/$MENU_NAME/$ITEM_TEXT'"
55
56## Double clicking will result in the command 'touch xdg-test-menu-item-install.tmp' to be run
57assert_file "$WORK_DIR/$CREATEFILE"
58
59fi
60
61## Cleanup
62xdg-desktop-menu uninstall --mode system "$DIRECTORY" "$DESKTOP" "$DESKTOP2">/dev/null 2>&1
63
64test_result
65}
66
67run_test test_menu_system_install
68