refactored unit tests
[grml-autoconfig.git] / tests / test_bootparameters.sh
diff --git a/tests/test_bootparameters.sh b/tests/test_bootparameters.sh
new file mode 100755 (executable)
index 0000000..7e61c86
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/zsh
+
+
+test_checkbootparam() {
+    CMDLINE='foo=dingens bar foobar=blub'
+
+    checkbootparam foobar
+    retval=$?
+    assertEquals 'wrong retval for bootparam foobar' 0 ${retval}
+
+    checkbootparam bar
+    retval=$?
+    assertEquals 'wrong retval for bootparam bar' 0 ${retval}
+
+    checkbootparam foo
+    retval=$?
+    assertEquals 'wrong retval for bootparam foo' 0 ${retval}
+
+    checkbootparam dingens
+    retval=$?
+    assertEquals 'wrong retval for non-existing bootparam dingens' 1 ${retval}
+
+    checkbootparam oops
+    retval=$?
+    assertEquals 'wrong retval for non-existing bootparam oops' 1 ${retval}
+}
+
+test_getbootparam() {
+    CMDLINE='test=dingens tester foo=dingens foobar=blub'
+
+    value=$(getbootparam foobar)
+    retval=$?
+    assertEquals 'unexpected value for botparam foobar' 'blub' ${value}
+    assertEquals 'unexpected retval' '0' ${retval}
+
+    value=$(getbootparam foo)
+    retval=$?
+    assertEquals 'unexpected value for bootparam foo' 'dingens' ${value}
+    assertEquals 'unexpected retval' 0 ${retval}
+
+    value=$(getbootparam test)
+    retval=$?
+    assertEquals 'unexpected value for bootparam test' 'dingens' ${value}
+    assertEquals 'unexpected retval' 0 ${retval}
+
+    value=$(getbootparam tester)
+    retval=$?
+    assertTrue 'expected empty string' "[ -z ${value} ]"
+    assertEquals 'unexpected retval' 1 ${retval}
+}
+
+
+. ./common_tests $0