tests.inc 22 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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. #assert MAX_PLAYERS >= 50
  65. Test:000_y_groups_Global()
  66. {
  67. // Need a certain number just to run this code.
  68. call OnPlayerConnect(42);
  69. ASSERT(Group_GetPlayer(GROUP_GLOBAL, 42));
  70. //call OnPlayerDisconnect(42, 0);
  71. }
  72. Test:y_groups_Valid()
  73. {
  74. new
  75. Group:g = Group_Create("Valid"),
  76. Group:i = Group_Create("Invalid");
  77. Group_Destroy(i);
  78. ASSERT_TRUE(Group_IsValid(g));
  79. ASSERT_FALSE(Group_IsValid(i));
  80. ASSERT_FALSE(Group_IsValid(Group:3));
  81. Group_Destroy(g);
  82. }
  83. Test:y_groups_Create0()
  84. {
  85. new
  86. Group:g = Group_Create();
  87. ASSERT(g != INVALID_GROUP);
  88. Group_Destroy(g);
  89. }
  90. Test:y_groups_Create0b()
  91. {
  92. new
  93. Group:g0 = Group_Create("hello"),
  94. Group:g1 = Group_Create("there");
  95. ASSERT(g0 != INVALID_GROUP);
  96. ASSERT(g1 != INVALID_GROUP);
  97. ASSERT(g0 != g1);
  98. Group_Destroy(g0);
  99. Group_Destroy(g1);
  100. }
  101. Test:y_groups_Create1()
  102. {
  103. new
  104. Group:g = Group_Create("Group 1");
  105. ASSERT(g != INVALID_GROUP);
  106. Group_Destroy(g);
  107. }
  108. Test:y_groups_GetID()
  109. {
  110. new
  111. Group:g = Group_Create("Group 2");
  112. ASSERT(g == Group_GetID("Group 2"));
  113. ASSERT(!strcmp("Group 2", Group_GetName(g)));
  114. Group_Destroy(g);
  115. }
  116. Test:y_groups_GetGang0()
  117. {
  118. new
  119. Group:g = Group_Create("Group 3");
  120. ASSERT_FALSE(Group_GetGang(g));
  121. Group_Destroy(g);
  122. }
  123. Test:y_groups_GetGang1()
  124. {
  125. new
  126. Group:g = Group_Create("Group 4");
  127. Group_SetGang(g, true);
  128. ASSERT_TRUE(Group_GetGang(g));
  129. Group_Destroy(g);
  130. }
  131. Test:y_groups_GetGang2()
  132. {
  133. new
  134. Group:g = Group_Create("Group 5");
  135. Group_SetGang(g, true);
  136. Group_SetGang(g, false);
  137. ASSERT_FALSE(Group_GetGang(g));
  138. Group_Destroy(g);
  139. }
  140. Test:y_groups_GetColour()
  141. {
  142. new
  143. Group:g = Group_Create("Group 6");
  144. Group_SetColour(g, 0x11227654);
  145. ASSERT(Group_GetColor(g) == 0x112276AA);
  146. Group_SetColour(g, 0x76541122);
  147. ASSERT(Group_GetColor(g) == 0x765411AA);
  148. Group_SetColour(g, 0x65127412);
  149. ASSERT(Group_GetColor(g) == 0x651274AA);
  150. Group_Destroy(g);
  151. }
  152. Test:y_groups_Set1()
  153. {
  154. new
  155. Group:g = Group_Create("Group 7");
  156. ASSERT(Group_GetCount(g) == 0);
  157. Group_SetPlayer(g, 42, true);
  158. ASSERT_TRUE(Group_GetPlayer(g, 42));
  159. ASSERT(Group_GetCount(g) == 1);
  160. new
  161. c = 0;
  162. foreach (new p : GroupMember[g])
  163. {
  164. ASSERT(p == 42);
  165. ++c;
  166. }
  167. ASSERT(c == 1);
  168. Group_Destroy(g);
  169. }
  170. Test:y_groups_Set2()
  171. {
  172. new
  173. Group:g = Group_Create("Group 8");
  174. ASSERT(Group_GetCount(g) == 0);
  175. //new k = Group_SetPlayer(g, 42, true);
  176. Group_SetPlayer(g, 42, true);
  177. ASSERT(Group_GetCount(g) == 1);
  178. Group_SetPlayer(g, 42, false);
  179. ASSERT(Group_GetCount(g) == 0);
  180. new
  181. c = 0;
  182. foreach (new p : GroupMember(g))
  183. {
  184. ++c;
  185. }
  186. ASSERT(c == 0);
  187. Group_Destroy(g);
  188. }
  189. Test:y_groups_Set3()
  190. {
  191. new
  192. Group:g = Group_Create("Group 8");
  193. Group_SetPlayer(g, 42, true);
  194. ASSERT(Group_GetCount(g) == 1);
  195. call OnPlayerDisconnect(42, 0);
  196. Group_Destroy(g);
  197. }
  198. Test:y_groups_SetBalanced0()
  199. {
  200. new
  201. Group:g1 = Group_Create("Group 1"),
  202. Group:g2 = Group_Create("Group 2");
  203. call OnPlayerConnect(22);
  204. Group_SetPlayer(g2, 22, true);
  205. Group_SetBalanced(22, g1, g2);
  206. ASSERT(Group_GetCount(g1) == 0 && Group_GetCount(g2) == 1);
  207. call OnPlayerDisconnect(22, 0);
  208. Group_Destroy(g1);
  209. Group_Destroy(g2);
  210. }
  211. Test:y_groups_SetBalanced1()
  212. {
  213. new
  214. Group:g1 = Group_Create("Group 1"),
  215. Group:g2 = Group_Create("Group 2");
  216. call OnPlayerConnect(23);
  217. call OnPlayerConnect(32);
  218. Group_SetBalanced(23, g1, g2);
  219. Group_SetBalanced(32, g1, g2);
  220. ASSERT(Group_GetCount(g1) == 1 && Group_GetCount(g2) == 1);
  221. call OnPlayerDisconnect(23, 0);
  222. call OnPlayerDisconnect(32, 0);
  223. Group_Destroy(g1);
  224. Group_Destroy(g2);
  225. }
  226. Test:y_groups_SetBalanced2()
  227. {
  228. new
  229. Group:g1 = Group_Create("Group 1"),
  230. Group:g2 = Group_Create("Group 2"),
  231. Group:g3 = Group_Create("Group 3");
  232. call OnPlayerConnect(1);
  233. call OnPlayerConnect(2);
  234. call OnPlayerConnect(3);
  235. call OnPlayerConnect(4);
  236. call OnPlayerConnect(5);
  237. call OnPlayerConnect(6);
  238. Group_SetBalanced(1, g1, g2, g3);
  239. Group_SetBalanced(2, g1, g2, g3);
  240. Group_SetBalanced(3, g1, g2, g3);
  241. Group_SetBalanced(4, g1, g2, g3);
  242. Group_SetBalanced(5, g1, g2, g3);
  243. Group_SetBalanced(6, g1, g2, g3);
  244. ASSERT(Group_GetCount(g1) == 2 && Group_GetCount(g2) == 2 && Group_GetCount(g3) == 2);
  245. call OnPlayerDisconnect(1, 0);
  246. call OnPlayerDisconnect(2, 0);
  247. call OnPlayerDisconnect(3, 0);
  248. call OnPlayerDisconnect(4, 0);
  249. call OnPlayerDisconnect(5, 0);
  250. call OnPlayerDisconnect(6, 0);
  251. Group_Destroy(g1);
  252. Group_Destroy(g2);
  253. Group_Destroy(g3);
  254. }
  255. Test:y_groups_SetBalanced3()
  256. {
  257. new
  258. Group:g[3];
  259. g[0] = Group_Create("Group 1");
  260. g[1] = Group_Create("Group 2");
  261. g[2] = Group_Create("Group 3");
  262. call OnPlayerConnect(0);
  263. call OnPlayerConnect(1);
  264. call OnPlayerConnect(2);
  265. call OnPlayerConnect(3);
  266. call OnPlayerConnect(4);
  267. call OnPlayerConnect(5);
  268. call OnPlayerConnect(6);
  269. Group_SetBalancedArray(0, g, sizeof(g));
  270. Group_SetBalancedArray(1, g, sizeof(g));
  271. Group_SetBalancedArray(2, g, sizeof(g));
  272. Group_SetBalancedArray(3, g, sizeof(g));
  273. Group_SetBalancedArray(4, g, sizeof(g));
  274. Group_SetBalancedArray(5, g, sizeof(g));
  275. Group_SetBalancedArray(6, g, sizeof(g));
  276. ASSERT(Group_GetCount(g[0]) == 3);
  277. ASSERT(Group_GetCount(g[1]) == 2);
  278. ASSERT(Group_GetCount(g[2]) == 2);
  279. call OnPlayerDisconnect(0, 0);
  280. call OnPlayerDisconnect(1, 0);
  281. call OnPlayerDisconnect(2, 0);
  282. call OnPlayerDisconnect(3, 0);
  283. call OnPlayerDisconnect(4, 0);
  284. call OnPlayerDisconnect(5, 0);
  285. call OnPlayerDisconnect(6, 0);
  286. Group_Destroy(g[0]);
  287. Group_Destroy(g[1]);
  288. Group_Destroy(g[2]);
  289. }
  290. Test:y_groups_SetBalancedIn1()
  291. {
  292. new
  293. Group:g[3];
  294. g[0] = Group_Create("Group 1");
  295. g[1] = Group_Create("Group 2");
  296. g[2] = Group_Create("Group 3");
  297. call OnPlayerConnect(0);
  298. call OnPlayerConnect(1);
  299. call OnPlayerConnect(2);
  300. call OnPlayerConnect(3);
  301. call OnPlayerConnect(4);
  302. call OnPlayerConnect(5);
  303. call OnPlayerConnect(6);
  304. Group_SetPlayer(g[0], 0, true);
  305. Group_SetPlayer(g[0], 1, true);
  306. Group_SetPlayer(g[0], 2, true);
  307. Group_SetPlayer(g[2], 3, true);
  308. Group_SetPlayer(g[2], 4, true);
  309. Group_SetPlayer(g[2], 5, true);
  310. Group_SetBalancedArray(6, g, sizeof(g));
  311. ASSERT(Group_GetCount(g[0]) == 3);
  312. ASSERT(Group_GetCount(g[1]) == 1);
  313. ASSERT(Group_GetCount(g[2]) == 3);
  314. call OnPlayerDisconnect(0, 0);
  315. call OnPlayerDisconnect(1, 0);
  316. call OnPlayerDisconnect(2, 0);
  317. call OnPlayerDisconnect(3, 0);
  318. call OnPlayerDisconnect(4, 0);
  319. call OnPlayerDisconnect(5, 0);
  320. call OnPlayerDisconnect(6, 0);
  321. Group_Destroy(g[0]);
  322. Group_Destroy(g[1]);
  323. Group_Destroy(g[2]);
  324. }
  325. Test:y_groups_SetBalancedIn2()
  326. {
  327. new
  328. Group:g[3];
  329. g[0] = Group_Create("Group 1");
  330. g[1] = Group_Create("Group 2");
  331. g[2] = Group_Create("Group 3");
  332. call OnPlayerConnect(0);
  333. call OnPlayerConnect(1);
  334. call OnPlayerConnect(2);
  335. call OnPlayerConnect(3);
  336. call OnPlayerConnect(4);
  337. call OnPlayerConnect(5);
  338. call OnPlayerConnect(6);
  339. Group_SetPlayer(g[0], 0, true);
  340. Group_SetPlayer(g[0], 1, true);
  341. Group_SetPlayer(g[0], 2, true);
  342. Group_SetPlayer(g[2], 3, true);
  343. Group_SetPlayer(g[2], 4, true);
  344. Group_SetPlayer(g[2], 5, true);
  345. Group_SetBalancedArray(0, g, sizeof(g));
  346. ASSERT(Group_GetCount(g[0]) == 3);
  347. ASSERT(Group_GetCount(g[1]) == 0);
  348. ASSERT(Group_GetCount(g[2]) == 3);
  349. call OnPlayerDisconnect(0, 0);
  350. call OnPlayerDisconnect(1, 0);
  351. call OnPlayerDisconnect(2, 0);
  352. call OnPlayerDisconnect(3, 0);
  353. call OnPlayerDisconnect(4, 0);
  354. call OnPlayerDisconnect(5, 0);
  355. call OnPlayerDisconnect(6, 0);
  356. Group_Destroy(g[0]);
  357. Group_Destroy(g[1]);
  358. Group_Destroy(g[2]);
  359. }
  360. Test:y_groups_SetBalancedIn3()
  361. {
  362. new
  363. Group:g[3];
  364. g[0] = Group_Create("Group 1");
  365. g[1] = Group_Create("Group 2");
  366. g[2] = Group_Create("Group 3");
  367. call OnPlayerConnect(0);
  368. call OnPlayerConnect(1);
  369. call OnPlayerConnect(2);
  370. call OnPlayerConnect(3);
  371. call OnPlayerConnect(4);
  372. call OnPlayerConnect(5);
  373. call OnPlayerConnect(6);
  374. Group_SetPlayer(g[0], 0, true);
  375. Group_SetPlayer(g[0], 1, true);
  376. Group_SetPlayer(g[0], 2, true);
  377. Group_SetPlayer(g[2], 3, true);
  378. Group_SetPlayer(g[2], 4, true);
  379. Group_SetPlayer(g[2], 5, true);
  380. Group_SetBalancedArray(4, g, sizeof(g));
  381. ASSERT(Group_GetCount(g[0]) == 3);
  382. ASSERT(Group_GetCount(g[1]) == 0);
  383. ASSERT(Group_GetCount(g[2]) == 3);
  384. call OnPlayerDisconnect(0, 0);
  385. call OnPlayerDisconnect(1, 0);
  386. call OnPlayerDisconnect(2, 0);
  387. call OnPlayerDisconnect(3, 0);
  388. call OnPlayerDisconnect(4, 0);
  389. call OnPlayerDisconnect(5, 0);
  390. call OnPlayerDisconnect(6, 0);
  391. Group_Destroy(g[0]);
  392. Group_Destroy(g[1]);
  393. Group_Destroy(g[2]);
  394. }
  395. Test:y_groups_SetBalancedIn3a()
  396. {
  397. new
  398. Group:g[3];
  399. g[0] = Group_Create("Group 1");
  400. g[1] = Group_Create("Group 2");
  401. g[2] = Group_Create("Group 3");
  402. call OnPlayerConnect(0);
  403. call OnPlayerConnect(1);
  404. call OnPlayerConnect(2);
  405. call OnPlayerConnect(3);
  406. call OnPlayerConnect(4);
  407. call OnPlayerConnect(5);
  408. call OnPlayerConnect(6);
  409. Group_SetPlayer(g[0], 0, true);
  410. Group_SetPlayer(g[0], 1, true);
  411. Group_SetPlayer(g[1], 2, true);
  412. Group_SetPlayer(g[1], 3, true);
  413. Group_SetPlayer(g[2], 4, true);
  414. Group_SetPlayer(g[2], 5, true);
  415. Group_SetPlayer(g[0], 6, true);
  416. Group_SetBalancedArray(0, g, sizeof(g));
  417. ASSERT(Group_GetCount(g[0]) == 3);
  418. ASSERT(Group_GetCount(g[1]) == 2);
  419. ASSERT(Group_GetCount(g[2]) == 2);
  420. call OnPlayerDisconnect(0, 0);
  421. call OnPlayerDisconnect(1, 0);
  422. call OnPlayerDisconnect(2, 0);
  423. call OnPlayerDisconnect(3, 0);
  424. call OnPlayerDisconnect(4, 0);
  425. call OnPlayerDisconnect(5, 0);
  426. call OnPlayerDisconnect(6, 0);
  427. Group_Destroy(g[0]);
  428. Group_Destroy(g[1]);
  429. Group_Destroy(g[2]);
  430. }
  431. Test:y_groups_SetBalancedIn3b()
  432. {
  433. new
  434. Group:g[3];
  435. g[0] = Group_Create("Group 1");
  436. g[1] = Group_Create("Group 2");
  437. g[2] = Group_Create("Group 3");
  438. call OnPlayerConnect(0);
  439. call OnPlayerConnect(1);
  440. call OnPlayerConnect(2);
  441. call OnPlayerConnect(3);
  442. call OnPlayerConnect(4);
  443. call OnPlayerConnect(5);
  444. call OnPlayerConnect(6);
  445. Group_SetPlayer(g[0], 0, true);
  446. Group_SetPlayer(g[0], 1, true);
  447. Group_SetPlayer(g[1], 2, true);
  448. Group_SetPlayer(g[1], 3, true);
  449. Group_SetPlayer(g[2], 4, true);
  450. Group_SetPlayer(g[2], 5, true);
  451. Group_SetPlayer(g[1], 6, true);
  452. Group_SetBalancedArray(0, g, sizeof(g));
  453. ASSERT(Group_GetCount(g[0]) == 2);
  454. ASSERT(Group_GetCount(g[1]) == 3);
  455. ASSERT(Group_GetCount(g[2]) == 2);
  456. call OnPlayerDisconnect(0, 0);
  457. call OnPlayerDisconnect(1, 0);
  458. call OnPlayerDisconnect(2, 0);
  459. call OnPlayerDisconnect(3, 0);
  460. call OnPlayerDisconnect(4, 0);
  461. call OnPlayerDisconnect(5, 0);
  462. call OnPlayerDisconnect(6, 0);
  463. Group_Destroy(g[0]);
  464. Group_Destroy(g[1]);
  465. Group_Destroy(g[2]);
  466. }
  467. Test:y_groups_SetBalancedIn3c()
  468. {
  469. new
  470. Group:g[3];
  471. g[0] = Group_Create("Group 1");
  472. g[1] = Group_Create("Group 2");
  473. g[2] = Group_Create("Group 3");
  474. call OnPlayerConnect(0);
  475. call OnPlayerConnect(1);
  476. call OnPlayerConnect(2);
  477. call OnPlayerConnect(3);
  478. call OnPlayerConnect(4);
  479. call OnPlayerConnect(5);
  480. call OnPlayerConnect(6);
  481. Group_SetPlayer(g[0], 0, true);
  482. Group_SetPlayer(g[0], 1, true);
  483. Group_SetPlayer(g[1], 2, true);
  484. Group_SetPlayer(g[1], 3, true);
  485. Group_SetPlayer(g[2], 4, true);
  486. Group_SetPlayer(g[2], 5, true);
  487. Group_SetPlayer(g[2], 6, true);
  488. Group_SetBalancedArray(0, g, sizeof(g));
  489. ASSERT(Group_GetCount(g[0]) == 2);
  490. ASSERT(Group_GetCount(g[1]) == 2);
  491. ASSERT(Group_GetCount(g[2]) == 3);
  492. call OnPlayerDisconnect(0, 0);
  493. call OnPlayerDisconnect(1, 0);
  494. call OnPlayerDisconnect(2, 0);
  495. call OnPlayerDisconnect(3, 0);
  496. call OnPlayerDisconnect(4, 0);
  497. call OnPlayerDisconnect(5, 0);
  498. call OnPlayerDisconnect(6, 0);
  499. Group_Destroy(g[0]);
  500. Group_Destroy(g[1]);
  501. Group_Destroy(g[2]);
  502. }
  503. Test:y_groups_SetBalancedIn4()
  504. {
  505. new
  506. Group:g[3];
  507. g[0] = Group_Create("Group 1");
  508. g[1] = Group_Create("Group 2");
  509. g[2] = Group_Create("Group 3");
  510. call OnPlayerConnect(0);
  511. call OnPlayerConnect(1);
  512. call OnPlayerConnect(2);
  513. call OnPlayerConnect(3);
  514. call OnPlayerConnect(4);
  515. call OnPlayerConnect(5);
  516. call OnPlayerConnect(6);
  517. Group_SetPlayer(g[0], 0, true);
  518. Group_SetPlayer(g[0], 1, true);
  519. Group_SetPlayer(g[1], 2, true);
  520. Group_SetPlayer(g[1], 3, true);
  521. Group_SetPlayer(g[2], 4, true);
  522. Group_SetPlayer(g[1], 6, true);
  523. Group_SetBalancedArray(2, g, sizeof(g));
  524. ASSERT(Group_GetCount(g[0]) == 2);
  525. ASSERT(Group_GetCount(g[1]) == 3);
  526. ASSERT(Group_GetCount(g[2]) == 1);
  527. call OnPlayerDisconnect(0, 0);
  528. call OnPlayerDisconnect(1, 0);
  529. call OnPlayerDisconnect(2, 0);
  530. call OnPlayerDisconnect(3, 0);
  531. call OnPlayerDisconnect(4, 0);
  532. call OnPlayerDisconnect(5, 0);
  533. call OnPlayerDisconnect(6, 0);
  534. Group_Destroy(g[0]);
  535. Group_Destroy(g[1]);
  536. Group_Destroy(g[2]);
  537. }
  538. Test:y_groups_SetBalancedSingle()
  539. {
  540. new
  541. Group:g1 = Group_Create("Group 1"),
  542. Group:result;
  543. call OnPlayerConnect(0);
  544. result = Group_SetBalanced(0, g1, Group:11);
  545. ASSERT(result == g1);
  546. call OnPlayerDisconnect(0, 0);
  547. Group_Destroy(g1);
  548. }
  549. Test:y_groups_SetBalancedInvalid()
  550. {
  551. new
  552. Group:result;
  553. call OnPlayerConnect(0);
  554. result = Group_SetBalanced(0, Group:99, Group:88);
  555. ASSERT(result == INVALID_GROUP);
  556. call OnPlayerDisconnect(0, 0);
  557. }
  558. #define MASTER 60
  559. #tryinclude "..\YSI_Core\y_master"
  560. #tryinclude "..\..\YSI_Core\y_master"
  561. #define _GROUP_MAKE_NAME<%0...%1> %0Test%1
  562. #define _GROUP_MAKE_LIMIT 123
  563. #tryinclude "y_groups\_funcs"
  564. #tryinclude "_funcs"
  565. static
  566. gPl,
  567. gEl,
  568. bool:gS;
  569. Test_SetPlayer(el, playerid, bool:s)
  570. {
  571. P:1("Test_SetPlayer called: %d %d %d", el, playerid, s);
  572. gPl = playerid;
  573. gEl = el;
  574. gS = s;
  575. return 1;
  576. }
  577. Test:0_y_groups_Connect0()
  578. {
  579. gPl = INVALID_PLAYER_ID;
  580. gEl = 100;
  581. gS = false;
  582. //new
  583. // Group:g = Group_Create();
  584. call OnPlayerConnect(45);
  585. ASSERT(gPl == INVALID_PLAYER_ID);
  586. ASSERT(gEl == 100);
  587. ASSERT(gS == false);
  588. //printf("%d %d %d", gPl, gEl, gS);
  589. Test_InitialiseFromGroups(7);
  590. ASSERT(gPl == 45);
  591. ASSERT(gEl == 7);
  592. ASSERT(gS == true);
  593. call OnPlayerDisconnect(45, 0);
  594. }
  595. Test:0_y_groups_Connect1()
  596. {
  597. gPl = INVALID_PLAYER_ID;
  598. gEl = 100;
  599. gS = false;
  600. //new
  601. // Group:g = Group_Create();
  602. Test_InitialiseFromGroups(8);
  603. ASSERT(gPl != INVALID_PLAYER_ID);
  604. ASSERT(gEl != 100);
  605. ASSERT(gS != false);
  606. call OnPlayerConnect(43);
  607. ASSERT(gPl == 43);
  608. ASSERT(gEl == 8);
  609. ASSERT(gS == true);
  610. call OnPlayerDisconnect(43, 0);
  611. }
  612. Test:y_groups_Chains()
  613. {
  614. new
  615. Group:g = Group_Create();
  616. call OnPlayerConnect(44);
  617. ASSERT_FALSE(Group_GetPlayer(g, 44));
  618. Group_SetGlobalGroup(g, true);
  619. ASSERT_TRUE(Group_GetPlayer(g, 44));
  620. call OnPlayerDisconnect(44, 0);
  621. }
  622. Test:y_groups_Children0()
  623. {
  624. new
  625. Group:g0 = Group_Create();
  626. ASSERT(!Group_GetGlobalGroup(g0));
  627. Group_Destroy(g0);
  628. }
  629. Test:y_groups_Children1()
  630. {
  631. new
  632. Group:g0 = Group_Create(),
  633. Group:g1 = Group_Create(),
  634. Group:g2 = Group_Create();
  635. // Check groups ARE descendants of themselves.
  636. ASSERT(Group_IsDescendant(GROUP_GLOBAL, GROUP_GLOBAL));
  637. ASSERT(Group_IsDescendant(g0, g0));
  638. ASSERT(Group_IsDescendant(g1, g1));
  639. ASSERT(Group_IsDescendant(g2, g2));
  640. // Check there are no relationships at all.
  641. ASSERT(!Group_IsDescendant(g0, g1));
  642. ASSERT(!Group_IsDescendant(g0, g2));
  643. ASSERT(!Group_IsDescendant(g1, g0));
  644. ASSERT(!Group_IsDescendant(g1, g2));
  645. ASSERT(!Group_IsDescendant(g2, g0));
  646. ASSERT(!Group_IsDescendant(g2, g1));
  647. // Grlobal group.
  648. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g0));
  649. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g1));
  650. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g2));
  651. ASSERT(!Group_IsDescendant(g0, GROUP_GLOBAL));
  652. ASSERT(!Group_IsDescendant(g1, GROUP_GLOBAL));
  653. ASSERT(!Group_IsDescendant(g2, GROUP_GLOBAL));
  654. Group_Destroy(g0),
  655. Group_Destroy(g1),
  656. Group_Destroy(g2);
  657. }
  658. Test:y_groups_Children2()
  659. {
  660. new
  661. Group:g0 = Group_Create(),
  662. Group:g1 = Group_Create(),
  663. Group:g2 = Group_Create();
  664. // Check groups are children of themselves.
  665. ASSERT(!Group_GetGroup(GROUP_GLOBAL, GROUP_GLOBAL));
  666. ASSERT(!Group_GetGroup(g0, g0));
  667. ASSERT(!Group_GetGroup(g1, g1));
  668. ASSERT(!Group_GetGroup(g2, g2));
  669. // Check there are no relationships at all.
  670. ASSERT(!Group_GetGroup(g0, g1));
  671. ASSERT(!Group_GetGroup(g0, g2));
  672. ASSERT(!Group_GetGroup(g1, g0));
  673. ASSERT(!Group_GetGroup(g1, g2));
  674. ASSERT(!Group_GetGroup(g2, g0));
  675. ASSERT(!Group_GetGroup(g2, g1));
  676. // Grlobal group.
  677. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g0));
  678. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g1));
  679. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g2));
  680. ASSERT(!Group_GetGroup(g0, GROUP_GLOBAL));
  681. ASSERT(!Group_GetGroup(g1, GROUP_GLOBAL));
  682. ASSERT(!Group_GetGroup(g2, GROUP_GLOBAL));
  683. Group_Destroy(g0),
  684. Group_Destroy(g1),
  685. Group_Destroy(g2);
  686. }
  687. Test:y_groups_Children3()
  688. {
  689. new
  690. Group:g0 = Group_Create(),
  691. Group:g1 = Group_Create(),
  692. Group:g2 = Group_Create();
  693. Group_AddChild(g0, g1);
  694. ASSERT(Group_IsDescendant(g0, g1));
  695. // Check there are no other relationships.
  696. ASSERT(!Group_IsDescendant(g0, g2));
  697. ASSERT(!Group_IsDescendant(g1, g0));
  698. ASSERT(!Group_IsDescendant(g1, g2));
  699. ASSERT(!Group_IsDescendant(g2, g0));
  700. ASSERT(!Group_IsDescendant(g2, g1));
  701. Group_Destroy(g0),
  702. Group_Destroy(g1),
  703. Group_Destroy(g2);
  704. }
  705. Test:y_groups_Children4()
  706. {
  707. new
  708. Group:g0 = Group_Create(),
  709. Group:g1 = Group_Create(),
  710. Group:g2 = Group_Create();
  711. Group_AddChild(g0, g1);
  712. Group_AddChild(g1, g2);
  713. // Test chaining.
  714. ASSERT(Group_IsDescendant(g0, g1));
  715. ASSERT(Group_IsDescendant(g1, g2));
  716. ASSERT(Group_IsDescendant(g0, g2));
  717. // Check there are no reverse relationships.
  718. ASSERT(!Group_IsDescendant(g1, g0));
  719. ASSERT(!Group_IsDescendant(g2, g0));
  720. ASSERT(!Group_IsDescendant(g2, g1));
  721. Group_Destroy(g0),
  722. Group_Destroy(g1),
  723. Group_Destroy(g2);
  724. }
  725. Test:y_groups_Children5()
  726. {
  727. new
  728. Group:g0 = Group_Create(),
  729. Group:g1 = Group_Create(),
  730. Group:g2 = Group_Create(),
  731. Group:g3 = Group_Create(),
  732. Group:g4 = Group_Create();
  733. Group_AddChild(g0, g1);
  734. Group_AddChild(g1, g2);
  735. Group_AddChild(g2, g0);
  736. Group_AddChild(g4, g0);
  737. // Test cycles don't hang.
  738. ASSERT(!Group_IsDescendant(g4, g3));
  739. ASSERT(!Group_IsDescendant(g3, g4));
  740. // Test cycles work.
  741. ASSERT(Group_IsDescendant(g4, g2));
  742. ASSERT(!Group_IsDescendant(g2, g4));
  743. ASSERT(Group_IsDescendant(g0, g2));
  744. ASSERT(Group_IsDescendant(g2, g0));
  745. Group_Destroy(g0),
  746. Group_Destroy(g1),
  747. Group_Destroy(g2);
  748. Group_Destroy(g3);
  749. Group_Destroy(g4);
  750. }
  751. Test:y_groups_Children6()
  752. {
  753. new
  754. Group:g0 = Group_Create(),
  755. Group:g1 = Group_Create(),
  756. Group:g2 = Group_Create();
  757. Group_AddChild(g0, g1);
  758. Group_AddChild(g1, g2);
  759. // Test removal
  760. ASSERT(Group_IsDescendant(g0, g2));
  761. Group_RemoveChild(g1, g2);
  762. ASSERT(!Group_IsDescendant(g0, g2));
  763. Group_AddChild(g1, g2);
  764. ASSERT(Group_IsDescendant(g0, g2));
  765. Group_Destroy(g1);
  766. ASSERT(!Group_IsDescendant(g0, g2));
  767. Group_Destroy(g0),
  768. Group_Destroy(g2);
  769. }
  770. Test:y_groups_Children7()
  771. {
  772. new
  773. Group:g0 = Group_Create(),
  774. Group:g1 = Group_Create(),
  775. Group:g2 = Group_Create();
  776. Group_AddChild(g0, g1);
  777. Group_AddChild(g1, g2);
  778. // Test chaining.
  779. ASSERT(Group_IsDescendant(g0, g1));
  780. ASSERT(Group_IsDescendant(g1, g2));
  781. ASSERT(Group_IsDescendant(g0, g2));
  782. // Check there are no reverse relationships.
  783. ASSERT(!Group_IsChild(g0, g2));
  784. Group_Destroy(g0),
  785. Group_Destroy(g1),
  786. Group_Destroy(g2);
  787. }
  788. Test:y_groups_ChildIterator0()
  789. {
  790. new
  791. Group:g0 = Group_Create(),
  792. Group:g1 = Group_Create(),
  793. Group:g2 = Group_Create();
  794. Group_AddChild(g0, g1);
  795. Group_AddChild(g0, g2);
  796. new
  797. total = 0;
  798. foreach (new Group:g : GroupChild(g0))
  799. {
  800. ++total;
  801. }
  802. ASSERT(total == 2);
  803. Group_Destroy(g0),
  804. Group_Destroy(g1),
  805. Group_Destroy(g2);
  806. }
  807. Test:y_groups_ChildIterator1()
  808. {
  809. new
  810. Group:g0 = Group_Create(),
  811. Group:g1 = Group_Create(),
  812. Group:g2 = Group_Create();
  813. Group_AddChild(g0, g1);
  814. Group_AddChild(g0, g2);
  815. ASSERT(Group_IsValid(g0));
  816. ASSERT(Group_IsValid(g1));
  817. ASSERT(Group_IsValid(g2));
  818. foreach (new Group:g : GroupChild(g0))
  819. {
  820. Group_Destroy(g);
  821. }
  822. ASSERT(Group_IsValid(g0));
  823. ASSERT(!Group_IsValid(g1));
  824. ASSERT(!Group_IsValid(g2));
  825. Group_Destroy(g0),
  826. ASSERT(!Group_IsValid(g0));
  827. }
  828. Test:y_groups_ChildIterator2()
  829. {
  830. new
  831. Group:g0 = Group_Create(),
  832. Group:g1 = Group_Create(),
  833. Group:g2 = Group_Create();
  834. Group_AddChild(g0, g1);
  835. Group_AddChild(g0, g2);
  836. ASSERT(Group_IsValid(g0));
  837. ASSERT(Group_IsValid(g1));
  838. ASSERT(Group_IsValid(g2));
  839. new
  840. total = 0;
  841. foreach (new Group:g : GroupChild[g0])
  842. {
  843. Group_Destroy(g);
  844. ++total;
  845. }
  846. ASSERT(total == 2);
  847. ASSERT(Group_IsValid(g0));
  848. ASSERT(!Group_IsValid(g1));
  849. ASSERT(!Group_IsValid(g2));
  850. Group_Destroy(g0),
  851. ASSERT(!Group_IsValid(g0));
  852. }
  853. Test:y_groups_Iterator0()
  854. {
  855. new
  856. Group:g0 = Group_Create(),
  857. Group:g1 = Group_Create(),
  858. Group:g2 = Group_Create();
  859. new
  860. total = 0;
  861. foreach (new Group:g : CreatedGroup)
  862. {
  863. ++total;
  864. }
  865. ASSERT(total >= 3);
  866. total = 0;
  867. foreach (new Group:g : CreatedGroup())
  868. {
  869. ++total;
  870. }
  871. ASSERT(total >= 3);
  872. Group_Destroy(g0),
  873. Group_Destroy(g1),
  874. Group_Destroy(g2);
  875. }
  876. #undef _GROUP_MAKE_LIMIT
  877. #undef _GROUP_MAKE_NAME
  878. #tryinclude "..\YSI_Core\y_master"
  879. #tryinclude "..\..\YSI_Core\y_master"