tests.inc 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. #include "..\y_va"
  2. #if !defined ALS_MAKE
  3. #define ALS_MAKE<%0...%1> %0__T_%1
  4. #define __ALS_MAKE_DEFINED
  5. #endif
  6. static stock y_als_Print(result[], fmat[], va_args<>)
  7. {
  8. // This function formats the incoming data and compares it to the reference.
  9. static
  10. msg[256];
  11. format(msg, sizeof (msg), "\"%s\" != \"%s\" (%d)", result, va_return(fmat, va_start<2>), strcmp(result, va_return(fmat, va_start<2>)));
  12. Testing_Test(!strcmp(result, va_return(fmat, va_start<2>)), msg);
  13. }
  14. // Defines for our "__PRINT" macro, see:
  15. // http://ysi.wikia.com/wiki/Library:YSI\y_als
  16. #define __ALS_PS_more:%0, "%d, "__ALS_PS_
  17. #define __ALS_PS_string:%0[], "%s, "__ALS_PS_
  18. #define __ALS_PS_Float:%0, "%f, "__ALS_PS_
  19. #define __ALS_PS_tag:%3:%0, "%d, "__ALS_PS_
  20. #define __ALS_PS_end:%0) "%d"
  21. #define __ALS_PS_none:%0)
  22. #define __ALS_PS_end_string:%0[]) "%s"
  23. #define __ALS_PS_end_Float:%0) "%f"
  24. #define __ALS_PS_end_tag:%3:%0) "%d"
  25. #define __ALS_R2_more:%0, ,%0 __ALS_R2_
  26. #define __ALS_R2_string:%0[], ,((%0[0])?(%0):NULL) __ALS_R2_
  27. #define __ALS_R2_Float:%0, ,(_:%0) __ALS_R2_
  28. #define __ALS_R2_tag:%3:%0, ,(_:%0) __ALS_R2_
  29. #define __ALS_R2_end:%0) ,%0)
  30. #define __ALS_R2_none:) )
  31. #define __ALS_R2_end_string:%0[]) ,((%0[0])?(%0):NULL))
  32. #define __ALS_R2_end_Float:%0) ,(_:%0))
  33. #define __ALS_R2_end_tag:%3:%0) ,(_:%0))
  34. #define __DO_PRINT(%9)<%0,%1>(%2) y_als_Print(%9,"On"#%0"("__ALS_PS_%2)")"__ALS_R2_%2);
  35. #define __PRINT<%0,%9> ALS_DO:__DO_PRINT(%9)<%0>
  36. // Set up a fake callback to test.
  37. #define ALS_R_FakeCallback 708
  38. #define ALS_DO_FakeCallback<%0> %0<FakeCallback,isfi>(more:playerid,string:text[],Float:pos,end:last)
  39. Test:y_als_Fake()
  40. {
  41. // Test that the defines for our fake callback are set up correctly (and the
  42. // print macro at the same time).
  43. new
  44. playerid = 709,
  45. text[] = "T_E_X_T_",
  46. Float:pos = 710.017,
  47. last = 711;
  48. // Floats don't print quite exactly.
  49. __PRINT<FakeCallback, "OnFakeCallback(709, T_E_X_T_, 710.017028, 711)">
  50. }
  51. static stock y_als_DoCall(playerid, text[], Float:pos, last)
  52. {
  53. ALS_CALL<FakeCallback>
  54. }
  55. Test:y_als_Call()
  56. {
  57. // Test the "ALS_CALL" macro.
  58. ASSERT(y_als_DoCall(6000, "", 0.0, 0) == 6000);
  59. }
  60. static stock y_als_DoGet(playerid, text[], Float:pos, last)
  61. {
  62. new
  63. ret = ALS_GET<FakeCallback>
  64. ASSERT(ret == playerid);
  65. //return ret;
  66. }
  67. Test:y_als_Get()
  68. {
  69. // Test the "ALS_GET" macro.
  70. y_als_DoGet(6003, "", 0.0, 0);
  71. }
  72. // The original version.
  73. forward OnFakeCallback(playerid, text[], Float:pos, last);
  74. public OnFakeCallback(playerid, text[], Float:pos, last)
  75. {
  76. return last;
  77. }
  78. // Forward our callback.
  79. ALS_FORWARD<FakeCallback>
  80. #define OnFakeCallback ALS_MAKE<..._OnFakeCallback>
  81. public OnFakeCallback(playerid, text[], Float:pos, last)
  82. {
  83. return playerid;
  84. }
  85. Test:y_als_call()
  86. {
  87. // Test that "call" calls the original one, not the latest one.
  88. new
  89. ret;
  90. ret = call OnFakeCallback(6010, NULL, 0.0, 6011);
  91. ASSERT(ret == 6011);
  92. }
  93. Test:y_als_Generation()
  94. {
  95. // Test all default callbacks.
  96. new
  97. playerid = 42;
  98. __PRINT<ScriptInit, "OnScriptInit()">
  99. __PRINT<ScriptExit, "OnScriptExit()">
  100. __PRINT<GameModeInit, "OnGameModeInit()">
  101. __PRINT<GameModeExit, "OnGameModeExit()">
  102. __PRINT<FilterScriptInit, "OnFilterScriptInit()">
  103. __PRINT<FilterScriptExit, "OnFilterScriptExit()">
  104. __PRINT<PlayerConnect, "OnPlayerConnect(42)">
  105. new
  106. reason = 11;
  107. __PRINT<PlayerDisconnect, "OnPlayerDisconnect(42, 11)">
  108. __PRINT<PlayerSpawn, "OnPlayerSpawn(42)">
  109. new
  110. killerid = INVALID_PLAYER_ID;
  111. ASSERT(INVALID_PLAYER_ID == 65535);
  112. __PRINT<PlayerDeath, "OnPlayerDeath(42, 65535, 11)">
  113. new
  114. vehicleid = 606;
  115. __PRINT<VehicleSpawn, "OnVehicleSpawn(606)">
  116. __PRINT<VehicleDeath, "OnVehicleDeath(606, 65535)">
  117. new
  118. text[] = "Hello There!";
  119. __PRINT<PlayerText, "OnPlayerText(42, Hello There!)">
  120. new
  121. cmdtext[] = "/help";
  122. __PRINT<PlayerCommandText, "OnPlayerCommandText(42, /help)">
  123. new
  124. classid = 101;
  125. __PRINT<PlayerRequestClass, "OnPlayerRequestClass(42, 101)">
  126. new
  127. ispassenger = 99;
  128. __PRINT<PlayerEnterVehicle, "OnPlayerEnterVehicle(42, 606, 99)">
  129. __PRINT<PlayerExitVehicle, "OnPlayerExitVehicle(42, 606)">
  130. new
  131. newstate = 1,
  132. oldstate = 3;
  133. __PRINT<PlayerStateChange, "OnPlayerStateChange(42, 1, 3)">
  134. __PRINT<PlayerEnterCheckpoint, "OnPlayerEnterCheckpoint(42)">
  135. __PRINT<PlayerLeaveCheckpoint, "OnPlayerLeaveCheckpoint(42)">
  136. __PRINT<PlayerEnterRaceCheckpoint, "OnPlayerEnterRaceCheckpoint(42)">
  137. __PRINT<PlayerLeaveRaceCheckpoint, "OnPlayerLeaveRaceCheckpoint(42)">
  138. new
  139. cmd[] = "changemode lvdm";
  140. __PRINT<RconCommand, "OnRconCommand(changemode lvdm)">
  141. __PRINT<PlayerRequestSpawn, "OnPlayerRequestSpawn(42)">
  142. new
  143. objectid = 1234;
  144. __PRINT<ObjectMoved, "OnObjectMoved(1234)">
  145. __PRINT<PlayerObjectMoved, "OnPlayerObjectMoved(42, 1234)">
  146. new
  147. pickupid = 4321;
  148. __PRINT<PlayerPickUpPickup, "OnPlayerPickUpPickup(42, 4321)">
  149. new
  150. componentid = 77;
  151. __PRINT<VehicleMod, "OnVehicleMod(42, 606, 77)">
  152. new
  153. enterexit = 0,
  154. interiorid = 10;
  155. __PRINT<EnterExitModShop, "OnEnterExitModShop(42, 0, 10)">
  156. new
  157. paintjobid = 654;
  158. __PRINT<VehiclePaintjob, "OnVehiclePaintjob(42, 606, 654)">
  159. new
  160. color1 = 421,
  161. color2 = 422;
  162. __PRINT<VehicleRespray, "OnVehicleRespray(42, 606, 421, 422)">
  163. __PRINT<VehicleDamageStatusUpdate, "OnVehicleDamageStatusUpdate(606, 42)">
  164. new
  165. row = 12;
  166. __PRINT<PlayerSelectedMenuRow, "OnPlayerSelectedMenuRow(42, 12)">
  167. __PRINT<PlayerExitedMenu, "OnPlayerExitedMenu(42)">
  168. new
  169. newinteriorid = 88,
  170. oldinteriorid = 89;
  171. __PRINT<PlayerInteriorChange, "OnPlayerInteriorChange(42, 88, 89)">
  172. new
  173. newkeys = 4,
  174. oldkeys = 5;
  175. __PRINT<PlayerKeyStateChange, "OnPlayerKeyStateChange(42, 4, 5)">
  176. new
  177. ip[] = "IP HERE",
  178. password[] = "PASS HERE",
  179. success = -11;
  180. __PRINT<RconLoginAttempt, "OnRconLoginAttempt(IP HERE, PASS HERE, -11)">
  181. __PRINT<PlayerUpdate, "OnPlayerUpdate(42)">
  182. new
  183. forplayerid = 43;
  184. __PRINT<PlayerStreamIn, "OnPlayerStreamIn(42, 43)">
  185. __PRINT<PlayerStreamOut, "OnPlayerStreamOut(42, 43)">
  186. __PRINT<VehicleStreamIn, "OnVehicleStreamIn(606, 43)">
  187. __PRINT<VehicleStreamOut, "OnVehicleStreamOut(606, 43)">
  188. new
  189. dialogid = 500,
  190. response = 404,
  191. listitem = 200,
  192. inputtext[] = "SOME TEXT";
  193. __PRINT<DialogResponse, "OnDialogResponse(42, 500, 404, 200, SOME TEXT)">
  194. new
  195. clickedplayerid = 44,
  196. source = -20;
  197. __PRINT<PlayerClickPlayer, "OnPlayerClickPlayer(42, 44, -20)">
  198. new
  199. uid = 4242;
  200. __PRINT<PlayerLogin, "OnPlayerLogin(42, 4242)">
  201. __PRINT<PlayerLogout, "OnPlayerLogout(42, 4242)">
  202. new
  203. damagedid = 45,
  204. Float:amount = 1.2,
  205. weaponid = 50;
  206. __PRINT<PlayerGiveDamage, "OnPlayerGiveDamage(42, 45, 1.200000, 50)">
  207. new
  208. issuerid = 46;
  209. __PRINT<PlayerTakeDamage, "OnPlayerTakeDamage(42, 46, 1.200000, 50)">
  210. new
  211. Float:fX = 10.24,
  212. Float:fY = 11.34,
  213. Float:fZ = 12.44;
  214. __PRINT<PlayerClickMap, "OnPlayerClickMap(42, 10.239999, 11.340000, 12.439999)">
  215. __PRINT<PlayerCommandReceived, "OnPlayerCommandReceived(42, /help)">
  216. __PRINT<PlayerCommandPerformed, "OnPlayerCommandPerformed(42, /help, -11)">
  217. new
  218. passenger_seat = 70;
  219. __PRINT<UnoccupiedVehicleUpdate, "OnUnoccupiedVehicleUpdate(606, 42, 70)">
  220. new
  221. clickedid = 90;
  222. // Actually revealed an issue in y_als with ALL tags being interpreted as
  223. // floats instead of just tagged integers.
  224. __PRINT<PlayerClickTextDraw, "OnPlayerClickTextDraw(42, 90)">
  225. new
  226. playertextid = 92;
  227. __PRINT<PlayerClickPlayerTextDraw, "OnPlayerClickPlayerTextDraw(42, 92)">
  228. new
  229. playerobject = 2234,
  230. Float:fRotX = 20.24,
  231. Float:fRotY = 21.34,
  232. Float:fRotZ = 22.44;
  233. __PRINT<PlayerEditObject, "OnPlayerEditObject(42, 2234, 1234, 404, 10.239999, 11.340000, 12.439999, 20.239999, 21.340000, 22.440000)">
  234. #if 0
  235. // This ends up too long to compile :(.
  236. new
  237. index = 650,
  238. modelid = 651,
  239. boneid = 652,
  240. Float:fOffsetX = 101.01,
  241. Float:fOffsetY = 202.02,
  242. Float:fOffsetZ = 303.03,
  243. Float:fScaleX = 404.04,
  244. Float:fScaleY = 505.05,
  245. Float:fScaleZ = 606.06;
  246. __PRINT<PlayerEditAttachedObject, "OnPlayerEditAttachedObject(42, 404, 650, 651, 652, 20.240000, 21.340000, 22.440000, 101.010000, 202.020000, 303.030000, 404.040000, 505.050000, 606.060000)">
  247. #endif
  248. }
  249. #undef __ALS_PS_more
  250. #undef __ALS_PS_string
  251. #undef __ALS_PS_tag
  252. #undef __ALS_PS_end
  253. #undef __ALS_PS_none
  254. #undef __ALS_PS_end_string
  255. #undef __ALS_PS_end_tag
  256. #undef __ALS_R2_more
  257. #undef __ALS_R2_string
  258. #undef __ALS_R2_tag
  259. #undef __ALS_R2_end
  260. #undef __ALS_R2_none
  261. #undef __ALS_R2_end_string
  262. #undef __ALS_R2_end_tag
  263. #undef __DO_PRINT
  264. #undef __PRINT
  265. #if defined __ALS_MAKE_DEFINED
  266. #undef ALS_MAKE
  267. #undef __ALS_MAKE_DEFINED
  268. #endif
  269. #undef ALS_R_FakeCallback
  270. #undef ALS_DO_FakeCallback
  271. #undef OnFakeCallback