From 2465556567d62aa4a076c381397a86f80d46ff53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Boraty=C5=84ski?= Date: Sun, 10 Apr 2016 16:32:21 +0200 Subject: [PATCH] features/testcases (#161) * Implemented equal test case. * Implemented not-equal test case. * Implemented greater-than test case. * Implemented greater-or-equal test case. * Implemented less-than test case. * Implemented less-or-eqal test case. Added some improvements and unifications. * Added more unifications. * Added more logs. * Unified not-equal test. --- include/functions | 160 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/include/functions b/include/functions index 4f595e53..8ec84597 100644 --- a/include/functions +++ b/include/functions @@ -68,6 +68,13 @@ # TestValue Evaluate a value in a string or key # ViewCategories Display tests categories # WaitForKeypress Wait for user to press a key to continue + +# TestCase_Equal Test case for checking if value is equal to something +# TestCase_NotEqual Test case for checking if value is not equal to something +# TestCase_GreaterThan Test case for checking if value is greater than something +# TestCase_GreaterOrEqual Test case for checking if value is greater or equal to something +# TestCase_LessThan Test case for checking if value is less than something +# TestCase_LessOrEqual Test case for checking if value is less or equal to something # ################################################################################# @@ -148,6 +155,159 @@ fi } + ################################################################################ + # Name : TestCase_Equal() + # Description : Test case for checking if value whether value is equal to value + # Returns : (0 - SUCCESS; 1 - MEDIUM-VALUED; 2 - FAIL) + ################################################################################ + + TestCase_Equal() + { + local RETVAL=2 + + if [ "$#" -lt "2" ]; then + ReportException "${TEST_NO}" "Error in function call to ${FUNCNAME}" + else + LogText "${FUNCNAME}: checking value for application ${APP}" + LogText "${FUNCNAME}: ${OPTION} is set to ${1}" + + + LogText "${FUNCNAME}: check if ${1} is equal to ${2}" + + if [ "$1" == "$2" ]; then + LogText "${FUNCNAME}: ${1} is equal to ${2}" + RETVAL=0 + fi + + if ! [ -z ${3+x} ]; then + LogText "${FUNCNAME}: ${1} is equal to ${3}" + if [ "$2" == "$3" ]; then + LogText "${FUNCNAME}: ${OPTION} is equal to ${3}" + RETVAL=1 + fi + fi + fi + return ${RETVAL} + } + + ################################################################################ + # Name : TestCase_ValueNotEqual() + # Description : Test case for checking if value is not equal to something + # Returns : (0 - SUCCESS; 1 - FAIL) + ################################################################################ + TestCase_NotEqual() + { + local RETVAL=1 + if [ "$#" -ne "2" ]; then + ReportException "${TEST_NO}" "Error in function call to ${FUNCNAME}" + else + LogText "${FUNCNAME}: checking value for application ${APP}" + LogText "${FUNCNAME}: ${OPTION} is set to ${1}" + + if [ "$1" != "$2" ]; then + LogText "${FUNCNAME}: ${1} is not equal to ${2}" + RETVAL=0 + else + LogText "${FUNCNAME}: ${1} is equal to ${2}" + fi + fi + + return ${RETVAL} + } + + ################################################################################ + # Name : TestCase_GreaterThan() + # Description : Test case for checking if value is greater than something + # Returns : (0 - SUCCESS; 1 - FAIL) + ################################################################################ + TestCase_GreaterThan() + { + local RETVAL=1 + if [ "$#" -ne "2" ]; then + ReportException "${TEST_NO}" "Error in function call to ${FUNCNAME}" + else + LogText "${FUNCNAME}: checking value for application ${APP}" + LogText "${FUNCNAME}: ${OPTION} is set to ${1}" + + LogText "${FUNCNAME}: checking if ${1} is greater than ${2}" + if [ "$1" > "$2" ]; then + LogText "${FUNCNAME}: ${1} is greater than ${2}" + RETVAL=0 + else + LogText "${FUNCNAME}: ${1} is not greater than ${2}" + fi + fi + + return ${RETVAL} + } + + ################################################################################ + # Name : TestCase_GreaterOrEqual() + # Description : Test case for checking if value is greater than something + # Returns : (0 - SUCCESS; 1 - FAIL) + ################################################################################ + TestCase_GreaterOrEqual() + { + local RETVAL=1 + if [ "$#" -ne "2" ]; then + ReportException "${TEST_NO}" "Error in function call to ${FUNCNAME}" + else + LogText "${FUNCNAME}: checking value for application ${APP}" + LogText "${FUNCNAME}: ${OPTION} is set to ${1}" + + LogText "${FUNCNAME}: checking if ${1} is greater or equal ${2}" + if [ TestCase_Equal "${1}" "${2}" ] || [ TestCase_GreaterThan "${1}" "${2}" ]; then + RETVAL=0 + fi + fi + return ${RETVAL} + } + ################################################################################ + # Name : TestCase_LessThan() + # Description : Test case for checking if value is greater than something + # Returns : (0 - SUCCESS; 1 - FAIL) + ################################################################################ + TestCase_LessThan() + { + local RETVAL=1 + if [ "$#" -ne "2" ]; then + ReportException "${TEST_NO}" "Error in function call to TestCase_GreaterOrEqual" + else + LogText "${FUNCNAME}: checking value for application ${APP}" + LogText "${FUNCNAME}: ${OPTION} is set to ${1}" + + LogText "${FUNCNAME}: checking if ${1} is less than ${2}" + if ! [ TestCase_GreaterOrEqual "${1}" "${2}" ]; then + LogText "${FUNCNAME}: ${1} is less than ${2}" + RETVAL=0 + fi + fi + return ${RETVAL} + } + + ################################################################################ + # Name : TestCase_LessOrEqual() + # Description : Test case for checking if value is less or equal something + # Returns : (0 - SUCCESS; 1 - FAIL) + ################################################################################ + TestCase_LessOrEqual() + { + local RETVAL=1 + if [ "$#" -ne "2" ]; then + ReportException "${TEST_NO}" "Error in function call to ${FUNCNAME}" + else + LogText "${FUNCNAME}: checking value for application ${APP}" + LogText "${FUNCNAME}: ${OPTION} is set to ${1}" + + LogText "${FUNCNAME}: checking if ${1} is less or equal ${2}" + if [ TestCase_Equal "${1}" "${2}" ] || [ TestCase_LessThan "${1}" "${2}" ]; then + LogText "${FUNCNAME}: ${1} is less than ${2}" + RETVAL=0 + fi + fi + return ${RETVAL} + } + # Check updates CheckUpdates() {