#!/bin/bash

## Include utility functions.
. "$XDG_TEST_DIR/include/testassertions.sh"
. "$XDG_TEST_DIR/include/testcontrol.sh"

## Test function
test_system_mime_uninstall() {

## Begin the test.
test_start "$FUNCNAME: uninstall system mime type"
test_purpose "Verify that new mime types get removed from the system space correctly" 

# Dependencies section
test_init

require_root
set_no_display

use_file "$XDG_TEST_DIR/xdg-mime/data/testmime.xml" INPUT_FILE
edit_file "$INPUT_FILE" "x-xdg-testpattern" TEST_MIME "x-$XDG_TEST_ID"
assert_file "$INPUT_FILE"
echo "text/$TEST_MIME" >testmime.expected

echo "Some text." >testfile.xdgtest
assert_file testfile.xdgtest

# TODO: query requires a desktop environment
#assert_exit 0 xdg-mime query filetipe testfile.xdgtest
#assert_stdout
#mv out.stout out.save

# Install & verify mime type is installed
assert_exit 0 xdg-mime install --mode system "$INPUT_FILE"

# TODO: query requires a running desktop environment
#assert_exit 0 xdg-mime query filetype $QUERY_FILE
#assert_stdout testmime.expected

# Test steps section
test_procedure

assert_exit 0 xdg-mime uninstall --mode system "$INPUT_FILE"
assert_nostdout
assert_nostderr

## Verify uninstall
#assert_exit 0 xdg-mime query filetype $QUERY_FILE
#assert_stdout out.save

test_result
} 
run_test test_system_mime_uninstall 
