# testframework _ISTEST = 1 _TRUE = (0 ! 1) _FALSE = (0 = 1) !! Set up the date, the player character basic attributes, etc. if $ARGS[0] = 'testsetup': daystart = 0 month = 8 $month = 'August' day = 26 week = 5 hour = 9 minut = 30 birthyear = 1999 birthmonth = 4 birthday = 1 pcs_haircol = 1 pcs_eyesize = 2 pcs_lip = 1 pcs_lashes = 1 !! Body pcs_hgt = 170 pcs_teeth = 0 pcs_butt = 8 pcs_skin = 500 !! Stats pcs_stren = 35 strenbuf = 10 pcs_agil = 35 agilbuf = 10 pcs_vital = 35 vitalbuf = 10 pcs_intel = 35 pcs_sprt = 35 pcs_react = 35 pcs_chrsm = 35 pcs_prcptn = 35 pcs_magik = 0 $pcs_firstname = "Svetlana" $pcs_lastname = "Lebedev" $pcs_nickname = "Sveta" end !! Asserts that the two strings passed in $ARGS[1] and $ARGS[2] are equal. if $ARGS[0] = 'assertEqualsString': RESULT = $ARGS[1] = $ARGS[2] end !! Asserts that the two numbers passed in ARGS[1] and ARGS[2] are equal. if $ARGS[0] = 'assertEqualsNumber': RESULT = ARGS[1] = ARGS[2] end !! Asserts that the two Arrays passed in $ARGS[1] and $ARGS[2] are equal. !! The two parameters are the Array variable names !! $ARGS[1]: the first array !! $ARGS[2]: the second array !! ARGS[3]: strict order (true / false: 1/0) if $ARGS[0] = 'assertEqualsStringArray': RESULT = 1 if ARRSIZE($ARGS[1]) ! ARRSIZE($ARGS[2]): RESULT = 0 else: $array_1 = 0 $array_2 = 0 elements = ARRSIZE($ARGS[1]) COPYARR '$array_1', $ARGS[1] COPYARR '$array_2', $ARGS[2] index = 0 :array_compare_loop pos = ARRPOS('$array_2', $array_1[index]) if pos = -1: RESULT = 0 elseif ARGS[3] = 1 and pos ! index: RESULT = 0 end index += 1 if index < elements and RESULT ! 0: jump ':array_compare_loop' end end !! $ARGS[1]: name of the array !! ARGS[2]: the value we are looking for if $ARGS[0] = 'assertNumberIsInArray': if $MID($ARGS[1], 1, 1) = '$': RESULT = 0 $ACTUAL_MESSAGE = "'<<$ARGS[1]>>' is a string type array, use 'assertStringIsInArray' not 'assertNumberIsInArray'." elseif $ARGS[2] ! '' and ISNUM($ARGS[2]) = 0: RESULT = 0 $ACTUAL_MESSAGE = "'<<$ARGS[1]>> is a numeric type array but <<$ARGS[2]>> is not a number." else: index = ARRPOS($ARGS[1], ARGS[2]) if index ! -1: $ACTUAL_MESSAGE = "<> was found in array '<<$ARGS[1]>> at index <>." RESULT = index ! -1 else $ACTUAL_MESSAGE = "<> was not found in array '<<$ARGS[1]>>." RESULT = 0 end end end if $ARGS[0] = 'addTestResult': $testResults[testCount] = "<<$TESTNAME>>; gs '<<$LOCATIONNAME>>', '<<$FUNCTIONNAME>>'" + iif($ARGUMENTS ! '', ', <<$ARGUMENTS>>', '') + "; <<$EXPECTED_MESSAGE>>; <<$ACTUAL_MESSAGE>>; " if TESTRESULT ! 0: $testResults[testCount] += 'S' testPassed += 1 else $testResults[testCount] += 'F' testFailed += 1 end testCount += 1 end if $ARGS[0] = 'displayTestResults': $ROW[0] = '

Test results for TestSuite: <<$_TESTSUITE>>

' $ROW[1] = ' Test built: <<$_TESTBUILDTIME>>' if _TESTSAVED ! 0: $ROW[2] = '

This is a saved test result, not a new run.

' else $ROW[2] = '

New test run results

' end $ROW[5] = ' Number of tests executed: <>' $ROW[6] = ' Number of test passed : <>' $ROW[7] = ' Number of test failed : <>' $ROW[8] = '' $ROW[9] = '' size = ARRSIZE('testResults') rowindex = ARRSIZE('ROW') resultindex = 0 :testresultprocessloop $ROW[rowindex] = '' rowindex += 1 resultindex += 1 if resultindex < size: jump 'testresultprocessloop' $ROW[rowindex] = '
Test NameCall (location, function)ExpectedActualResult
' + $REPLACE($testResults[resultindex], '; ', '') + '
' size = ARRSIZE('ROW') index = 0 :testresultdisplayloop '<<$ROW[index]>>' index += 1 if index < size: jump 'testresultdisplayloop' '
' *nl end if $ARGS[0] = 'saveTestResults': gs 'testframework', 'cleanUpTestData' _TESTSAVED = 1 savegame '<<$_TESTSUITE>>-Results-<<$_TESTFILETIME>>.test' end if $ARGS[0] = 'testDefaultCleanup': killvar 'ARGUMENTS' killvar 'EXPECTED' killvar 'EXPECTED_MESSAGE' killvar 'ACTUAL' killvar 'ACTUAL_MESSAGE' killvar 'FUNCTIONNAME' killvar 'TESTRESULT' killvar 'daystart' killvar 'month' killvar '$month' killvar 'day' killvar 'week' killvar 'hour' killvar 'minut' killvar 'birthyear' killvar 'birthmonth' killvar 'birthday' killvar 'pcs_haircol' killvar 'pcs_eyesize' killvar 'pcs_lip' killvar 'pcs_lashes' !! Body killvar 'pcs_hgt' killvar 'pcs_teeth' killvar 'pcs_butt' killvar 'pcs_skin' !! Stats killvar 'pcs_stren' killvar 'strenbuf' killvar 'pcs_agil' killvar 'agilbuf' killvar 'pcs_vital' killvar 'vitalbuf' killvar 'pcs_intel' killvar 'pcs_sprt' killvar 'pcs_react' killvar 'pcs_chrsm' killvar 'pcs_prcptn' killvar 'pcs_magik' killvar 'pcs_firstname' killvar 'pcs_lastname' killvar 'pcs_nickname' end --- testframework --------------------------------