y_testing.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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_y_testing
  55. #endinput
  56. #endif
  57. #define _INC_y_testing
  58. #include <a_samp>
  59. #include "y_debug"
  60. #include "..\YSI_Storage\y_amx"
  61. #if defined YSI_TESTS
  62. #if defined INCLUDE_TESTS
  63. #error Incompatible testing options (YSI_TESTS + INCLUDE_TESTS)
  64. #endif
  65. #if !defined RUN_TESTS
  66. #define RUN_TESTS
  67. #endif
  68. #endif
  69. #if defined INCLUDE_TESTS
  70. #define RUN_TESTS
  71. #define Debug_PrintT va_printf
  72. #elseif defined RUN_TESTS
  73. #define _AUTO_RUN_TESTS
  74. #define Debug_PrintT va_printf
  75. #else
  76. #if _DEBUG > 0 || defined _YSI_SPECIAL_DEBUG
  77. #define RUN_TESTS
  78. #define _AUTO_RUN_TESTS
  79. #define Debug_PrintT va_printf
  80. #else
  81. #define Debug_PrintT(%0);
  82. #endif
  83. #endif
  84. #define Y_TESTING_DIALOG_ID (0x7974) // "yt"
  85. #define TEST_TRUE(%0) Testing_Test(!!%0)
  86. #define TEST_FALSE(%0) Testing_Test(!%0)
  87. #define TEST_NULL(%0) Testing_Test(0 == %0)
  88. #define TEST_NOT_NULL(%0) Testing_Test(0 != %0)
  89. #define TEST_N(%0,%1) Testing_Test(%1 == %0)
  90. #define TEST_TRUE_EX(%0,%2) Testing_Test(bool:(%0), (%2))
  91. #define TEST_FALSE_EX(%0,%2) Testing_Test(!(%0), (%2))
  92. #define TEST_NULL_EX(%0,%2) Testing_Test((%0) == 0, (%2))
  93. #define TEST_N_EX(%0,%1,%2) Testing_Test((%0) == (%1), (%2))
  94. #define TEST_MSG "\2\2\2\2\2"
  95. #define TEST_FAILED "FAIL:"
  96. #define TEST_PASSED "PASS!"
  97. #define _Y_TESTEQ(%0) "\"%0\"")
  98. #define _Y_TESTDQ:_Y_TESTEQ(%0"%1"%2) _Y_TESTDQ:_Y_TESTEQ(%0\x22;%1\x22;%2)
  99. #define _Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0)%1) _Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0\x29;%1)
  100. #define _Y_TESTOB:_Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0(%1) _Y_TESTOB:_Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0\x28;%1)
  101. #define ASSERT(%0) Testing_Test(%0,TEST_MSG" %s", _Y_TESTOB:_Y_TESTCB:_Y_TESTDQ:_Y_TESTEQ(%0)
  102. #define ASSERT_TRUE(%0) ASSERT(!!%0)
  103. #define ASSERT_FALSE(%0) ASSERT(!%0)
  104. #define ASSERT_NULL(%0) ASSERT(0 == %0)
  105. #define ASSERT_N:%1(%0) ASSERT(%1 == %0)
  106. #define ASK(%0) Testing_Ask(playerid,%0)
  107. static stock const
  108. Y_TESTING_TEST = _A<yQ@_>,
  109. Y_TESTING_INIT = _A<_yQ@>,
  110. Y_TESTING_SHUT = _A<yQ_@>,
  111. Y_TESTING_PTEST = _A<_@yQ>,
  112. Y_TESTING_PINIT = _A<_y@Q>,
  113. Y_TESTING_PSHUT = _A<y_@Q>;
  114. static stock
  115. YSI_g_sTestResult,
  116. YSI_g_sFailMessage[512],
  117. YSI_g_sPlayer = cellmax,
  118. bool:YSI_g_sAsked,
  119. YSI_g_sTests,
  120. YSI_g_sFails;
  121. #if defined RUN_TESTS
  122. #define Test:%1() forward bool:yQ@_%1(); public bool:yQ@_%1() for(new string:__name[]=#%1,bool:__once=(printf("*** Test %s start", __name) || TRUE);__once;__once=(printf(" ") && FALSE))
  123. #define TestInit:%1() forward _yQ@%1(); public _yQ@%1() for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))
  124. #define TestClose:%1() forward yQ_@%1(); public yQ_@%1() for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))
  125. #define PTest:%1(%2) forward bool:_@yQ%1(%2); public bool:_@yQ%1(%2) for(new string:__name[]=#%1,bool:__once=(printf("*** Player Test %s start", __name) || TRUE);__once;__once=(printf(" ") && FALSE))
  126. #define PTestInit:%1(%2) forward _y@Q%1(%2); public _y@Q%1(%2) for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))
  127. #define PTestClose:%1(%2) forward y_@Q%1(%2); public y_@Q%1(%2) for(new string:__name[]=#%1,bool:__once=TRUE;__once;__once=(printf(" ", __name) && FALSE))
  128. #else
  129. #define Test:%1() stock bool:yQ@_%1()
  130. #define TestInit:%1() stock _yQ@%1()
  131. #define TestClose:%1() stock yQ_@%1()
  132. #define PTest:%1(%2) stock bool:_@yQ%1(%2)
  133. #define PTestInit:%1(%2) stock _y@Q%1(%2)
  134. #define PTestClose:%1(%2) stock y_@Q%1(%2)
  135. #endif
  136. // These all need to come AFTER the types are defined in case the have tests.
  137. #include "..\YSI_Internal\y_version"
  138. #include "..\YSI_Storage\y_amx"
  139. #include "..\YSI_Internal\y_shortfunc"
  140. #include "y_debug"
  141. #include "..\YSI_Internal\y_natives"
  142. #include "..\YSI_Coding\y_va"
  143. /**--------------------------------------------------------------------------**\
  144. <summary>Testing_Ask</summary>
  145. <param name="playerid">Player to ask a question to.</param>
  146. <param name="str[]">What to ask.</param>
  147. <param name="va_args<>">Additional data.</param>
  148. <returns>
  149. -
  150. </returns>
  151. <remarks>
  152. Calls a dialog to ask the player if the given test actually passed.
  153. </remarks>
  154. \**--------------------------------------------------------------------------**/
  155. stock Testing_Ask(playerid, str[] = "", va_args<>)
  156. {
  157. va_format(YSI_g_sFailMessage, sizeof (YSI_g_sFailMessage), str, va_start<2>);
  158. ShowPlayerDialog(playerid, Y_TESTING_DIALOG_ID, DIALOG_STYLE_MSGBOX, "Did the test pass?", YSI_g_sFailMessage, "Yes", "No");
  159. YSI_g_sAsked = true;
  160. }
  161. stock Testing_Test(bool:x, str[] = "", va_args<>)
  162. {
  163. P:3("Testing_Test called: %i, \"%s\"", x, str);
  164. ++YSI_g_sTests;
  165. if (!x)
  166. {
  167. ++YSI_g_sFails;
  168. if (numargs() == 2)
  169. {
  170. P:T(TEST_FAILED " %s", va_start<1>);
  171. }
  172. else
  173. {
  174. if (str[0] == '\2')
  175. {
  176. strunpack(str, !TEST_FAILED, 6);
  177. str[5] = ' ';
  178. }
  179. P:T(str, va_start<2>);
  180. }
  181. }
  182. #if defined TEST_SHOW_PASSES
  183. else
  184. {
  185. P:T(TEST_PASSED, va_start<2>);
  186. }
  187. #endif
  188. }
  189. /**--------------------------------------------------------------------------**\
  190. <summary>Testing_Run</summary>
  191. <param name="&tests">Number of tests run.</param>
  192. <param name="&fails">Number of tests which failed.</param>
  193. <param name="buffer[33]">The name of the first test which failed.</param>
  194. <returns>
  195. Wether all tests were sucessful or not.
  196. </returns>
  197. <remarks>
  198. -
  199. native Testing_Run(&tests, &fails, buffer[33] = "");
  200. </remarks>
  201. \**--------------------------------------------------------------------------**/
  202. stock bool:Testing_Run(&tests, &fails, lastfail[33] = "", bool:p = false)
  203. {
  204. P:3("bool:Testing_Run called: %i, %i, \"%s\", %i", tests, fails, lastfail, p);
  205. #pragma unused p, lastfail
  206. #if defined RUN_TESTS
  207. P:2("Testing_Run() called");
  208. new
  209. idx,
  210. buffer[32];
  211. while ((idx = AMX_GetPublicNamePrefix(idx, buffer, Y_TESTING_TEST)))
  212. {
  213. strunpack(buffer, buffer);
  214. // Call the setup function if there is one.
  215. buffer[0] = '_';
  216. buffer[1] = 'y';
  217. buffer[2] = 'Q';
  218. buffer[3] = '@';
  219. CallLocalFunction(buffer, "");
  220. // Call the test.
  221. buffer[0] = 'y';
  222. buffer[1] = 'Q';
  223. buffer[2] = '@';
  224. buffer[3] = '_';
  225. fails = YSI_g_sFails;
  226. P:5("Testing_Run(): Calling %s", unpack(buffer[1]));
  227. CallLocalFunction(buffer, "");
  228. #if !defined TEST_SHOW_PASSES
  229. if (YSI_g_sFails == fails)
  230. {
  231. printf(TEST_PASSED);
  232. printf(" ");
  233. }
  234. #endif
  235. buffer[2] = '_';
  236. buffer[3] = '@';
  237. CallLocalFunction(buffer, "");
  238. }
  239. tests = YSI_g_sTests;
  240. fails = YSI_g_sFails;
  241. return fails == 0;
  242. #else
  243. #pragma unused tests, fails, lastfail
  244. return true;
  245. #endif
  246. }
  247. /**--------------------------------------------------------------------------**\
  248. <summary>Testing_Player</summary>
  249. <param name="playerid">Player to test on.</param>
  250. <param name="&idx">Next test to run.</param>
  251. <param name="&tests">Number of tests run.</param>
  252. <param name="&fails">Number of tests which failed.</param>
  253. <param name="buffer[33]">The name of the first test which failed.</param>
  254. <returns>
  255. Wether all tests were sucessful or not.
  256. </returns>
  257. <remarks>
  258. -
  259. native Testing_Run(&tests, &fails, buffer[33] = "");
  260. </remarks>
  261. \**--------------------------------------------------------------------------**/
  262. stock bool:Testing_Player(playerid, &idx, &tests, &fails, lastfail[33] = "", bool:p = false)
  263. {
  264. P:3("bool:Testing_Player called: %i, %i, %i, %i, \"%s\", %i", playerid, idx, tests, fails, lastfail, p);
  265. #pragma unused p
  266. #if defined RUN_TESTS
  267. P:2("Testing_Player() called");
  268. new
  269. buffer[32];
  270. if ((idx = AMX_GetPublicNamePrefix(YSI_g_sPlayer, buffer, Y_TESTING_PTEST)))
  271. {
  272. strunpack(buffer, buffer);
  273. // Call the setup function if there is one.
  274. buffer[0] = '_';
  275. buffer[1] = 'y';
  276. buffer[2] = '@';
  277. buffer[3] = 'Q';
  278. CallLocalFunction(buffer, "");
  279. // Call the test.
  280. buffer[1] = '@';
  281. buffer[2] = 'y';
  282. fails = YSI_g_sFails;
  283. P:5("Testing_Player(): Calling %s", buffer[6]);
  284. CallLocalFunction(buffer, "");
  285. #if !defined TEST_SHOW_PASSES
  286. if (YSI_g_sFails == fails)
  287. {
  288. printf(TEST_PASSED);
  289. printf(" ");
  290. }
  291. #endif
  292. }
  293. tests = YSI_g_sTests;
  294. fails = YSI_g_sFails;
  295. return fails == 0;
  296. #else
  297. #pragma unused tests, fails, lastfail
  298. return true;
  299. #endif
  300. }
  301. #if defined RUN_TESTS
  302. #if defined _AUTO_RUN_TESTS
  303. #if defined FILTERSCRIPT
  304. // Hook main in gamemodes.
  305. public OnFilterScriptInit()
  306. {
  307. #if defined Testing_OnFilterScriptInit
  308. Testing_OnFilterScriptInit();
  309. #endif
  310. // Disable error messages (as we're likely to generate them).
  311. //state ysi_debug : off;
  312. // Need to do it this way because "y_malloc" screws it up. But
  313. // the new heap is still safe because it is set at this point.
  314. new
  315. tests,
  316. fails;
  317. printf(" ");
  318. printf(" ||===================|| ");
  319. printf(" || STARTING TESTS... || ");
  320. printf(" ||===================|| ");
  321. printf(" ");
  322. Testing_Run(tests, fails, _, true);
  323. if (YSI_g_sTestResult != 9) printf("*** Test system verification failed!");
  324. else
  325. {
  326. printf("*** Tests: %d, Fails: %d", tests, fails);
  327. if (!fails)
  328. {
  329. printf(" ");
  330. printf(" ||===================|| ");
  331. printf(" || ALL TESTS PASSED! || ");
  332. printf(" ||===================|| ");
  333. printf(" ");
  334. }
  335. }
  336. //state ysi_debug : on;
  337. }
  338. #if defined _ALS_OnFilterScriptInit
  339. #undef OnFilterScriptInit
  340. #else
  341. #define _ALS_OnFilterScriptInit
  342. #endif
  343. #define OnFilterScriptInit Testing_OnFilterScriptInit
  344. #if defined Testing_OnFilterScriptInit
  345. forward Testing_OnFilterScriptInit();
  346. #endif
  347. #else
  348. // Hook main in gamemodes.
  349. main()
  350. {
  351. #if defined Testing_main
  352. Testing_main();
  353. #endif
  354. // Disable error messages (as we're likely to generate them).
  355. //state ysi_debug : off;
  356. // Need to do it this way because "y_malloc" screws it up. But
  357. // the new heap is still safe because it is set at this point.
  358. new
  359. tests,
  360. fails;
  361. printf(" ");
  362. printf(" ||===================|| ");
  363. printf(" || STARTING TESTS... || ");
  364. printf(" ||===================|| ");
  365. printf(" ");
  366. Testing_Run(tests, fails, _, true);
  367. if (YSI_g_sTestResult != 9) printf("*** Test system verification failed!");
  368. else
  369. {
  370. printf("*** Tests: %d, Fails: %d", tests, fails);
  371. if (!fails)
  372. {
  373. printf(" ");
  374. printf(" ||===================|| ");
  375. printf(" || ALL TESTS PASSED! || ");
  376. printf(" ||===================|| ");
  377. printf(" ");
  378. }
  379. }
  380. //state ysi_debug : on;
  381. }
  382. #if defined _ALS_main
  383. #undef main
  384. #else
  385. #define _ALS_main
  386. #endif
  387. #define main forward Testing_main(); public Testing_main
  388. #endif
  389. Testing_Next(playerid)
  390. {
  391. new
  392. buffer[32];
  393. for ( ; ; )
  394. {
  395. new
  396. fails = YSI_g_sFails;
  397. // Get the last test (nicely fails for cellmax).
  398. if ((YSI_g_sPlayer = AMX_GetPublicNamePrefix(YSI_g_sPlayer, buffer, Y_TESTING_PTEST)))
  399. {
  400. strunpack(buffer, buffer);
  401. // Call the shutdown function if there is one.
  402. buffer[0] = 'y';
  403. buffer[1] = '_';
  404. buffer[2] = '@';
  405. buffer[3] = 'Q';
  406. CallLocalFunction(buffer, "i", playerid);
  407. }
  408. // Get the new test, but don't store the index.
  409. if (AMX_GetPublicNamePrefix(YSI_g_sPlayer, buffer, Y_TESTING_PTEST))
  410. {
  411. YSI_g_sAsked = false;
  412. strunpack(buffer, buffer);
  413. // Call the setup function if there is one.
  414. buffer[0] = '_';
  415. buffer[1] = 'y';
  416. buffer[2] = '@';
  417. buffer[3] = 'Q';
  418. CallLocalFunction(buffer, "i", playerid);
  419. // Call the test.
  420. buffer[1] = '@';
  421. buffer[2] = 'y';
  422. P:5("Testing_Next(): Calling %s", unpack(buffer[1]));
  423. CallLocalFunction(buffer, "i", playerid);
  424. }
  425. else
  426. {
  427. YSI_g_sAsked = true;
  428. // No more tests.
  429. printf("*** Tests: %d, Fails: %d", YSI_g_sTests, YSI_g_sFails);
  430. if (!YSI_g_sFails)
  431. {
  432. printf(" ");
  433. printf(" ||==========================|| ");
  434. printf(" || ALL PLAYER TESTS PASSED! || ");
  435. printf(" ||==========================|| ");
  436. printf(" ");
  437. }
  438. }
  439. // If the test needs a player but doesn't ask them anything
  440. // then we can't wait for "OnDialogResponse" to run the next
  441. // one.
  442. if (YSI_g_sAsked)
  443. {
  444. break;
  445. }
  446. else if (fails == YSI_g_sFails)
  447. {
  448. printf(TEST_PASSED);
  449. }
  450. }
  451. }
  452. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  453. {
  454. if (dialogid == Y_TESTING_DIALOG_ID)
  455. {
  456. ++YSI_g_sTests;
  457. if (response)
  458. {
  459. // Pass.
  460. printf(TEST_PASSED);
  461. }
  462. else
  463. {
  464. // Fail.
  465. printf(TEST_FAILED " %s", YSI_g_sFailMessage);
  466. ++YSI_g_sFails;
  467. }
  468. Testing_Next(playerid);
  469. return 1;
  470. }
  471. #if defined Testing_OnDialogResponse
  472. return Testing_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
  473. #else
  474. return 1;
  475. #endif
  476. }
  477. #if defined _ALS_OnDialogResponse
  478. #undef OnDialogResponse
  479. #else
  480. #define _ALS_OnDialogResponse
  481. #endif
  482. #define OnDialogResponse Testing_OnDialogResponse
  483. #if defined Testing_OnDialogResponse
  484. forward Testing_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  485. #endif
  486. public OnPlayerSpawn(playerid)
  487. {
  488. if (YSI_g_sPlayer == cellmax && !IsPlayerNPC(playerid))
  489. {
  490. printf(" ");
  491. printf(" ||==========================|| ");
  492. printf(" || STARTING PLAYER TESTS... || ");
  493. printf(" ||==========================|| ");
  494. printf(" ");
  495. YSI_g_sTests = 0;
  496. YSI_g_sFails = 0;
  497. Testing_Next(playerid);
  498. }
  499. #if defined Testing_OnPlayerSpawn
  500. return Testing_OnPlayerSpawn(playerid);
  501. #else
  502. return 1;
  503. #endif
  504. }
  505. #if defined _ALS_OnPlayerSpawn
  506. #undef OnPlayerSpawn
  507. #else
  508. #define _ALS_OnPlayerSpawn
  509. #endif
  510. #define OnPlayerSpawn Testing_OnPlayerSpawn
  511. #if defined Testing_OnPlayerSpawn
  512. forward Testing_OnPlayerSpawn(playerid);
  513. #endif
  514. #else
  515. Testing_RunAll()
  516. {
  517. // Disable error messages (as we're likely to generate them).
  518. //state ysi_debug : off;
  519. new
  520. tests,
  521. fails;
  522. printf(" ");
  523. printf(" ||===================|| ");
  524. printf(" || STARTING TESTS... || ");
  525. printf(" ||===================|| ");
  526. printf(" ");
  527. Testing_Run(tests, fails, _, true);
  528. printf("*** Tests: %d, Fails: %d", tests, fails);
  529. if (!fails)
  530. {
  531. printf(" ");
  532. printf(" ||===================|| ");
  533. printf(" || ALL TESTS PASSED! || ");
  534. printf(" ||===================|| ");
  535. printf(" ");
  536. }
  537. //state ysi_debug : on;
  538. }
  539. #endif
  540. #endif
  541. // Meta tests.
  542. stock Testing_TestRedirect(bool:x, str[] = "", va_args<>)
  543. {
  544. ASSERT(x == bool:YSI_g_sTestResult);
  545. ASSERT(str[0] != '\0');
  546. ASSERT(!strcmp(str, "\2\2\2\2\2", false, 5));
  547. }
  548. Test:y_testing_2()
  549. {
  550. new
  551. t = YSI_g_sTests,
  552. f = YSI_g_sFails;
  553. ASSERT(false == false);
  554. ASSERT(true == true);
  555. ASSERT(TRUE != FALSE);
  556. ASSERT(t + 3 == YSI_g_sTests);
  557. ASSERT(f == YSI_g_sFails);
  558. ASSERT(t + 5 == YSI_g_sTests);
  559. // Fail a fake test on purpose.
  560. //state ysi_debug : on;
  561. P:I("The next test hasn't really failed...");
  562. P:I(" - It is testing the test system.");
  563. //state ysi_debug : off;
  564. ASSERT(false);
  565. ASSERT(f + 1 == YSI_g_sFails); // Not a mistake. Run this test twice to
  566. ASSERT(f + 1 == YSI_g_sFails); // ensure the first one didn't fail too.
  567. --YSI_g_sFails; // Reduce the failure count to not fail the whole suite.
  568. }
  569. TestInit:y_testing_1()
  570. {
  571. YSI_g_sTestResult = 5;
  572. }
  573. Test:y_testing_1()
  574. {
  575. new
  576. x = YSI_g_sTestResult;
  577. ASSERT(FALSE == false);
  578. ASSERT(TRUE == true);
  579. ASSERT(true != false);
  580. ASSERT(isnull(NULL));
  581. ASSERT_TRUE(true);
  582. ASSERT_TRUE(!false);
  583. ASSERT_FALSE(false);
  584. ASSERT_FALSE(!true);
  585. // Test the messages themselves.
  586. #define Testing_Test Testing_TestRedirect
  587. YSI_g_sTestResult = false;
  588. ASSERT(false);
  589. YSI_g_sTestResult = true;
  590. ASSERT(true);
  591. #undef Testing_Test
  592. YSI_g_sTestResult = x + 3;
  593. }
  594. TestClose:y_testing_1()
  595. {
  596. ++YSI_g_sTestResult;
  597. }