y_testing.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /**--------------------------------------------------------------------------**\
  2. ====================================
  3. y_testing - Run unit tests easilly
  4. ====================================
  5. Description:
  6. Runs any functions named as tests when the Testing_Run function is called.
  7. Legal:
  8. Version: MPL 1.1
  9. The contents of this file are subject to the Mozilla Public License Version
  10. 1.1 (the "License"); you may not use this file except in compliance with
  11. the License. You may obtain a copy of the License at
  12. http://www.mozilla.org/MPL/
  13. Software distributed under the License is distributed on an "AS IS" basis,
  14. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  15. for the specific language governing rights and limitations under the
  16. License.
  17. The Original Code is the YSI testing include.
  18. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  19. Portions created by the Initial Developer are Copyright (C) 2011
  20. the Initial Developer. All Rights Reserved.
  21. Contributors:
  22. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  23. Thanks:
  24. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  25. ZeeX - Very productive conversations.
  26. koolk - IsPlayerinAreaEx code.
  27. TheAlpha - Danish translation.
  28. breadfish - German translation.
  29. Fireburn - Dutch translation.
  30. yom - French translation.
  31. 50p - Polish translation.
  32. Zamaroht - Spanish translation.
  33. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  34. for me to strive to better.
  35. Pixels^ - Running XScripters where the idea was born.
  36. Matite - Pestering me to release it and using it.
  37. Very special thanks to:
  38. Thiadmer - PAWN, whose limits continue to amaze me!
  39. Kye/Kalcor - SA:MP.
  40. SA:MP Team past, present and future - SA:MP.
  41. Version:
  42. 1.0
  43. Changelog:
  44. 16/02/12:
  45. Added better error reporting (less verbose passes).
  46. Removed "Tests:".
  47. Added player requiring tests.
  48. 25/10/10:
  49. Integrated in to YSI.
  50. 06/08/10:
  51. First version
  52. </remarks>
  53. \**--------------------------------------------------------------------------**/
  54. /*#if defined _inc_a_samp || defined _samp_included || defined _inc_y_version
  55. #error y_testing must be the VERY FIRST include in your mode if being used.
  56. #endif
  57. // Now we redefined "native" to do something clever!
  58. // "IsPlayerAttachedObjectSlotUsed" is an issue for us...
  59. // "y_renative" allows native functions to be declared without constantly trying
  60. // to redefine it.
  61. #include "internal\y_renative"
  62. #define native%0(%1); _YSI_NO_TAG_NATIVE:_YSI_RE_NATIVE<%0@|||%1|||%0>_YSI_RE_STOCK<%0|||%1|||_:%0@>
  63. //stock%0(%1){printf(_:_YSI_NO_SQUARE:"native "#%0" called");return _:%0@(%1);}
  64. #define _YSI_RE_STOCK<%0|||%1|||%2> stock%0(%1){print(_:_YSI_NO_SQUARE:"native "#%0" called");return %2(%1);}
  65. #define _YSI_NO_SQUARE:%0);%1(%2[%3]%4);} _YSI_NO_SQUARE:%0);%1(%2%4);}
  66. //#define _YSI_NO_TAG_NATIVE:_YSI_RE_NATIVE<%0:%1|||%2|||%3:%4>%5{%6;%7:%8:%9} _YSI_RE_NATIVE<%1|||%2|||%4>%5{%6;return%8:%9}
  67. #define _YSI_NO_TAG_NATIVE:_YSI_RE_NATIVE<%0:%1|||%2|||%3:%4>_YSI_RE_STOCK<%5:%6|||%7|||_:%8:%9> _YSI_RE_NATIVE<%1|||%2|||%4>_YSI_RE_STOCK<%5:%6|||%7|||%8:%9>*/
  68. #include <a_samp>
  69. #if defined YSI_TESTS
  70. #if defined INCLUDE_TESTS
  71. #error Incompatible testing options (YSI_TESTS + INCLUDE_TESTS)
  72. #endif
  73. #if !defined RUN_TESTS
  74. #define RUN_TESTS
  75. #endif
  76. #endif
  77. #if defined INCLUDE_TESTS
  78. #define RUN_TESTS
  79. #define Debug_PrintT va_printf
  80. #elseif defined RUN_TESTS
  81. #define _AUTO_RUN_TESTS
  82. #define Debug_PrintT va_printf
  83. #else
  84. #if _DEBUG > 0 || defined _YSI_SPECIAL_DEBUG
  85. #define RUN_TESTS
  86. #define _AUTO_RUN_TESTS
  87. //#if defined _YSI_SPECIAL_DEBUG
  88. // #define TP printf
  89. // //#define TC(%0); %0
  90. #define Debug_PrintT va_printf
  91. //#else
  92. // //#define TP P:0
  93. // //#define TC C:0
  94. //#endif
  95. #else
  96. #define Debug_PrintT(%0);
  97. // #define Tests:%1() stock bool:Tests_@%1()
  98. // #define Test:%1() stock bool:Test_@%1()
  99. // #define TestInit:%1() stock Init_@%1()
  100. // #define TestClose:%1() stock Shut_@%1()
  101. #endif
  102. #endif
  103. #define Y_TESTING_DIALOG_ID (0x7974) // "yt"
  104. #define TEST_TRUE(%0) Testing_Test(!!%0)
  105. #define TEST_FALSE(%0) Testing_Test(!%0)
  106. #define TEST_NULL(%0) Testing_Test(0 == %0)
  107. #define TEST_NOT_NULL(%0) Testing_Test(0 != %0)
  108. #define TEST_N(%0,%1) Testing_Test(%1 == %0)
  109. #define TEST_TRUE_EX(%0,%2) Testing_Test(bool:(%0), (%2))
  110. #define TEST_FALSE_EX(%0,%2) Testing_Test(!(%0), (%2))
  111. #define TEST_NULL_EX(%0,%2) Testing_Test((%0) == 0, (%2))
  112. #define TEST_N_EX(%0,%1,%2) Testing_Test((%0) == (%1), (%2))
  113. #define TEST_MSG "\2\2\2\2\2"
  114. #define TEST_FAILED "FAIL:"
  115. #define TEST_PASSED "PASS!"
  116. //#define TEST_FAILED "*** Test Failed:"
  117. //#define TEST_PASSED "*** Test Passed:"
  118. #define _Y_TESTEQ(%0) "\"%0\"")
  119. #define _Y_TESTDQ:_Y_TESTEQ(%0"%1"%2) _Y_TESTDQ:_Y_TESTEQ(%0\x22;%1\x22;%2)
  120. //#define _Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0)%1) _Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0\x29;%1)
  121. #define _Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0)%1) _Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0\x29;%1)
  122. #define _Y_TESTOB:_Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0(%1) _Y_TESTOB:_Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0\x28;%1)
  123. #define ASSERT(%0) Testing_Test(%0,TEST_MSG" %s", _Y_TESTOB:_Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0)
  124. #define ASSERT_TRUE(%0) ASSERT(!!%0) //Testing_Test(!!%0,__name)
  125. #define ASSERT_FALSE(%0) ASSERT(!%0) //Testing_Test(!%0,__name)
  126. #define ASSERT_NULL(%0) ASSERT(0 == %0) //Testing_Test(0==%0,__name)
  127. #define ASSERT_N:%1(%0) ASSERT(%1 == %0) //Testing_Test(%1==%0,__name)
  128. #define ASK(%0) Testing_Ask(playerid,%0)
  129. static stock
  130. YSI_g_sFailMessage[512],
  131. YSI_g_sPlayer = cellmax,
  132. bool:YSI_g_sAsked,
  133. YSI_g_sTests,
  134. YSI_g_sFails;
  135. #if defined RUN_TESTS
  136. #define Test:%1() forward bool:Tezt_@%1(); public bool:Tezt_@%1() for(new string:__name[]=#%1,bool:__once=(printf("*** Test %s start", __name) || TRUE);__once;__once=(printf(" ") && FALSE))
  137. //#define Tests:%1() forward bool:Test_@%1(); public bool:Test_@%1() for(new string:__name[]=#%1,bool:__once=(printf("*** Test %s start", __name) || TRUE);__once;__once=(printf(" ") && FALSE))
  138. #define TestInit:%1() forward Init_@%1(); public Init_@%1() for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))
  139. #define TestClose:%1() forward Shut_@%1(); public Shut_@%1() for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))
  140. #define PTest:%1(%2) forward bool:Tezp_@%1(%2); public bool:Tezp_@%1(%2) for(new string:__name[]=#%1,bool:__once=(printf("*** Player Test %s start", __name) || TRUE);__once;__once=(printf(" ") && FALSE))
  141. //#define Tests:%1() forward bool:Test_@%1(); public bool:Test_@%1() for(new string:__name[]=#%1,bool:__once=(printf("*** Test %s start", __name) || TRUE);__once;__once=(printf(" ") && FALSE))
  142. #define PTestInit:%1(%2) forward Inip_@%1(%2); public Inip_@%1(%2) for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))
  143. #define PTestClose:%1(%2) forward Shup_@%1(%2); public Shup_@%1(%2) for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))
  144. #else
  145. #define Test:%1() stock bool:Test_@%1()
  146. #define TestInit:%1() stock Init_@%1()
  147. #define TestClose:%1() stock Shut_@%1()
  148. #define PTest:%1(%2) stock bool:Test_@%1(%2)
  149. #define PTestInit:%1(%2) stock Init_@%1(%2)
  150. #define PTestClose:%1(%2) stock Shut_@%1(%2)
  151. #endif
  152. // These all need to come AFTER the types are defined in case the have tests.
  153. #include "internal\y_version"
  154. #include "y_amx"
  155. #include "internal\y_shortfunc"
  156. #include "y_debug"
  157. #include "internal\y_natives"
  158. #include "y_va"
  159. /**--------------------------------------------------------------------------**\
  160. <summary>Testing_Ask</summary>
  161. <param name="playerid">Player to ask a question to.</param>
  162. <param name="str[]">What to ask.</param>
  163. <param name="va_args<>">Additional data.</param>
  164. <returns>
  165. -
  166. </returns>
  167. <remarks>
  168. Calls a dialog to ask the player if the given test actually passed.
  169. </remarks>
  170. \**--------------------------------------------------------------------------**/
  171. stock Testing_Ask(playerid, str[] = "", va_args<>)
  172. {
  173. va_format(YSI_g_sFailMessage, sizeof (YSI_g_sFailMessage), str, va_start<2>);
  174. ShowPlayerDialog(playerid, Y_TESTING_DIALOG_ID, DIALOG_STYLE_MSGBOX, "Did the test pass?", YSI_g_sFailMessage, "Yes", "No");
  175. YSI_g_sAsked = true;
  176. }
  177. stock Testing_Test(bool:x, str[] = "", va_args<>)
  178. {
  179. P:3("Testing_Test called: %i, \"%s\"", x, str);
  180. ++YSI_g_sTests;
  181. if (!x)
  182. {
  183. ++YSI_g_sFails;
  184. if (numargs() == 2)
  185. {
  186. P:T(TEST_FAILED " %s", va_start<1>);
  187. //printf("*** Test failed: %s", str);
  188. }
  189. else
  190. {
  191. if (str[0] == '\2')
  192. {
  193. strunpack(str, !TEST_FAILED, 6);
  194. str[5] = ' ';
  195. }
  196. P:T(str, va_start<2>);
  197. }
  198. }
  199. #if defined TEST_SHOW_PASSES
  200. else /*if (numargs() == 2)
  201. {
  202. P:T(TEST_PASSED " %s", va_start<1>);
  203. }
  204. else
  205. {
  206. P:T(str, va_start<2>);
  207. if (str[0] == '\2')
  208. {
  209. strunpack(str, !TEST_PASSED, 17);
  210. str[16] = ' ';
  211. }
  212. printf(str);
  213. P:T(str, va_start<2>);*/
  214. {
  215. P:T(TEST_PASSED, va_start<2>);
  216. }
  217. #endif
  218. }
  219. /**--------------------------------------------------------------------------**\
  220. <summary>Testing_Run</summary>
  221. <param name="&tests">Number of tests run.</param>
  222. <param name="&fails">Number of tests which failed.</param>
  223. <param name="buffer[33]">The name of the first test which failed.</param>
  224. <returns>
  225. Wether all tests were sucessful or not.
  226. </returns>
  227. <remarks>
  228. -
  229. native Testing_Run(&tests, &fails, buffer[33] = "");
  230. </remarks>
  231. \**--------------------------------------------------------------------------**/
  232. stock bool:Testing_Run(&tests, &fails, lastfail[33] = "", bool:p = false)
  233. {
  234. P:3("bool:Testing_Run called: %i, %i, \"%s\", %i", tests, fails, lastfail, p);
  235. #pragma unused p, lastfail
  236. #if defined RUN_TESTS
  237. P:2("Testing_Run() called");
  238. new
  239. idx,
  240. buffer[32];
  241. while ((idx = AMX_GetPublicName(idx, buffer, "Tezt_@")))
  242. {
  243. strunpack(buffer, buffer);
  244. //++YSI_g_sTests;
  245. // Call the setup function if there is one.
  246. buffer[0] = 'I';
  247. buffer[1] = 'n';
  248. buffer[2] = 'i';
  249. buffer[3] = 't';
  250. CallLocalFunction(buffer, "");
  251. // Call the test.
  252. buffer[0] = 'T';
  253. buffer[1] = 'e';
  254. buffer[2] = 'z';
  255. buffer[3] = 't';
  256. fails = YSI_g_sFails;
  257. P:5("Testing_Run(): Calling %s", buffer[6]);
  258. CallLocalFunction(buffer, "");
  259. #if !defined TEST_SHOW_PASSES
  260. if (YSI_g_sFails == fails)
  261. {
  262. printf(TEST_PASSED);
  263. printf(" ");
  264. }
  265. #endif
  266. /*if (YSI_g_sFails != fails)
  267. {
  268. if (YSI_g_sFails)
  269. {
  270. ++YSI_g_sFails;
  271. }
  272. else
  273. {
  274. fails = 0;
  275. // Copy the string over.
  276. while ((lastfail[fails] = buffer[fails + 6])) ++fails;
  277. YSI_g_sFails = 1;
  278. }
  279. //C:1(if (p) printf("*** Test failed: %s", buffer[fails + 6]););
  280. }*/
  281. // Call the shutdown function if there is one.
  282. buffer[0] = 'S';
  283. buffer[1] = 'h';
  284. buffer[2] = 'u';
  285. buffer[3] = 't';
  286. CallLocalFunction(buffer, "");
  287. }
  288. tests = YSI_g_sTests;
  289. fails = YSI_g_sFails;
  290. return fails == 0;
  291. #else
  292. #pragma unused tests, fails, lastfail
  293. return true;
  294. #endif
  295. }
  296. /**--------------------------------------------------------------------------**\
  297. <summary>Testing_Player</summary>
  298. <param name="playerid">Player to test on.</param>
  299. <param name="&idx">Next test to run.</param>
  300. <param name="&tests">Number of tests run.</param>
  301. <param name="&fails">Number of tests which failed.</param>
  302. <param name="buffer[33]">The name of the first test which failed.</param>
  303. <returns>
  304. Wether all tests were sucessful or not.
  305. </returns>
  306. <remarks>
  307. -
  308. native Testing_Run(&tests, &fails, buffer[33] = "");
  309. </remarks>
  310. \**--------------------------------------------------------------------------**/
  311. stock bool:Testing_Player(playerid, &idx, &tests, &fails, lastfail[33] = "", bool:p = false)
  312. {
  313. P:3("bool:Testing_Player called: %i, %i, %i, %i, \"%s\", %i", playerid, idx, tests, fails, lastfail, p);
  314. #pragma unused p
  315. #if defined RUN_TESTS
  316. P:2("Testing_Player() called");
  317. new
  318. //idx,
  319. buffer[32];
  320. //while ((idx = AMX_GetPublicName(idx, buffer, "Tezt_@")))
  321. if ((idx = AMX_GetPublicName(idx, buffer, "Tezp_@")))
  322. {
  323. strunpack(buffer, buffer);
  324. //++YSI_g_sTests;
  325. // Call the setup function if there is one.
  326. buffer[0] = 'I';
  327. buffer[1] = 'n';
  328. buffer[2] = 'i';
  329. buffer[3] = 'p';
  330. CallLocalFunction(buffer, "");
  331. // Call the test.
  332. buffer[0] = 'T';
  333. buffer[1] = 'e';
  334. buffer[2] = 'z';
  335. buffer[3] = 'p';
  336. fails = YSI_g_sFails;
  337. P:5("Testing_Player(): Calling %s", buffer[6]);
  338. CallLocalFunction(buffer, "");
  339. #if !defined TEST_SHOW_PASSES
  340. if (YSI_g_sFails == fails)
  341. {
  342. printf(TEST_PASSED);
  343. printf(" ");
  344. }
  345. #endif
  346. /*if (YSI_g_sFails != fails)
  347. {
  348. if (YSI_g_sFails)
  349. {
  350. ++YSI_g_sFails;
  351. }
  352. else
  353. {
  354. fails = 0;
  355. // Copy the string over.
  356. while ((lastfail[fails] = buffer[fails + 6])) ++fails;
  357. YSI_g_sFails = 1;
  358. }
  359. //C:1(if (p) printf("*** Test failed: %s", buffer[fails + 6]););
  360. }*/
  361. // Call the shutdown function if there is one.
  362. //buffer[0] = 'S';
  363. //buffer[1] = 'h';
  364. //buffer[2] = 'u';
  365. //buffer[3] = 'p';
  366. //CallLocalFunction(buffer, "");
  367. }
  368. tests = YSI_g_sTests;
  369. fails = YSI_g_sFails;
  370. return fails == 0;
  371. #else
  372. #pragma unused tests, fails, lastfail
  373. return true;
  374. #endif
  375. }
  376. #if defined RUN_TESTS
  377. /*#define Test:%1() forward bool:Tezt_@%1(); public bool:Tezt_@%1() for(new string:__name[]=#%1,bool:__once=(printf("*** Test %s start", __name) || TRUE);__once;__once=(printf(" ") && FALSE))
  378. //#define Tests:%1() forward bool:Test_@%1(); public bool:Test_@%1() for(new string:__name[]=#%1,bool:__once=(printf("*** Test %s start", __name) || TRUE);__once;__once=(printf(" ") && FALSE))
  379. #define TestInit:%1() forward Init_@%1(); public Init_@%1() for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))
  380. #define TestClose:%1() forward Shut_@%1(); public Shut_@%1() for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))
  381. #define PTest:%1(%2) forward bool:Tezp_@%1(%2); public bool:Tezp_@%1(%2) for(new string:__name[]=#%1,bool:__once=(printf("*** Player Test %s start", __name) || TRUE);__once;__once=(printf(" ") && FALSE))
  382. //#define Tests:%1() forward bool:Test_@%1(); public bool:Test_@%1() for(new string:__name[]=#%1,bool:__once=(printf("*** Test %s start", __name) || TRUE);__once;__once=(printf(" ") && FALSE))
  383. #define PTestInit:%1(%2) forward Inip_@%1(%2); public Inip_@%1(%2) for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))
  384. #define PTestClose:%1(%2) forward Shup_@%1(%2); public Shup_@%1(%2) for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))*/
  385. #if defined _AUTO_RUN_TESTS
  386. #if !defined FILTERSCRIPT
  387. // Hook main in gamemodes.
  388. main()
  389. {
  390. // Disable error messages (as we're likely to generate them).
  391. state ysi_debug : off;
  392. CallLocalFunction("Testing_main", "");
  393. new
  394. tests,
  395. fails;
  396. printf(" ");
  397. printf(" ||===================|| ");
  398. printf(" || STARTING TESTS... || ");
  399. printf(" ||===================|| ");
  400. printf(" ");
  401. Testing_Run(tests, fails, _, true);
  402. printf("*** Tests: %d, Fails: %d", tests, fails);
  403. if (!fails)
  404. {
  405. printf(" ");
  406. printf(" ||===================|| ");
  407. printf(" || ALL TESTS PASSED! || ");
  408. printf(" ||===================|| ");
  409. printf(" ");
  410. }
  411. state ysi_debug : on;
  412. }
  413. #define main forward Testing_main(); public Testing_main
  414. Testing_Next(playerid)
  415. {
  416. new
  417. buffer[32];
  418. for ( ; ; )
  419. {
  420. new
  421. fails = YSI_g_sFails;
  422. // Get the last test (nicely fails for cellmax).
  423. if ((YSI_g_sPlayer = AMX_GetPublicName(YSI_g_sPlayer, buffer, "Tezp_@")))
  424. {
  425. strunpack(buffer, buffer);
  426. // Call the shutdown function if there is one.
  427. buffer[0] = 'S';
  428. buffer[1] = 'h';
  429. buffer[2] = 'u';
  430. buffer[3] = 'p';
  431. CallLocalFunction(buffer, "i", playerid);
  432. }
  433. // Get the new test, but don't store the index.
  434. if (AMX_GetPublicName(YSI_g_sPlayer, buffer, "Tezp_@"))
  435. {
  436. YSI_g_sAsked = false;
  437. //++YSI_g_sTests;
  438. strunpack(buffer, buffer);
  439. // Call the setup function if there is one.
  440. buffer[0] = 'I';
  441. buffer[1] = 'n';
  442. buffer[2] = 'i';
  443. buffer[3] = 'p';
  444. CallLocalFunction(buffer, "i", playerid);
  445. // Call the test.
  446. buffer[0] = 'T';
  447. buffer[1] = 'e';
  448. buffer[2] = 'z';
  449. buffer[3] = 'p';
  450. P:5("Testing_Next(): Calling %s", buffer[6]);
  451. CallLocalFunction(buffer, "i", playerid);
  452. }
  453. else
  454. {
  455. YSI_g_sAsked = true;
  456. // No more tests.
  457. printf("*** Tests: %d, Fails: %d", YSI_g_sTests, YSI_g_sFails);
  458. if (!YSI_g_sFails)
  459. {
  460. printf(" ");
  461. printf(" ||==========================|| ");
  462. printf(" || ALL PLAYER TESTS PASSED! || ");
  463. printf(" ||==========================|| ");
  464. printf(" ");
  465. }
  466. }
  467. // If the test needs a player but doesn't ask them anything
  468. // then we can't wait for "OnDialogResponse" to run the next
  469. // one.
  470. if (YSI_g_sAsked)
  471. {
  472. break;
  473. }
  474. else if (fails == YSI_g_sFails)
  475. {
  476. printf(TEST_PASSED);
  477. }
  478. }
  479. //while (!YSI_g_sAsked);
  480. }
  481. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  482. {
  483. if (dialogid == Y_TESTING_DIALOG_ID)
  484. {
  485. ++YSI_g_sTests;
  486. if (response)
  487. {
  488. // Pass.
  489. printf(TEST_PASSED);
  490. }
  491. else
  492. {
  493. // Fail.
  494. printf(TEST_FAILED " %s", YSI_g_sFailMessage);
  495. ++YSI_g_sFails;
  496. }
  497. Testing_Next(playerid);
  498. return 1;
  499. }
  500. #if defined Testing_OnDialogResponse
  501. return Testing_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
  502. #else
  503. return 1;
  504. #endif
  505. }
  506. #if defined _ALS_OnDialogResponse
  507. #undef OnDialogResponse
  508. #else
  509. #define _ALS_OnDialogResponse
  510. #endif
  511. #define OnDialogResponse Testing_OnDialogResponse
  512. #if defined Testing_OnDialogResponse
  513. forward Testing_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  514. #endif
  515. public OnPlayerSpawn(playerid)
  516. {
  517. if (YSI_g_sPlayer == cellmax && !IsPlayerNPC(playerid))
  518. {
  519. printf(" ");
  520. printf(" ||==========================|| ");
  521. printf(" || STARTING PLAYER TESTS... || ");
  522. printf(" ||==========================|| ");
  523. printf(" ");
  524. YSI_g_sTests = 0;
  525. YSI_g_sFails = 0;
  526. Testing_Next(playerid);
  527. }
  528. #if defined Testing_OnPlayerSpawn
  529. return Testing_OnPlayerSpawn(playerid);
  530. #else
  531. return 1;
  532. #endif
  533. }
  534. #if defined _ALS_OnPlayerSpawn
  535. #undef OnPlayerSpawn
  536. #else
  537. #define _ALS_OnPlayerSpawn
  538. #endif
  539. #define OnPlayerSpawn Testing_OnPlayerSpawn
  540. #if defined Testing_OnPlayerSpawn
  541. forward Testing_OnPlayerSpawn(playerid);
  542. #endif
  543. #endif
  544. #else
  545. Testing_RunAll()
  546. {
  547. // Disable error messages (as we're likely to generate them).
  548. state ysi_debug : off;
  549. new
  550. tests,
  551. fails;
  552. printf(" ");
  553. printf(" ||===================|| ");
  554. printf(" || STARTING TESTS... || ");
  555. printf(" ||===================|| ");
  556. printf(" ");
  557. Testing_Run(tests, fails, _, true);
  558. printf("*** Tests: %d, Fails: %d", tests, fails);
  559. if (!fails)
  560. {
  561. printf(" ");
  562. printf(" ||===================|| ");
  563. printf(" || ALL TESTS PASSED! || ");
  564. printf(" ||===================|| ");
  565. printf(" ");
  566. }
  567. state ysi_debug : on;
  568. }
  569. #endif
  570. #else
  571. //#define Tests:%1() stock bool:Tests_@%1()
  572. /*#define Test:%1() stock bool:Test_@%1()
  573. #define TestInit:%1() stock Init_@%1()
  574. #define TestClose:%1() stock Shut_@%1()
  575. #define PTest:%1(%2) stock bool:Test_@%1(%2)
  576. #define PTestInit:%1(%2) stock Init_@%1(%2)
  577. #define PTestClose:%1(%2) stock Shut_@%1(%2)*/
  578. #endif