1
0

tests.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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. static
  65. YSI_g_sValue;
  66. #if defined YSI_FAILING_TESTS
  67. DEFINE_HOOK_REPLACEMENT(VeryLongTarget_, YyYy);
  68. hook y_hooks_YyYy0()
  69. {
  70. // The length after replacement here will be longer than the hook name,
  71. // even with prefix/suffixes. This means you can't generate the
  72. // original name because there is no original.
  73. ASSERT(true);
  74. YSI_g_sValue = 101;
  75. }
  76. hook y_hooks_YyYy1()
  77. {
  78. // The length after replacement here will be longer than the hook name,
  79. // even with prefix/suffixes. This means you can't generate the
  80. // original name because there is no original.
  81. ASSERT(true);
  82. YSI_g_sValue = 202;
  83. }
  84. hook y_hooks_YyYz1()
  85. {
  86. // Will come very next in the header.
  87. ASSERT(true);
  88. YSI_g_sValue = 303;
  89. }
  90. forward y_hooks_VeryLongTarget_0();
  91. public y_hooks_VeryLongTarget_0()
  92. {
  93. // This one should work, because we have the original function to use
  94. // for a pointer, not a newly generated version.
  95. ASSERT(YSI_g_sValue == 101);
  96. YSI_g_sValue += 404;
  97. }
  98. Test:y_hooks_TooLongReplacements()
  99. {
  100. YSI_g_sValue = 0;
  101. CallLocalFunction("y_hooks_VeryLongTarget_0", "");
  102. ASSERT(YSI_g_sValue == 505);
  103. YSI_g_sValue = 0;
  104. CallLocalFunction("y_hooks_YyYz1", "");
  105. ASSERT(YSI_g_sValue == 303);
  106. YSI_g_sValue = 0;
  107. // Currently fails.
  108. CallLocalFunction("y_hooks_VeryLongTarget_1", "");
  109. ASSERT(YSI_g_sValue == 202);
  110. }
  111. #endif
  112. hook Ony_hooksShortUpdate()
  113. {
  114. ++YSI_g_sValue;
  115. }
  116. hook Ony_hooksShortUpd()
  117. {
  118. ++YSI_g_sValue;
  119. }
  120. Test:Ony_hooksShortUpdate()
  121. {
  122. YSI_g_sValue = 0;
  123. CallLocalFunction("Ony_hooksShortUpdate", "");
  124. ASSERT(YSI_g_sValue == 2);
  125. }
  126. #if defined YSI_FAILING_TESTS
  127. DEFINE_HOOK_REPLACEMENT(TTTTT_YYYYY, YHook);
  128. forward Ony_hooksTTTTT_YYYYY_WtExtras();
  129. hook Ony_hooksYHook()
  130. {
  131. ++YSI_g_sValue;
  132. }
  133. hook Ony_hooksTTTTT_YYYYY()
  134. {
  135. ++YSI_g_sValue;
  136. }
  137. Test:y_hooksReplacement2()
  138. {
  139. YSI_g_sValue = 0;
  140. CallLocalFunction("Ony_hooksTTTTT_YYYYY", "");
  141. ASSERT(YSI_g_sValue == 2);
  142. }
  143. public Ony_hooksTTTTT_YYYYY_WtExtras()
  144. {
  145. ++YSI_g_sValue;
  146. }
  147. hook Ony_hooksYHook_WtExtras()
  148. {
  149. ++YSI_g_sValue;
  150. }
  151. Test:y_hooksReplacement3()
  152. {
  153. YSI_g_sValue = 0;
  154. CallLocalFunction("Ony_hooksTTTTT_YYYYY_WtExtras", "");
  155. ASSERT(YSI_g_sValue == 2);
  156. }
  157. #endif
  158. forward Ony_hooksTest2(cmd[]);
  159. hook Ony_hooksTest2@000(cmd[])
  160. {
  161. ++YSI_g_sValue;
  162. return 1;
  163. }
  164. hook Ony_hooksTest2@001(cmd[])
  165. {
  166. // Called second due to forced orderings.
  167. ++YSI_g_sValue;
  168. return 1;
  169. }
  170. public Ony_hooksTest2(cmd[])
  171. {
  172. // Called second due to forced orderings.
  173. //if (YSI_g_sValue) return YSI_g_sValue - 7;
  174. return 1;
  175. }
  176. Test:y_hooks_Ony_hooksTest2()
  177. {
  178. // Check both hooks are called.
  179. YSI_g_sValue = 0;
  180. ASSERT(CallLocalFunction("Ony_hooksTest2", "s", "IGNORE_ME") != 0);
  181. ASSERT(YSI_g_sValue == 2);
  182. YSI_g_sValue = 0;
  183. }
  184. forward Ony_hooksTest3(cmd[]);
  185. hook Ony_hooksTest3@000(cmd[])
  186. {
  187. ++YSI_g_sValue;
  188. //printf("a");
  189. return 1;
  190. }
  191. hook Ony_hooksTest3@001(cmd[])
  192. {
  193. // Called second due to forced orderings.
  194. ++YSI_g_sValue;
  195. //printf("b");
  196. return 1;
  197. }
  198. Test:y_hooks_Ony_hooksTest3()
  199. {
  200. // Check both hooks are called.
  201. YSI_g_sValue = 0;
  202. ASSERT(CallLocalFunction("Ony_hooksTest3", "s", "IGNORE_ME") != 0);
  203. ASSERT(YSI_g_sValue == 2);
  204. YSI_g_sValue = 0;
  205. }
  206. forward Ony_hooksTest1(cmd[]);
  207. hook Ony_hooksTest1@000(cmd[])
  208. {
  209. ++YSI_g_sValue;
  210. return 1;
  211. }
  212. hook Ony_hooksTest1@001(cmd[])
  213. {
  214. // Called second due to forced orderings.
  215. ++YSI_g_sValue;
  216. return 0;
  217. }
  218. Test:y_hooks_Ony_hooksTest1()
  219. {
  220. // Check both hooks are called.
  221. YSI_g_sValue = 0;
  222. ASSERT(CallLocalFunction("Ony_hooksTest1", "s", "IGNORE_ME") == 0);
  223. ASSERT(YSI_g_sValue == 2);
  224. YSI_g_sValue = 0;
  225. }
  226. forward Ony_hooksTest4(cmd[]);
  227. hook Ony_hooksTest4@000(cmd[])
  228. {
  229. ++YSI_g_sValue;
  230. return -1;
  231. }
  232. hook Ony_hooksTest4@001(cmd[])
  233. {
  234. // Called second due to forced orderings.
  235. ++YSI_g_sValue;
  236. return 0;
  237. }
  238. Test:y_hooks_Ony_hooksTest4()
  239. {
  240. // Check only one hook is called.
  241. YSI_g_sValue = 0;
  242. ASSERT(CallLocalFunction("Ony_hooksTest4", "s", "IGNORE_ME") == 0);
  243. ASSERT(YSI_g_sValue == 1);
  244. YSI_g_sValue = 0;
  245. }
  246. forward Ony_hooksTest5(cmd[]);
  247. hook Ony_hooksTest5@000(cmd[])
  248. {
  249. ++YSI_g_sValue;
  250. return -2;
  251. }
  252. hook Ony_hooksTest5@001(cmd[])
  253. {
  254. // Called second due to forced orderings.
  255. ++YSI_g_sValue;
  256. return 0;
  257. }
  258. Test:y_hooks_Ony_hooksTest5()
  259. {
  260. // Check only one hook is called.
  261. YSI_g_sValue = 0;
  262. ASSERT(CallLocalFunction("Ony_hooksTest5", "s", "IGNORE_ME") == 1);
  263. ASSERT(YSI_g_sValue == 1);
  264. YSI_g_sValue = 0;
  265. }
  266. static stock y_hooks_funcidx2(str[])
  267. {
  268. new
  269. func[32],
  270. buf,
  271. idx;
  272. while ((idx = AMX_GetPublicName(idx, func, str)))
  273. {
  274. if (!strcmp(func, str))
  275. {
  276. AMX_GetPublicEntry(idx - 1, buf);
  277. return buf;
  278. }
  279. }
  280. return -1;
  281. }
  282. forward y_hooks_Invalidate1();
  283. public y_hooks_Invalidate1() {}
  284. Test:y_hooks_Invalidate1()
  285. {
  286. ASSERT(funcidx("y_hooks_Invalidate1") != -1);
  287. Hooks_InvalidateName(y_hooks_funcidx2("y_hooks_Invalidate1"));
  288. Hooks_SortPublics();
  289. ASSERT(funcidx("y_hooks_Invalidate1") == -1);
  290. }
  291. forward y_hooks_Invalidate2();
  292. public y_hooks_Invalidate2() {}
  293. forward y_hooks_Invalidate3();
  294. public y_hooks_Invalidate3() {}
  295. Test:y_hooks_Invalidate23()
  296. {
  297. new
  298. base0,
  299. count0;
  300. AMX_GetBaseCount(AMX_TABLE_PUBLICS, base0, count0);
  301. ASSERT(funcidx("y_hooks_Invalidate2") != -1);
  302. ASSERT(funcidx("y_hooks_Invalidate3") != -1);
  303. Hooks_InvalidateName(y_hooks_funcidx2("y_hooks_Invalidate2"));
  304. Hooks_InvalidateName(y_hooks_funcidx2("y_hooks_Invalidate3"));
  305. Hooks_SortPublics();
  306. ASSERT(funcidx("y_hooks_Invalidate2") == -1);
  307. ASSERT(funcidx("y_hooks_Invalidate3") == -1);
  308. new
  309. base1,
  310. count1;
  311. AMX_GetBaseCount(AMX_TABLE_PUBLICS, base1, count1);
  312. ASSERT(base1 > base0);
  313. ASSERT(count1 < count0);
  314. }
  315. Test:y_hooks_IsolateName1()
  316. {
  317. new
  318. name[32];
  319. name = "@yH_Hello@Other";
  320. Hooks_IsolateName(name);
  321. ASSERT_FALSE(strcmp(name, "Hello"));
  322. name = "@yH_Hi@@Other";
  323. Hooks_IsolateName(name);
  324. ASSERT_FALSE(strcmp(name, "Hi"));
  325. name = "@yH_No@Other@More";
  326. Hooks_IsolateName(name);
  327. ASSERT_FALSE(strcmp(name, "No"));
  328. name = "@yH_Yes_Other@N";
  329. Hooks_IsolateName(name);
  330. ASSERT_FALSE(strcmp(name, "Yes_Other"));
  331. }
  332. Test:y_hooks_IsolateName2()
  333. {
  334. new
  335. func[32];
  336. #define FUNC:%0; func = "_yH@"#%0"@";Hooks_IsolateName(func);ASSERT(!strcmp(#%0, func));
  337. FUNC:A;
  338. FUNC:AAA;
  339. FUNC:AAB;
  340. FUNC:ABA;
  341. FUNC:ABB;
  342. FUNC:aB;
  343. FUNC:ab;
  344. FUNC:Ab;
  345. #undef FUNC
  346. }
  347. static g_y_hooksVar;
  348. Test:y_hooks_Customs()
  349. {
  350. g_y_hooksVar = 0;
  351. CallLocalFunction("y_hooks_MyFunc1", "ii", 4, 5);
  352. ASSERT(g_y_hooksVar == (4 + 5) * 6);
  353. }
  354. forward y_hooks_MyFunc1(a, b);
  355. public y_hooks_MyFunc1(a, b)
  356. {
  357. //printf("Part 1 %d %d", a, b);
  358. g_y_hooksVar += a + b;
  359. }
  360. #tryinclude "..\YSI_Internal\y_unique"
  361. #tryinclude "..\..\YSI_Internal\y_unique"
  362. hook y_hooks_MyFunc1(a, b)
  363. {
  364. //printf("Part 2 %d", a);
  365. g_y_hooksVar += a + b;
  366. }
  367. #tryinclude "..\YSI_Internal\y_unique"
  368. #tryinclude "..\..\YSI_Internal\y_unique"
  369. hook y_hooks_MyFunc1(a, b)
  370. {
  371. //printf("Part 3 %d", b);
  372. g_y_hooksVar += a + b;
  373. }
  374. #tryinclude "..\YSI_Internal\y_unique"
  375. #tryinclude "..\..\YSI_Internal\y_unique"
  376. hook y_hooks_MyFunc1(a, b)
  377. {
  378. //printf("Part 3 %d", b);
  379. g_y_hooksVar += a + b;
  380. }
  381. #tryinclude "..\YSI_Internal\y_unique"
  382. #tryinclude "..\..\YSI_Internal\y_unique"
  383. hook y_hooks_MyFunc1(a, b)
  384. {
  385. //printf("Part 3 %d", b);
  386. g_y_hooksVar += a + b;
  387. }
  388. #tryinclude "..\YSI_Internal\y_unique"
  389. #tryinclude "..\..\YSI_Internal\y_unique"
  390. hook y_hooks_MyFunc1(a, b)
  391. {
  392. //printf("Part 3 %d", b);
  393. g_y_hooksVar += a + b;
  394. }
  395. forward OnPlayerEnterDynamicArea(p, a);
  396. public OnPlayerEnterDynamicArea(p, a) { g_y_hooksVar += 100; }
  397. hook OnPlayerEnterDynArea(p, a) { g_y_hooksVar += 10; }
  398. Test:y_hooks_SpecialCases()
  399. {
  400. g_y_hooksVar = 0;
  401. CallLocalFunction("OnPlayerEnterDynamicArea", "ii", 0, 0);
  402. ASSERT(g_y_hooksVar == 110);
  403. }
  404. Test:Hooks_MakeLongName0()
  405. {
  406. new
  407. name[64];
  408. name = "OnUpd";
  409. ASSERT(Hooks_MakeLongName(name) == 8);
  410. ASSERT(!strcmp(name, "OnUpdate"));
  411. name = "OnUpdD";
  412. ASSERT(Hooks_MakeLongName(name) == 9);
  413. ASSERT(!strcmp(name, "OnUpdateD"));
  414. name = "OnUpda";
  415. ASSERT(Hooks_MakeLongName(name) == 6);
  416. ASSERT(!strcmp(name, "OnUpda"));
  417. }
  418. Test:Hooks_MakeLongName1()
  419. {
  420. new
  421. name[64];
  422. name = "CP";
  423. ASSERT(Hooks_MakeLongName(name) == 10);
  424. ASSERT(!strcmp(name, "Checkpoint"));
  425. name = "TD";
  426. ASSERT(Hooks_MakeLongName(name) == 8);
  427. ASSERT(!strcmp(name, "TextDraw"));
  428. name = "Upd";
  429. ASSERT(Hooks_MakeLongName(name) == 6);
  430. ASSERT(!strcmp(name, "Update"));
  431. name = "Dyn";
  432. ASSERT(Hooks_MakeLongName(name) == 7);
  433. ASSERT(!strcmp(name, "Dynamic"));
  434. name = "Obj";
  435. ASSERT(Hooks_MakeLongName(name) == 6);
  436. ASSERT(!strcmp(name, "Object"));
  437. name = "Cmd";
  438. ASSERT(Hooks_MakeLongName(name) == 7);
  439. ASSERT(!strcmp(name, "Command"));
  440. name = "DynamicCP";
  441. ASSERT(Hooks_MakeLongName(name) == 9);
  442. ASSERT(!strcmp(name, "DynamicCP"));
  443. }
  444. Test:Hooks_MakeLongName2()
  445. {
  446. new
  447. name[64];
  448. name = "OnUpdTDCP";
  449. ASSERT(Hooks_MakeLongName(name) == 26);
  450. ASSERT(!strcmp(name, "OnUpdateTextDrawCheckpoint"));
  451. name = "OnUpdTDObjCmd";
  452. ASSERT(Hooks_MakeLongName(name) == 29);
  453. ASSERT(!strcmp(name, "OnUpdateTextDrawObjectCommand"));
  454. name = "OnUpdTDCPObjCmd";
  455. ASSERT(Hooks_MakeLongName(name) == 31);
  456. ASSERT(!strcmp(name, "OnUpdateTextDrawCPObjectCommand"));
  457. }
  458. Test:Hooks_MakeShortName1()
  459. {
  460. new
  461. name[64];
  462. name = "OnPlayerEnterRaceCP";
  463. ASSERT(Hooks_MakeShortName(name) == 19);
  464. ASSERT(!strcmp(name, "OnPlayerEnterRaceCP"));
  465. name = "OnPlayerEnterRaceCheckpoint";
  466. ASSERT(Hooks_MakeShortName(name) == 27);
  467. ASSERT(!strcmp(name, "OnPlayerEnterRaceCheckpoint"));
  468. name = "OnPlayerEnterDynamicCP";
  469. ASSERT(Hooks_MakeShortName(name) == 22);
  470. ASSERT(!strcmp(name, "OnPlayerEnterDynamicCP"));
  471. name = "OnPlayerEnterDynamicRaceCheckpoint";
  472. ASSERT(Hooks_MakeShortName(name) == 26);
  473. ASSERT(!strcmp(name, "OnPlayerEnterDynamicRaceCP"));
  474. name = "AAAAAAAAAAAAAAAAAAAUpdateTextDraw";
  475. Hooks_MakeShortName(name);
  476. ASSERT(!strcmp(name, "AAAAAAAAAAAAAAAAAAAUpdateTD"));
  477. name = "BBBBBAAAAAAAAAAAAAAAAAAAUpdateTextDraw";
  478. Hooks_MakeShortName(name);
  479. ASSERT(!strcmp(name, "BBBBBAAAAAAAAAAAAAAAAAAAUpdTD"));
  480. }
  481. Test:Hooks_MakeShortName2()
  482. {
  483. new
  484. name[64];
  485. name = "AAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCC";
  486. ASSERT(Hooks_MakeShortName(name) == 43);
  487. ASSERT(!strcmp(name, "AAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCC"));
  488. name = "AAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCommandCCCC";
  489. ASSERT(Hooks_MakeShortName(name) == 45);
  490. ASSERT(!strcmp(name, "AAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCmdCCCC"));
  491. }
  492. Test:Hooks_GetDefaultReturn()
  493. {
  494. ASSERT(Hooks_GetDefaultReturn("OnHookRet\0\0\0\0\0\0\0\0") == 1);
  495. ASSERT(Hooks_GetDefaultReturn("OnPlayerCommandText\0\0\0\0\0\0\0\0") == 0);
  496. ASSERT(Hooks_GetDefaultReturn("OnHookRet2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0") == 0);
  497. ASSERT(Hooks_GetDefaultReturn("OnPlayerConnect\0\0\0\0\0\0\0\0") == 1);
  498. }
  499. HOOK_RET:OnHookRet2() return 0;
  500. DEFINE_HOOK_REPLACEMENT(Replacement, Rpl);
  501. forward OnPlayerCustomReplacement();
  502. public OnPlayerCustomReplacement() { g_y_hooksVar += 500; }
  503. hook OnPlayerCustomRpl() { g_y_hooksVar += 55; }
  504. Test:y_hooks_CustomReplacement()
  505. {
  506. g_y_hooksVar = 0;
  507. CallLocalFunction("OnPlayerCustomReplacement", "");
  508. ASSERT(g_y_hooksVar == 555);
  509. }
  510. #if !defined BAD_numargs
  511. #error y_hooks tests require BAD_numargs
  512. #endif
  513. hook OnTestNumArgs0(a, b, c, d, e, f)
  514. {
  515. ASSERT(Hooks_NumArgs() == 6);
  516. ASSERT(numargs() == 6);
  517. }
  518. hook OnTestNumArgs1(a, b, c, d, f)
  519. {
  520. ASSERT(Hooks_NumArgs() == 5);
  521. ASSERT(BAD_numargs() != 5);
  522. ASSERT(numargs() == 5);
  523. }
  524. forward OnTestNumArgs1(a, b, c, d, f);
  525. public OnTestNumArgs1(a, b, c, d, f)
  526. {
  527. ASSERT(Hooks_NumArgs() == 5);
  528. ASSERT(BAD_numargs() != 5);
  529. ASSERT(numargs() == 5);
  530. }
  531. hook OnTestNumArgs2(a, b, c, f)
  532. {
  533. ASSERT(Hooks_NumArgs() == 4);
  534. ASSERT(BAD_numargs() != 4);
  535. ASSERT(numargs() == 4);
  536. }
  537. #tryinclude "..\YSI_Internal\y_unique"
  538. #tryinclude "..\..\YSI_Internal\y_unique"
  539. hook OnTestNumArgs2(a, b, c, f)
  540. {
  541. ASSERT(Hooks_NumArgs() == 4);
  542. ASSERT(BAD_numargs() != 4);
  543. ASSERT(numargs() == 4);
  544. }
  545. forward OnTestNumArgs2(a, b, c, f);
  546. public OnTestNumArgs2(a, b, c, f)
  547. {
  548. ASSERT(Hooks_NumArgs() == 4);
  549. ASSERT(BAD_numargs() != 4);
  550. ASSERT(numargs() == 4);
  551. }
  552. static OnTestNumArgs4(total, ...)
  553. {
  554. ASSERT(numargs() == total + 1);
  555. }
  556. Test:y_hooks_numargs()
  557. {
  558. CallLocalFunction("OnTestNumArgs0", "iiiiii", 0, 0, 0, 0, 0, 0);
  559. CallLocalFunction("OnTestNumArgs1", "iiiii", 0, 0, 0, 0, 0);
  560. CallLocalFunction("OnTestNumArgs2", "iiii", 0, 0, 0, 0);
  561. OnTestNumArgs4(0);
  562. OnTestNumArgs4(1, 1);
  563. OnTestNumArgs4(2, 1, 2);
  564. OnTestNumArgs4(3, 1, 2, 3);
  565. OnTestNumArgs4(4, 1, 2, 3, 4);
  566. OnTestNumArgs4(5, 1, 2, 3, 4, 5);
  567. OnTestNumArgs4(6, 1, 2, 3, 4, 5, 6);
  568. }
  569. hook y_hooks_State1(string:c[]) <y_hooks_state : y_hooks_state_1>
  570. {
  571. g_y_hooksVar = strval(c[0]);
  572. }
  573. hook y_hooks_State1(string:c[]) <y_hooks_state : y_hooks_state_2>
  574. {
  575. g_y_hooksVar = strval(c[5]);
  576. }
  577. rehook y_hooks_State1(string:c[]) <y_hooks_state : y_hooks_state_3>
  578. {
  579. g_y_hooksVar += strval(c[5]);
  580. }
  581. hook public y_hooks_State1(string:c[]) <y_hooks_state : y_hooks_state_4>
  582. {
  583. g_y_hooksVar = strval(c[5]);
  584. }
  585. Test:y_hooks_State1()
  586. {
  587. state y_hooks_state : y_hooks_state_1;
  588. CallLocalFunction("y_hooks_State1", "s", "1000 2000");
  589. ASSERT(g_y_hooksVar == 1000);
  590. state y_hooks_state : y_hooks_state_2;
  591. CallLocalFunction("y_hooks_State1", "s", "1000 2000");
  592. ASSERT(g_y_hooksVar == 2000);
  593. state y_hooks_state : y_hooks_state_1;
  594. CallLocalFunction("y_hooks_State1", "s", "1000 2000");
  595. state y_hooks_state : y_hooks_state_3;
  596. CallLocalFunction("y_hooks_State1", "s", "1000 2000");
  597. ASSERT(g_y_hooksVar == 3000);
  598. }