y_groups_tests.inc 22 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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_NE(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_NE(g0, INVALID_GROUP);
  96. ASSERT_NE(g1, INVALID_GROUP);
  97. ASSERT_NE(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_NE(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_EQ(g, Group_GetID("Group 2"));
  113. ASSERT_SAME(Group_GetName(g), "Group 2");
  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_EQ(Group_GetColor(g), 0x112276AA);
  146. Group_SetColour(g, 0x76541122);
  147. ASSERT_EQ(Group_GetColor(g), 0x765411AA);
  148. Group_SetColour(g, 0x65127412);
  149. ASSERT_EQ(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_ZE(Group_GetCount(g));
  157. Group_SetPlayer(g, 42, true);
  158. ASSERT_TRUE(Group_GetPlayer(g, 42));
  159. ASSERT_EQ(Group_GetCount(g), 1);
  160. new
  161. c = 0;
  162. FOREACH__ (new p : GroupMember[g])
  163. {
  164. ASSERT_EQ(p, 42);
  165. ++c;
  166. }
  167. ASSERT_EQ(c, 1);
  168. Group_Destroy(g);
  169. }
  170. TEST__ y_groups_Set2()
  171. {
  172. new
  173. Group:g = Group_Create("Group 8");
  174. ASSERT_ZE(Group_GetCount(g));
  175. //new k = Group_SetPlayer(g, 42, true);
  176. Group_SetPlayer(g, 42, true);
  177. ASSERT_EQ(Group_GetCount(g), 1);
  178. Group_SetPlayer(g, 42, false);
  179. ASSERT_ZE(Group_GetCount(g));
  180. new
  181. c = 0;
  182. FOREACH__ (new p : GroupMember(g))
  183. {
  184. ++c;
  185. }
  186. ASSERT_ZE(c);
  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_EQ(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_EQ(Group_GetCount(g[0]), 3);
  277. ASSERT_EQ(Group_GetCount(g[1]), 2);
  278. ASSERT_EQ(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_EQ(Group_GetCount(g[0]), 3);
  312. ASSERT_EQ(Group_GetCount(g[1]), 1);
  313. ASSERT_EQ(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_EQ(Group_GetCount(g[0]), 3);
  347. ASSERT_ZE(Group_GetCount(g[1]));
  348. ASSERT_EQ(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_EQ(Group_GetCount(g[0]), 3);
  382. ASSERT_ZE(Group_GetCount(g[1]));
  383. ASSERT_EQ(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_EQ(Group_GetCount(g[0]), 3);
  418. ASSERT_EQ(Group_GetCount(g[1]), 2);
  419. ASSERT_EQ(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_EQ(Group_GetCount(g[0]), 2);
  454. ASSERT_EQ(Group_GetCount(g[1]), 3);
  455. ASSERT_EQ(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_EQ(Group_GetCount(g[0]), 2);
  490. ASSERT_EQ(Group_GetCount(g[1]), 2);
  491. ASSERT_EQ(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_EQ(Group_GetCount(g[0]), 2);
  525. ASSERT_EQ(Group_GetCount(g[1]), 3);
  526. ASSERT_EQ(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_EQ(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_EQ(result, INVALID_GROUP);
  556. call OnPlayerDisconnect(0, 0);
  557. }
  558. #define Y_GTEST_GROUP_NAME<%0...%1> %0Test%1
  559. #define Y_GTEST_GROUP_LIMIT 123
  560. #define Y_GTEST_GROUP_TAG _
  561. #include "y_groups__include"
  562. #define MASTER 60
  563. #include "..\..\YSI_Core\y_master"
  564. static
  565. gPl,
  566. gEl,
  567. bool:gS;
  568. Test_SetPlayer(el, playerid, bool:s)
  569. {
  570. P:1("Test_SetPlayer called: %d %d %d", el, playerid, s);
  571. gPl = playerid;
  572. gEl = el;
  573. gS = s;
  574. return 1;
  575. }
  576. TEST__ 0_y_groups_Connect0()
  577. {
  578. gPl = INVALID_PLAYER_ID;
  579. gEl = 100;
  580. gS = false;
  581. //new
  582. // Group:g = Group_Create();
  583. call OnPlayerConnect(45);
  584. ASSERT_EQ(gPl, INVALID_PLAYER_ID);
  585. ASSERT_EQ(gEl, 100);
  586. ASSERT_EQ(gS, false);
  587. //printf("%d %d %d", gPl, gEl, gS);
  588. Test_InitialiseFromGroups(7);
  589. ASSERT_EQ(gPl, 45);
  590. ASSERT_EQ(gEl, 7);
  591. ASSERT_EQ(gS, true);
  592. call OnPlayerDisconnect(45, 0);
  593. }
  594. TEST__ 0_y_groups_Connect1()
  595. {
  596. gPl = INVALID_PLAYER_ID;
  597. gEl = 100;
  598. gS = false;
  599. //new
  600. // Group:g = Group_Create();
  601. Test_InitialiseFromGroups(8);
  602. ASSERT_NE(gPl, INVALID_PLAYER_ID);
  603. ASSERT_NE(gEl, 100);
  604. ASSERT_NE(gS, false);
  605. call OnPlayerConnect(43);
  606. ASSERT_EQ(gPl, 43);
  607. ASSERT_EQ(gEl, 8);
  608. ASSERT_EQ(gS, true);
  609. call OnPlayerDisconnect(43, 0);
  610. }
  611. TEST__ y_groups_Chains()
  612. {
  613. new
  614. Group:g = Group_Create();
  615. call OnPlayerConnect(44);
  616. ASSERT_FALSE(Group_GetPlayer(g, 44));
  617. Group_SetGlobalGroup(g, true);
  618. ASSERT_TRUE(Group_GetPlayer(g, 44));
  619. call OnPlayerDisconnect(44, 0);
  620. }
  621. TEST__ y_groups_Children0()
  622. {
  623. new
  624. Group:g0 = Group_Create();
  625. ASSERT(!Group_GetGlobalGroup(g0));
  626. Group_Destroy(g0);
  627. }
  628. TEST__ y_groups_Children1()
  629. {
  630. new
  631. Group:g0 = Group_Create(),
  632. Group:g1 = Group_Create(),
  633. Group:g2 = Group_Create();
  634. // Check groups ARE descendants of themselves.
  635. ASSERT(Group_IsDescendant(GROUP_GLOBAL, GROUP_GLOBAL));
  636. ASSERT(Group_IsDescendant(g0, g0));
  637. ASSERT(Group_IsDescendant(g1, g1));
  638. ASSERT(Group_IsDescendant(g2, g2));
  639. // Check there are no relationships at all.
  640. ASSERT(!Group_IsDescendant(g0, g1));
  641. ASSERT(!Group_IsDescendant(g0, g2));
  642. ASSERT(!Group_IsDescendant(g1, g0));
  643. ASSERT(!Group_IsDescendant(g1, g2));
  644. ASSERT(!Group_IsDescendant(g2, g0));
  645. ASSERT(!Group_IsDescendant(g2, g1));
  646. // Grlobal group.
  647. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g0));
  648. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g1));
  649. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g2));
  650. ASSERT(!Group_IsDescendant(g0, GROUP_GLOBAL));
  651. ASSERT(!Group_IsDescendant(g1, GROUP_GLOBAL));
  652. ASSERT(!Group_IsDescendant(g2, GROUP_GLOBAL));
  653. Group_Destroy(g0),
  654. Group_Destroy(g1),
  655. Group_Destroy(g2);
  656. }
  657. TEST__ y_groups_Children2()
  658. {
  659. new
  660. Group:g0 = Group_Create(),
  661. Group:g1 = Group_Create(),
  662. Group:g2 = Group_Create();
  663. // Check groups are children of themselves.
  664. ASSERT(!Group_GetGroup(GROUP_GLOBAL, GROUP_GLOBAL));
  665. ASSERT(!Group_GetGroup(g0, g0));
  666. ASSERT(!Group_GetGroup(g1, g1));
  667. ASSERT(!Group_GetGroup(g2, g2));
  668. // Check there are no relationships at all.
  669. ASSERT(!Group_GetGroup(g0, g1));
  670. ASSERT(!Group_GetGroup(g0, g2));
  671. ASSERT(!Group_GetGroup(g1, g0));
  672. ASSERT(!Group_GetGroup(g1, g2));
  673. ASSERT(!Group_GetGroup(g2, g0));
  674. ASSERT(!Group_GetGroup(g2, g1));
  675. // Grlobal group.
  676. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g0));
  677. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g1));
  678. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g2));
  679. ASSERT(!Group_GetGroup(g0, GROUP_GLOBAL));
  680. ASSERT(!Group_GetGroup(g1, GROUP_GLOBAL));
  681. ASSERT(!Group_GetGroup(g2, GROUP_GLOBAL));
  682. Group_Destroy(g0),
  683. Group_Destroy(g1),
  684. Group_Destroy(g2);
  685. }
  686. TEST__ y_groups_Children3()
  687. {
  688. new
  689. Group:g0 = Group_Create(),
  690. Group:g1 = Group_Create(),
  691. Group:g2 = Group_Create();
  692. Group_AddChild(g0, g1);
  693. ASSERT(Group_IsDescendant(g0, g1));
  694. // Check there are no other relationships.
  695. ASSERT(!Group_IsDescendant(g0, g2));
  696. ASSERT(!Group_IsDescendant(g1, g0));
  697. ASSERT(!Group_IsDescendant(g1, g2));
  698. ASSERT(!Group_IsDescendant(g2, g0));
  699. ASSERT(!Group_IsDescendant(g2, g1));
  700. Group_Destroy(g0),
  701. Group_Destroy(g1),
  702. Group_Destroy(g2);
  703. }
  704. TEST__ y_groups_Children4()
  705. {
  706. new
  707. Group:g0 = Group_Create(),
  708. Group:g1 = Group_Create(),
  709. Group:g2 = Group_Create();
  710. Group_AddChild(g0, g1);
  711. Group_AddChild(g1, g2);
  712. // Test chaining.
  713. ASSERT(Group_IsDescendant(g0, g1));
  714. ASSERT(Group_IsDescendant(g1, g2));
  715. ASSERT(Group_IsDescendant(g0, g2));
  716. // Check there are no reverse relationships.
  717. ASSERT(!Group_IsDescendant(g1, g0));
  718. ASSERT(!Group_IsDescendant(g2, g0));
  719. ASSERT(!Group_IsDescendant(g2, g1));
  720. Group_Destroy(g0),
  721. Group_Destroy(g1),
  722. Group_Destroy(g2);
  723. }
  724. TEST__ y_groups_Children5()
  725. {
  726. new
  727. Group:g0 = Group_Create(),
  728. Group:g1 = Group_Create(),
  729. Group:g2 = Group_Create(),
  730. Group:g3 = Group_Create(),
  731. Group:g4 = Group_Create();
  732. Group_AddChild(g0, g1);
  733. Group_AddChild(g1, g2);
  734. Group_AddChild(g2, g0);
  735. Group_AddChild(g4, g0);
  736. // Test cycles don't hang.
  737. ASSERT(!Group_IsDescendant(g4, g3));
  738. ASSERT(!Group_IsDescendant(g3, g4));
  739. // Test cycles work.
  740. ASSERT(Group_IsDescendant(g4, g2));
  741. ASSERT(!Group_IsDescendant(g2, g4));
  742. ASSERT(Group_IsDescendant(g0, g2));
  743. ASSERT(Group_IsDescendant(g2, g0));
  744. Group_Destroy(g0),
  745. Group_Destroy(g1),
  746. Group_Destroy(g2);
  747. Group_Destroy(g3);
  748. Group_Destroy(g4);
  749. }
  750. TEST__ y_groups_Children6()
  751. {
  752. new
  753. Group:g0 = Group_Create(),
  754. Group:g1 = Group_Create(),
  755. Group:g2 = Group_Create();
  756. Group_AddChild(g0, g1);
  757. Group_AddChild(g1, g2);
  758. // Test removal
  759. ASSERT(Group_IsDescendant(g0, g2));
  760. Group_RemoveChild(g1, g2);
  761. ASSERT(!Group_IsDescendant(g0, g2));
  762. Group_AddChild(g1, g2);
  763. ASSERT(Group_IsDescendant(g0, g2));
  764. Group_Destroy(g1);
  765. ASSERT(!Group_IsDescendant(g0, g2));
  766. Group_Destroy(g0),
  767. Group_Destroy(g2);
  768. }
  769. TEST__ y_groups_Children7()
  770. {
  771. new
  772. Group:g0 = Group_Create(),
  773. Group:g1 = Group_Create(),
  774. Group:g2 = Group_Create();
  775. Group_AddChild(g0, g1);
  776. Group_AddChild(g1, g2);
  777. // Test chaining.
  778. ASSERT(Group_IsDescendant(g0, g1));
  779. ASSERT(Group_IsDescendant(g1, g2));
  780. ASSERT(Group_IsDescendant(g0, g2));
  781. // Check there are no reverse relationships.
  782. ASSERT(!Group_IsChild(g0, g2));
  783. Group_Destroy(g0),
  784. Group_Destroy(g1),
  785. Group_Destroy(g2);
  786. }
  787. TEST__ y_groups_ChildIterator0()
  788. {
  789. new
  790. Group:g0 = Group_Create(),
  791. Group:g1 = Group_Create(),
  792. Group:g2 = Group_Create();
  793. Group_AddChild(g0, g1);
  794. Group_AddChild(g0, g2);
  795. new
  796. total = 0;
  797. FOREACH__ (new Group:g : GroupChild(g0))
  798. {
  799. ++total;
  800. }
  801. ASSERT_EQ(total, 2);
  802. Group_Destroy(g0),
  803. Group_Destroy(g1),
  804. Group_Destroy(g2);
  805. }
  806. TEST__ y_groups_ChildIterator1()
  807. {
  808. new
  809. Group:g0 = Group_Create(),
  810. Group:g1 = Group_Create(),
  811. Group:g2 = Group_Create();
  812. Group_AddChild(g0, g1);
  813. Group_AddChild(g0, g2);
  814. ASSERT(Group_IsValid(g0));
  815. ASSERT(Group_IsValid(g1));
  816. ASSERT(Group_IsValid(g2));
  817. FOREACH__ (new Group:g : GroupChild(g0))
  818. {
  819. Group_Destroy(g);
  820. }
  821. ASSERT(Group_IsValid(g0));
  822. ASSERT(!Group_IsValid(g1));
  823. ASSERT(!Group_IsValid(g2));
  824. Group_Destroy(g0),
  825. ASSERT(!Group_IsValid(g0));
  826. }
  827. TEST__ y_groups_ChildIterator2()
  828. {
  829. new
  830. Group:g0 = Group_Create(),
  831. Group:g1 = Group_Create(),
  832. Group:g2 = Group_Create();
  833. Group_AddChild(g0, g1);
  834. Group_AddChild(g0, g2);
  835. ASSERT(Group_IsValid(g0));
  836. ASSERT(Group_IsValid(g1));
  837. ASSERT(Group_IsValid(g2));
  838. new
  839. total = 0;
  840. FOREACH__ (new Group:g : GroupChild[g0])
  841. {
  842. Group_Destroy(g);
  843. ++total;
  844. }
  845. ASSERT_EQ(total, 2);
  846. ASSERT(Group_IsValid(g0));
  847. ASSERT(!Group_IsValid(g1));
  848. ASSERT(!Group_IsValid(g2));
  849. Group_Destroy(g0),
  850. ASSERT(!Group_IsValid(g0));
  851. }
  852. TEST__ y_groups_Iterator0()
  853. {
  854. new
  855. Group:g0 = Group_Create(),
  856. Group:g1 = Group_Create(),
  857. Group:g2 = Group_Create();
  858. new
  859. total = 0;
  860. FOREACH__ (new Group:g : CreatedGroup)
  861. {
  862. ++total;
  863. }
  864. ASSERT(total >= 3);
  865. total = 0;
  866. FOREACH__ (new Group:g : CreatedGroup())
  867. {
  868. ++total;
  869. }
  870. ASSERT(total >= 3);
  871. Group_Destroy(g0),
  872. Group_Destroy(g1),
  873. Group_Destroy(g2);
  874. }