1
0

testframework.qsrc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. # testframework
  2. _ISTEST = 1
  3. _TRUE = (0 ! 1)
  4. _FALSE = (0 = 1)
  5. !! Set up the date, the player character basic attributes, etc.
  6. if $ARGS[0] = 'testsetup':
  7. daystart = 0
  8. month = 8
  9. $month = 'August'
  10. day = 26
  11. week = 5
  12. hour = 9
  13. minut = 30
  14. birthyear = 1999
  15. birthmonth = 4
  16. birthday = 1
  17. pcs_haircol = 1
  18. pcs_eyesize = 2
  19. pcs_lip = 1
  20. pcs_lashes = 1
  21. !! Body
  22. pcs_hgt = 170
  23. pcs_teeth = 0
  24. pcs_butt = 8
  25. pcs_skin = 500
  26. !! Stats
  27. pcs_stren = 35
  28. strenbuf = 10
  29. pcs_agil = 35
  30. agilbuf = 10
  31. pcs_vital = 35
  32. vitalbuf = 10
  33. pcs_intel = 35
  34. pcs_sprt = 35
  35. pcs_react = 35
  36. pcs_chrsm = 35
  37. pcs_prcptn = 35
  38. pcs_magik = 0
  39. $pcs_firstname = "Svetlana"
  40. $pcs_lastname = "Lebedev"
  41. $pcs_nickname = "Sveta"
  42. end
  43. !! Asserts that the two strings passed in $ARGS[1] and $ARGS[2] are equal.
  44. if $ARGS[0] = 'assertEqualsString':
  45. RESULT = $ARGS[1] = $ARGS[2]
  46. end
  47. !! Asserts that the two numbers passed in ARGS[1] and ARGS[2] are equal.
  48. if $ARGS[0] = 'assertEqualsNumber':
  49. RESULT = ARGS[1] = ARGS[2]
  50. end
  51. !! Asserts that the two Arrays passed in $ARGS[1] and $ARGS[2] are equal.
  52. !! The two parameters are the Array variable names
  53. !! $ARGS[1]: the first array
  54. !! $ARGS[2]: the second array
  55. !! ARGS[3]: strict order (true / false: 1/0)
  56. if $ARGS[0] = 'assertEqualsStringArray':
  57. RESULT = 1
  58. if ARRSIZE($ARGS[1]) ! ARRSIZE($ARGS[2]):
  59. RESULT = 0
  60. else:
  61. $array_1 = 0
  62. $array_2 = 0
  63. elements = ARRSIZE($ARGS[1])
  64. COPYARR '$array_1', $ARGS[1]
  65. COPYARR '$array_2', $ARGS[2]
  66. index = 0
  67. :array_compare_loop
  68. pos = ARRPOS('$array_2', $array_1[index])
  69. if pos = -1:
  70. RESULT = 0
  71. elseif ARGS[3] = 1 and pos ! index:
  72. RESULT = 0
  73. end
  74. index += 1
  75. if index < elements and RESULT ! 0: jump ':array_compare_loop'
  76. end
  77. end
  78. !! $ARGS[1]: name of the array
  79. !! ARGS[2]: the value we are looking for
  80. if $ARGS[0] = 'assertNumberIsInArray':
  81. if $MID($ARGS[1], 1, 1) = '$':
  82. RESULT = 0
  83. $ACTUAL_MESSAGE = "'<<$ARGS[1]>>' is a string type array, use 'assertStringIsInArray' not 'assertNumberIsInArray'."
  84. elseif $ARGS[2] ! '' and ISNUM($ARGS[2]) = 0:
  85. RESULT = 0
  86. $ACTUAL_MESSAGE = "'<<$ARGS[1]>> is a numeric type array but <<$ARGS[2]>> is not a number."
  87. else:
  88. index = ARRPOS($ARGS[1], ARGS[2])
  89. if index ! -1:
  90. $ACTUAL_MESSAGE = "<<ARGS[2]>> was found in array '<<$ARGS[1]>> at index <<index>>."
  91. RESULT = index ! -1
  92. else
  93. $ACTUAL_MESSAGE = "<<ARGS[2]>> was not found in array '<<$ARGS[1]>>."
  94. RESULT = 0
  95. end
  96. end
  97. end
  98. if $ARGS[0] = 'addTestResult':
  99. $testResults[testCount] = "<<$TESTNAME>>; gs '<<$LOCATIONNAME>>', '<<$FUNCTIONNAME>>'" + iif($ARGUMENTS ! '', ', <<$ARGUMENTS>>', '') + "; <<$EXPECTED_MESSAGE>>; <<$ACTUAL_MESSAGE>>; "
  100. if TESTRESULT ! 0:
  101. $testResults[testCount] += '<font style="color: green;"><b>S</b></font>'
  102. testPassed += 1
  103. else
  104. $testResults[testCount] += '<font style="color: red;"><b>F</b></font>'
  105. testFailed += 1
  106. end
  107. testCount += 1
  108. end
  109. if $ARGS[0] = 'displayTestResults':
  110. $ROW[0] = '<h1>Test results for TestSuite: <<$_TESTSUITE>></h1>'
  111. $ROW[1] = ' <b>Test built</b>: <<$_TESTBUILDTIME>>'
  112. if _TESTSAVED ! 0:
  113. $ROW[2] = ' <h3>This is a saved test result, not a new run.</h3>'
  114. else
  115. $ROW[2] = ' <h3>New test run results</h3>'
  116. end
  117. $ROW[5] = ' <b>Number of tests executed</b>: <<testCount>>'
  118. $ROW[6] = ' <b>Number of test passed</b> : <<testPassed>>'
  119. $ROW[7] = ' <b>Number of test failed</b> : <<testFailed>>'
  120. $ROW[8] = '<table style="border: 2px solid #000; background: white;">'
  121. $ROW[9] = '<tr style="border: 2px solid #000; background: white;"><th style="max-width: 15%; border: 2px solid #000; background: white;">Test Name</th><th style="max-width: 30%; border: 1px solid #000; background: white;">Call (location, function)</th><th style="max-width: 25%; border: 1px solid #000; background: white;">Expected</th><th style="max-width: 20%; border: 1px solid #000; background: white;">Actual</th><th style="max-width: 10%; border: 1px solid #000; background: white;">Result</th></tr>'
  122. size = ARRSIZE('testResults')
  123. rowindex = ARRSIZE('ROW')
  124. resultindex = 0
  125. :testresultprocessloop
  126. $ROW[rowindex] = '<tr style="padding: 5px; border: 1px solid #000;"><td style="border: 1px solid #000; padding: 10px; margin-right: 10px;">' + $REPLACE($testResults[resultindex], '; ', '</td><td style="border: 1px solid #000; padding: 10px; margin: 0px 10px 0px 10px;">') + '</td></tr>'
  127. rowindex += 1
  128. resultindex += 1
  129. if resultindex < size: jump 'testresultprocessloop'
  130. $ROW[rowindex] = '</table>'
  131. size = ARRSIZE('ROW')
  132. index = 0
  133. :testresultdisplayloop
  134. '<<$ROW[index]>>'
  135. index += 1
  136. if index < size: jump 'testresultdisplayloop'
  137. '<hr>'
  138. *nl
  139. end
  140. if $ARGS[0] = 'saveTestResults':
  141. gs 'testframework', 'cleanUpTestData'
  142. _TESTSAVED = 1
  143. savegame '<<$_TESTSUITE>>-Results-<<$_TESTFILETIME>>.test'
  144. end
  145. if $ARGS[0] = 'cleanUpDefault':
  146. killvar 'ARGUMENTS'
  147. killvar 'EXPECTED'
  148. killvar 'EXPECTED_MESSAGE'
  149. killvar 'ACTUAL'
  150. killvar 'ACTUAL_MESSAGE'
  151. killvar 'FUNCTIONNAME'
  152. killvar 'TESTRESULT'
  153. killvar 'daystart'
  154. killvar 'month'
  155. killvar '$month'
  156. killvar 'day'
  157. killvar 'week'
  158. killvar 'hour'
  159. killvar 'minut'
  160. killvar 'birthyear'
  161. killvar 'birthmonth'
  162. killvar 'birthday'
  163. killvar 'pcs_haircol'
  164. killvar 'pcs_eyesize'
  165. killvar 'pcs_lip'
  166. killvar 'pcs_lashes'
  167. !! Body
  168. killvar 'pcs_hgt'
  169. killvar 'pcs_teeth'
  170. killvar 'pcs_butt'
  171. killvar 'pcs_skin'
  172. !! Stats
  173. killvar 'pcs_stren'
  174. killvar 'strenbuf'
  175. killvar 'pcs_agil'
  176. killvar 'agilbuf'
  177. killvar 'pcs_vital'
  178. killvar 'vitalbuf'
  179. killvar 'pcs_intel'
  180. killvar 'pcs_sprt'
  181. killvar 'pcs_react'
  182. killvar 'pcs_chrsm'
  183. killvar 'pcs_prcptn'
  184. killvar 'pcs_magik'
  185. killvar 'pcs_firstname'
  186. killvar 'pcs_lastname'
  187. killvar 'pcs_nickname'
  188. end
  189. --- testframework --------------------------------