tests: Add a test case for the new swtpm_setup option

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9fdc2ec..5e0e191 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -42,7 +42,8 @@
 	test_print_capabilities \
 	test_print_states \
 	test_swtpm_setup_overwrite \
-	test_swtpm_setup_file_backend
+	test_swtpm_setup_file_backend \
+	test_swtpm_setup_misc
 
 TESTS += \
 	test_tpm2_ctrlchannel2 \
diff --git a/tests/test_swtpm_setup_misc b/tests/test_swtpm_setup_misc
new file mode 100755
index 0000000..9b53dbc
--- /dev/null
+++ b/tests/test_swtpm_setup_misc
@@ -0,0 +1,79 @@
+#!/usr/bin/env bash
+
+# For the license, see the LICENSE file in the root directory.
+
+if [ "$(id -u)" -eq 0 ]; then
+	echo "Not running this test as root."
+	exit 77
+fi
+
+ROOT=${abs_top_builddir:-$(dirname "$0")/..}
+TESTDIR=${abs_top_testdir:-$(dirname "$0")}
+SRCDIR=${abs_top_srcdir:-$(dirname "$0")/..}
+
+source ${TESTDIR}/common
+
+trap "cleanup" SIGTERM EXIT
+
+function cleanup()
+{
+	rm -rf ${workdir}
+}
+
+workdir=$(mktemp -d)
+
+FILES="swtpm-localca.conf swtpm-localca.options swtpm_setup.conf"
+
+XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
+	--create-config-files 1>/dev/null
+
+if [ $? -ne 0 ]; then
+	echo "Error: Could not created config files (without parameters)"
+	exit 1
+fi
+for f in ${FILES}; do
+	if ! [ -f "${workdir}/${f}" ]; then
+		echo "Error: File ${workedir}/${f} was not created"
+		exit 1
+	fi
+done
+if ! [ -d "${workdir}/var/lib/swtpm-localca" ]; then
+	echo "Error: Directory var/lib/swtpm-localca was not created"
+	exit 1
+fi
+
+XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
+	--create-config-files skip-if-exist 1>/dev/null
+
+if [ $? -ne 0 ]; then
+	echo "Error: skip-if-exists should have exit'ed with 0."
+	exit 1
+fi
+
+echo "Test 1: Ok"
+cleanup
+
+workdir=$(mktemp -d)
+
+XDG_CONFIG_HOME="${workdir}" ${SWTPM_SETUP} \
+	--create-config-files skip-if-exist 1>/dev/null
+
+if [ $? -ne 0 ]; then
+	echo "Error: skip-if-exists should have exit'ed with 0."
+	exit 1
+fi
+for f in ${FILES}; do
+	if ! [ -f "${workdir}/${f}" ]; then
+		echo "Error: File ${workedir}/${f} was not created"
+		exit 1
+	fi
+done
+if ! [ -d "${workdir}/var/lib/swtpm-localca" ]; then
+	echo "Error: Directory var/lib/swtpm-localca was not created"
+	exit 1
+fi
+
+echo "Test 2: Ok"
+cleanup
+
+exit 0