tests.inc 9.3 KB

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