1
0

tests.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*
  2. Legal:
  3. Version: MPL 1.1
  4. The contents of this file are subject to the Mozilla Public License Version
  5. 1.1 the "License"; you may not use this file except in compliance with
  6. the License. You may obtain a copy of the License at
  7. http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS IS" basis,
  9. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  10. for the specific language governing rights and limitations under the
  11. License.
  12. The Original Code is the YSI framework.
  13. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  14. Portions created by the Initial Developer are Copyright C 2011
  15. the Initial Developer. All Rights Reserved.
  16. Contributors:
  17. Y_Less
  18. koolk
  19. JoeBullet/Google63
  20. g_aSlice/Slice
  21. Misiur
  22. samphunter
  23. tianmeta
  24. maddinat0r
  25. spacemud
  26. Crayder
  27. Dayvison
  28. Ahmad45123
  29. Zeex
  30. irinel1996
  31. Yiin-
  32. Chaprnks
  33. Konstantinos
  34. Masterchen09
  35. Southclaws
  36. PatchwerkQWER
  37. m0k1
  38. paulommu
  39. udan111
  40. Thanks:
  41. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  42. ZeeX - Very productive conversations.
  43. koolk - IsPlayerinAreaEx code.
  44. TheAlpha - Danish translation.
  45. breadfish - German translation.
  46. Fireburn - Dutch translation.
  47. yom - French translation.
  48. 50p - Polish translation.
  49. Zamaroht - Spanish translation.
  50. Los - Portuguese translation.
  51. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
  52. me to strive to better.
  53. Pixels^ - Running XScripters where the idea was born.
  54. Matite - Pestering me to release it and using it.
  55. Very special thanks to:
  56. Thiadmer - PAWN, whose limits continue to amaze me!
  57. Kye/Kalcor - SA:MP.
  58. SA:MP Team past, present and future - SA:MP.
  59. Optional plugins:
  60. Gamer_Z - GPS.
  61. Incognito - Streamer.
  62. Me - sscanf2, fixes2, Whirlpool.
  63. */
  64. #if !defined ALS_MAKE
  65. #define ALS_MAKE<%0...%1> %0__T_%1
  66. #define __ALS_MAKE_DEFINED
  67. #endif
  68. static stock y_als_Print(result[], fmat[], va_args<>)
  69. {
  70. // This function formats the incoming data and compares it to the reference.
  71. static
  72. msg[256];
  73. //printf("ONE: %d", numargs());
  74. // printf("\"%s\" \"%s\"", result, fmat);
  75. //printf("%s", result);
  76. //printf("%s", fmat);
  77. //printf("%s", msg);
  78. // msg[0] = '\0';
  79. // format(msg, sizeof (msg), fmat, 0);
  80. va_format(msg, sizeof (msg), fmat, va_start<2>);
  81. //printf("TWO");
  82. //printf("%s", msg);
  83. new
  84. bool:cmp = !strcmp(result, msg);
  85. //va_format(msg, sizeof (msg), fmat, va_start<2>);
  86. //printf("%s", msg);
  87. //printf("%s %s", result, fmat);
  88. format(msg, sizeof (msg), "\"%s\" != \"%s\" (%d)", result, msg, cmp);
  89. Testing_Test(cmp, msg);
  90. //printf("THREE");
  91. //printf("%s", msg);
  92. }
  93. // Defines for our "__PRINT" macro, see:
  94. // http://ysi.wikia.com/wiki/Library:YSI\y_als
  95. #define __ALS_PS_more:%0, "%d, "__ALS_PS_
  96. #define __ALS_PS_string:%0[], "%s, "__ALS_PS_
  97. #define __ALS_PS_Float:%0, "%f, "__ALS_PS_
  98. #define __ALS_PS_tag:%3:%0, "%d, "__ALS_PS_
  99. #define __ALS_PS_end:%0) "%d"
  100. #define __ALS_PS_none:%0)
  101. #define __ALS_PS_end_string:%0[]) "%s"
  102. #define __ALS_PS_end_Float:%0) "%f"
  103. #define __ALS_PS_end_tag:%3:%0) "%d"
  104. #define __ALS_R2_more:%0, ,%0 __ALS_R2_
  105. #define __ALS_R2_string:%0[], ,((%0[0])?(%0):NULL) __ALS_R2_
  106. #define __ALS_R2_Float:%0, ,(_:%0) __ALS_R2_
  107. #define __ALS_R2_tag:%3:%0, ,(_:%0) __ALS_R2_
  108. #define __ALS_R2_end:%0) ,%0)
  109. #define __ALS_R2_none:) )
  110. #define __ALS_R2_end_string:%0[]) ,((%0[0])?(%0):NULL))
  111. #define __ALS_R2_end_Float:%0) ,(_:%0))
  112. #define __ALS_R2_end_tag:%3:%0) ,(_:%0))
  113. #define __DO_PRINT(%9)<%0,%1>(%2) y_als_Print(%9,"On"#%0"("__ALS_PS_%2)")"__ALS_R2_%2);
  114. #define __PRINT<%0,%9> ALS_DO:__DO_PRINT(%9)<%0>
  115. // Set up a fake callback to test.
  116. #define ALS_R_FakeCallback 708
  117. #define ALS_DO_FakeCallback<%0> %0<FakeCallback,isfi>(more:playerid,string:text[],Float:pos,end:last)
  118. Test:y_als_Fake()
  119. {
  120. // Test that the defines for our fake callback are set up correctly (and the
  121. // print macro at the same time).
  122. new
  123. playerid = 709,
  124. text[] = "T_E_X_T_",
  125. Float:pos = 710.017,
  126. last = 711;
  127. // Floats don't print quite exactly.
  128. __PRINT<FakeCallback, "OnFakeCallback(709, T_E_X_T_, 710.017028, 711)">
  129. }
  130. static stock y_als_DoCall(playerid, text[], Float:pos, last)
  131. {
  132. ALS_CALL<FakeCallback>
  133. }
  134. Test:y_als_Call()
  135. {
  136. // Test the "ALS_CALL" macro.
  137. ASSERT(y_als_DoCall(6000, "", 0.0, 0) == 6000);
  138. }
  139. static stock y_als_DoGet(playerid, text[], Float:pos, last)
  140. {
  141. new
  142. ret = ALS_GET<FakeCallback>
  143. ASSERT(ret == playerid);
  144. //return ret;
  145. }
  146. Test:y_als_Get()
  147. {
  148. // Test the "ALS_GET" macro.
  149. y_als_DoGet(6003, "", 0.0, 0);
  150. }
  151. // The original version.
  152. forward OnFakeCallback(playerid, text[], Float:pos, last);
  153. public OnFakeCallback(playerid, text[], Float:pos, last)
  154. {
  155. return last;
  156. }
  157. // Forward our callback.
  158. ALS_FORWARD<FakeCallback>
  159. #define OnFakeCallback ALS_MAKE<..._OnFakeCallback>
  160. public OnFakeCallback(playerid, text[], Float:pos, last)
  161. {
  162. return playerid;
  163. }
  164. Test:y_als_call()
  165. {
  166. // Test that "call" calls the original one, not the latest one.
  167. new
  168. ret;
  169. ret = call OnFakeCallback(6010, NULL, 0.0, 6011);
  170. ASSERT(ret == 6011);
  171. }
  172. Test:y_als_Generation()
  173. {
  174. // Test all default callbacks.
  175. new
  176. playerid = 42;
  177. __PRINT<ScriptInit, "OnScriptInit()">
  178. __PRINT<ScriptExit, "OnScriptExit()">
  179. __PRINT<GameModeInit, "OnGameModeInit()">
  180. __PRINT<GameModeExit, "OnGameModeExit()">
  181. __PRINT<FilterScriptInit, "OnFilterScriptInit()">
  182. __PRINT<FilterScriptExit, "OnFilterScriptExit()">
  183. __PRINT<PlayerConnect, "OnPlayerConnect(42)">
  184. new
  185. reason = 11;
  186. __PRINT<PlayerDisconnect, "OnPlayerDisconnect(42, 11)">
  187. __PRINT<PlayerSpawn, "OnPlayerSpawn(42)">
  188. new
  189. killerid = INVALID_PLAYER_ID;
  190. ASSERT(INVALID_PLAYER_ID == 65535);
  191. __PRINT<PlayerDeath, "OnPlayerDeath(42, 65535, 11)">
  192. new
  193. vehicleid = 606;
  194. __PRINT<VehicleSpawn, "OnVehicleSpawn(606)">
  195. __PRINT<VehicleDeath, "OnVehicleDeath(606, 65535)">
  196. new
  197. text[] = "Hello There!";
  198. __PRINT<PlayerText, "OnPlayerText(42, Hello There!)">
  199. new
  200. cmdtext[] = "/help";
  201. __PRINT<PlayerCommandText, "OnPlayerCommandText(42, /help)">
  202. new
  203. classid = 101;
  204. __PRINT<PlayerRequestClass, "OnPlayerRequestClass(42, 101)">
  205. new
  206. ispassenger = 99;
  207. __PRINT<PlayerEnterVehicle, "OnPlayerEnterVehicle(42, 606, 99)">
  208. __PRINT<PlayerExitVehicle, "OnPlayerExitVehicle(42, 606)">
  209. new
  210. newstate = 1,
  211. oldstate = 3;
  212. __PRINT<PlayerStateChange, "OnPlayerStateChange(42, 1, 3)">
  213. __PRINT<PlayerEnterCheckpoint, "OnPlayerEnterCheckpoint(42)">
  214. __PRINT<PlayerLeaveCheckpoint, "OnPlayerLeaveCheckpoint(42)">
  215. __PRINT<PlayerEnterRaceCheckpoint, "OnPlayerEnterRaceCheckpoint(42)">
  216. __PRINT<PlayerLeaveRaceCheckpoint, "OnPlayerLeaveRaceCheckpoint(42)">
  217. new
  218. cmd[] = "changemode lvdm";
  219. __PRINT<RconCommand, "OnRconCommand(changemode lvdm)">
  220. __PRINT<PlayerRequestSpawn, "OnPlayerRequestSpawn(42)">
  221. new
  222. objectid = 1234;
  223. __PRINT<ObjectMoved, "OnObjectMoved(1234)">
  224. __PRINT<PlayerObjectMoved, "OnPlayerObjectMoved(42, 1234)">
  225. new
  226. pickupid = 4321;
  227. __PRINT<PlayerPickUpPickup, "OnPlayerPickUpPickup(42, 4321)">
  228. new
  229. componentid = 77;
  230. __PRINT<VehicleMod, "OnVehicleMod(42, 606, 77)">
  231. new
  232. enterexit = 0,
  233. interiorid = 10;
  234. __PRINT<EnterExitModShop, "OnEnterExitModShop(42, 0, 10)">
  235. new
  236. paintjobid = 654;
  237. __PRINT<VehiclePaintjob, "OnVehiclePaintjob(42, 606, 654)">
  238. new
  239. color1 = 421,
  240. color2 = 422;
  241. __PRINT<VehicleRespray, "OnVehicleRespray(42, 606, 421, 422)">
  242. __PRINT<VehicleDamageStatusUpdate, "OnVehicleDamageStatusUpdate(606, 42)">
  243. new
  244. row = 12;
  245. __PRINT<PlayerSelectedMenuRow, "OnPlayerSelectedMenuRow(42, 12)">
  246. __PRINT<PlayerExitedMenu, "OnPlayerExitedMenu(42)">
  247. new
  248. newinteriorid = 88,
  249. oldinteriorid = 89;
  250. __PRINT<PlayerInteriorChange, "OnPlayerInteriorChange(42, 88, 89)">
  251. new
  252. newkeys = 4,
  253. oldkeys = 5;
  254. __PRINT<PlayerKeyStateChange, "OnPlayerKeyStateChange(42, 4, 5)">
  255. new
  256. ip[] = "IP HERE",
  257. password[] = "PASS HERE",
  258. success = -11;
  259. __PRINT<RconLoginAttempt, "OnRconLoginAttempt(IP HERE, PASS HERE, -11)">
  260. __PRINT<PlayerUpdate, "OnPlayerUpdate(42)">
  261. new
  262. forplayerid = 43;
  263. __PRINT<PlayerStreamIn, "OnPlayerStreamIn(42, 43)">
  264. __PRINT<PlayerStreamOut, "OnPlayerStreamOut(42, 43)">
  265. __PRINT<VehicleStreamIn, "OnVehicleStreamIn(606, 43)">
  266. __PRINT<VehicleStreamOut, "OnVehicleStreamOut(606, 43)">
  267. new
  268. dialogid = 500,
  269. response = 404,
  270. listitem = 200,
  271. inputtext[] = "SOME TEXT";
  272. __PRINT<DialogResponse, "OnDialogResponse(42, 500, 404, 200, SOME TEXT)">
  273. new
  274. clickedplayerid = 44,
  275. source = -20;
  276. __PRINT<PlayerClickPlayer, "OnPlayerClickPlayer(42, 44, -20)">
  277. new
  278. uid = 4242;
  279. __PRINT<PlayerLogin, "OnPlayerLogin(42, 4242)">
  280. __PRINT<PlayerLogout, "OnPlayerLogout(42, 4242)">
  281. new
  282. damagedid = 45,
  283. Float:amount = 1.2,
  284. weaponid = 50,
  285. bodypart = 2;
  286. #if defined GetPlayerLastShotVectors
  287. __PRINT<PlayerGiveDamage, "OnPlayerGiveDamage(42, 45, 1.200000, 50, 2)">
  288. #else
  289. __PRINT<PlayerGiveDamage, "OnPlayerGiveDamage(42, 45, 1.200000, 50)">
  290. #pragma unused bodypart
  291. #endif
  292. new
  293. issuerid = 46;
  294. #if defined GetPlayerLastShotVectors
  295. __PRINT<PlayerTakeDamage, "OnPlayerTakeDamage(42, 46, 1.200000, 50, 2)">
  296. #else
  297. __PRINT<PlayerTakeDamage, "OnPlayerTakeDamage(42, 46, 1.200000, 50)">
  298. #pragma unused bodypart
  299. #endif
  300. new
  301. Float:fX = 10.24,
  302. Float:fY = 11.34,
  303. Float:fZ = 12.44;
  304. __PRINT<PlayerClickMap, "OnPlayerClickMap(42, 10.239999, 11.340000, 12.439999)">
  305. __PRINT<PlayerCommandReceived, "OnPlayerCommandReceived(42, /help)">
  306. __PRINT<PlayerCommandPerformed, "OnPlayerCommandPerformed(42, /help, -11)">
  307. new
  308. passenger_seat = 70,
  309. Float:new_x = 3.3,
  310. Float:new_y = 4.4,
  311. Float:new_z = 5.5;
  312. #if defined GetServerTickRate
  313. __PRINT<UnoccupiedVehicleUpdate, "OnUnoccupiedVehicleUpdate(606, 42, 70, 3.299999, 4.400000, 5.500000)">
  314. #else
  315. __PRINT<UnoccupiedVehicleUpdate, "OnUnoccupiedVehicleUpdate(606, 42, 70)">
  316. #pragma unused new_x, new_y, new_z
  317. #endif
  318. new
  319. clickedid = 90;
  320. // Actually revealed an issue in y_als with ALL tags being interpreted as
  321. // floats instead of just tagged integers.
  322. __PRINT<PlayerClickTextDraw, "OnPlayerClickTextDraw(42, 90)">
  323. new
  324. playertextid = 92;
  325. __PRINT<PlayerClickPlayerTextDraw, "OnPlayerClickPlayerTextDraw(42, 92)">
  326. new
  327. playerobject = 2234,
  328. Float:fRotX = 20.24,
  329. Float:fRotY = 21.34,
  330. Float:fRotZ = 22.44;
  331. __PRINT<PlayerEditObject, "OnPlayerEditObject(42, 2234, 1234, 404, 10.239999, 11.340000, 12.439999, 20.239999, 21.340000, 22.440000)">
  332. #if 0
  333. // This ends up too long to compile :(.
  334. new
  335. index = 650,
  336. modelid = 651,
  337. boneid = 652,
  338. Float:fOffsetX = 101.01,
  339. Float:fOffsetY = 202.02,
  340. Float:fOffsetZ = 303.03,
  341. Float:fScaleX = 404.04,
  342. Float:fScaleY = 505.05,
  343. Float:fScaleZ = 606.06;
  344. __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)">
  345. #endif
  346. }
  347. #undef __ALS_PS_more
  348. #undef __ALS_PS_string
  349. #undef __ALS_PS_tag
  350. #undef __ALS_PS_end
  351. #undef __ALS_PS_none
  352. #undef __ALS_PS_end_string
  353. #undef __ALS_PS_end_tag
  354. #undef __ALS_R2_more
  355. #undef __ALS_R2_string
  356. #undef __ALS_R2_tag
  357. #undef __ALS_R2_end
  358. #undef __ALS_R2_none
  359. #undef __ALS_R2_end_string
  360. #undef __ALS_R2_end_tag
  361. #undef __DO_PRINT
  362. #undef __PRINT
  363. #if defined __ALS_MAKE_DEFINED
  364. #undef ALS_MAKE
  365. #undef __ALS_MAKE_DEFINED
  366. #endif
  367. #undef ALS_R_FakeCallback
  368. #undef ALS_DO_FakeCallback
  369. #undef OnFakeCallback