tests.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. #assert MAX_PLAYERS >= 50
  2. Test:000_y_groups_Global()
  3. {
  4. // Need a certain number just to run this code.
  5. call OnPlayerConnect(42);
  6. ASSERT(Group_GetPlayer(GROUP_GLOBAL, 42));
  7. //call OnPlayerDisconnect(42, 0);
  8. }
  9. Test:y_groups_Valid()
  10. {
  11. new
  12. Group:g = Group_Create("Valid"),
  13. Group:i = Group_Create("Invalid");
  14. Group_Destroy(i);
  15. ASSERT_TRUE(Group_IsValid(g));
  16. ASSERT_FALSE(Group_IsValid(i));
  17. ASSERT_FALSE(Group_IsValid(Group:3));
  18. Group_Destroy(g);
  19. }
  20. Test:y_groups_Create0()
  21. {
  22. new
  23. Group:g = Group_Create();
  24. ASSERT(g != INVALID_GROUP);
  25. Group_Destroy(g);
  26. }
  27. Test:y_groups_Create0b()
  28. {
  29. new
  30. Group:g0 = Group_Create("hello"),
  31. Group:g1 = Group_Create("there");
  32. ASSERT(g0 != INVALID_GROUP);
  33. ASSERT(g1 != INVALID_GROUP);
  34. ASSERT(g0 != g1);
  35. Group_Destroy(g0);
  36. Group_Destroy(g1);
  37. }
  38. Test:y_groups_Create1()
  39. {
  40. new
  41. Group:g = Group_Create("Group 1");
  42. ASSERT(g != INVALID_GROUP);
  43. Group_Destroy(g);
  44. }
  45. Test:y_groups_GetID()
  46. {
  47. new
  48. Group:g = Group_Create("Group 2");
  49. ASSERT(g == Group_GetID("Group 2"));
  50. ASSERT(!strcmp("Group 2", Group_GetName(g)));
  51. Group_Destroy(g);
  52. }
  53. Test:y_groups_GetGang0()
  54. {
  55. new
  56. Group:g = Group_Create("Group 3");
  57. ASSERT_FALSE(Group_GetGang(g));
  58. Group_Destroy(g);
  59. }
  60. Test:y_groups_GetGang1()
  61. {
  62. new
  63. Group:g = Group_Create("Group 4");
  64. Group_SetGang(g, true);
  65. ASSERT_TRUE(Group_GetGang(g));
  66. Group_Destroy(g);
  67. }
  68. Test:y_groups_GetGang2()
  69. {
  70. new
  71. Group:g = Group_Create("Group 5");
  72. Group_SetGang(g, true);
  73. Group_SetGang(g, false);
  74. ASSERT_FALSE(Group_GetGang(g));
  75. Group_Destroy(g);
  76. }
  77. Test:y_groups_GetColour()
  78. {
  79. new
  80. Group:g = Group_Create("Group 6");
  81. Group_SetColour(g, 0x11227654);
  82. ASSERT(Group_GetColor(g) == 0x112276AA);
  83. Group_SetColour(g, 0x76541122);
  84. ASSERT(Group_GetColor(g) == 0x765411AA);
  85. Group_SetColour(g, 0x65127412);
  86. ASSERT(Group_GetColor(g) == 0x651274AA);
  87. Group_Destroy(g);
  88. }
  89. Test:y_groups_Set1()
  90. {
  91. new
  92. Group:g = Group_Create("Group 7");
  93. ASSERT(Group_GetCount(g) == 0);
  94. Group_SetPlayer(g, 42, true);
  95. ASSERT_TRUE(Group_GetPlayer(g, 42));
  96. ASSERT(Group_GetCount(g) == 1);
  97. new
  98. c = 0;
  99. foreach (new p : GroupMember(g))
  100. {
  101. ASSERT(p == 42);
  102. ++c;
  103. }
  104. ASSERT(c == 1);
  105. Group_Destroy(g);
  106. }
  107. Test:y_groups_Set2()
  108. {
  109. new
  110. Group:g = Group_Create("Group 8");
  111. ASSERT(Group_GetCount(g) == 0);
  112. //new k = Group_SetPlayer(g, 42, true);
  113. Group_SetPlayer(g, 42, true);
  114. ASSERT(Group_GetCount(g) == 1);
  115. Group_SetPlayer(g, 42, false);
  116. ASSERT(Group_GetCount(g) == 0);
  117. new
  118. c = 0;
  119. foreach (new p : GroupMember(g))
  120. {
  121. ++c;
  122. }
  123. ASSERT(c == 0);
  124. Group_Destroy(g);
  125. }
  126. Test:y_groups_Set3()
  127. {
  128. new
  129. Group:g = Group_Create("Group 8");
  130. Group_SetPlayer(g, 42, true);
  131. ASSERT(Group_GetCount(g) == 1);
  132. //W@(#On#PlayerDisconnect ,x:#ii#,42, 0);
  133. call OnPlayerDisconnect(42, 0);
  134. //ASSERT(Group_GetCount(g) == 0);
  135. //call OnPlayerConnect(42);
  136. //ASSERT(Group_GetCount(g) == 0);
  137. Group_Destroy(g);
  138. }
  139. #define MASTER 60
  140. #tryinclude "..\YSI_Core\y_master"
  141. #tryinclude "..\..\YSI_Core\y_master"
  142. #define _GROUP_MAKE_NAME<%0...%1> %0Test%1
  143. #define _GROUP_MAKE_LIMIT 123
  144. #tryinclude "y_groups\_funcs"
  145. #tryinclude "_funcs"
  146. static
  147. gPl,
  148. gEl,
  149. bool:gS;
  150. Test_SetPlayer(el, playerid, bool:s)
  151. {
  152. P:1("Test_SetPlayer called: %d %d %d", el, playerid, s);
  153. gPl = playerid;
  154. gEl = el;
  155. gS = s;
  156. return 1;
  157. }
  158. Test:0_y_groups_Connect0()
  159. {
  160. gPl = INVALID_PLAYER_ID;
  161. gEl = 100;
  162. gS = false;
  163. //new
  164. // Group:g = Group_Create();
  165. call OnPlayerConnect(45);
  166. ASSERT(gPl == INVALID_PLAYER_ID);
  167. ASSERT(gEl == 100);
  168. ASSERT(gS == false);
  169. //printf("%d %d %d", gPl, gEl, gS);
  170. Test_InitialiseFromGroups(7);
  171. ASSERT(gPl == 45);
  172. ASSERT(gEl == 7);
  173. ASSERT(gS == true);
  174. call OnPlayerDisconnect(45, 0);
  175. }
  176. Test:0_y_groups_Connect1()
  177. {
  178. gPl = INVALID_PLAYER_ID;
  179. gEl = 100;
  180. gS = false;
  181. //new
  182. // Group:g = Group_Create();
  183. Test_InitialiseFromGroups(8);
  184. ASSERT(gPl != INVALID_PLAYER_ID);
  185. ASSERT(gEl != 100);
  186. ASSERT(gS != false);
  187. call OnPlayerConnect(43);
  188. ASSERT(gPl == 43);
  189. ASSERT(gEl == 8);
  190. ASSERT(gS == true);
  191. call OnPlayerDisconnect(43, 0);
  192. }
  193. Test:y_groups_Chains()
  194. {
  195. new
  196. Group:g = Group_Create();
  197. call OnPlayerConnect(44);
  198. ASSERT_FALSE(Group_GetPlayer(g, 44));
  199. Group_SetGlobalGroup(g, true);
  200. ASSERT_TRUE(Group_GetPlayer(g, 44));
  201. call OnPlayerDisconnect(44, 0);
  202. }
  203. Test:y_groups_Children0()
  204. {
  205. new
  206. Group:g0 = Group_Create();
  207. ASSERT(!Group_GetGlobalGroup(g0));
  208. Group_Destroy(g0);
  209. }
  210. Test:y_groups_Children1()
  211. {
  212. new
  213. Group:g0 = Group_Create(),
  214. Group:g1 = Group_Create(),
  215. Group:g2 = Group_Create();
  216. // Check groups ARE descendants of themselves.
  217. ASSERT(Group_IsDescendant(GROUP_GLOBAL, GROUP_GLOBAL));
  218. ASSERT(Group_IsDescendant(g0, g0));
  219. ASSERT(Group_IsDescendant(g1, g1));
  220. ASSERT(Group_IsDescendant(g2, g2));
  221. // Check there are no relationships at all.
  222. ASSERT(!Group_IsDescendant(g0, g1));
  223. ASSERT(!Group_IsDescendant(g0, g2));
  224. ASSERT(!Group_IsDescendant(g1, g0));
  225. ASSERT(!Group_IsDescendant(g1, g2));
  226. ASSERT(!Group_IsDescendant(g2, g0));
  227. ASSERT(!Group_IsDescendant(g2, g1));
  228. // Grlobal group.
  229. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g0));
  230. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g1));
  231. ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g2));
  232. ASSERT(!Group_IsDescendant(g0, GROUP_GLOBAL));
  233. ASSERT(!Group_IsDescendant(g1, GROUP_GLOBAL));
  234. ASSERT(!Group_IsDescendant(g2, GROUP_GLOBAL));
  235. Group_Destroy(g0),
  236. Group_Destroy(g1),
  237. Group_Destroy(g2);
  238. }
  239. Test:y_groups_Children2()
  240. {
  241. new
  242. Group:g0 = Group_Create(),
  243. Group:g1 = Group_Create(),
  244. Group:g2 = Group_Create();
  245. // Check groups are children of themselves.
  246. ASSERT(!Group_GetGroup(GROUP_GLOBAL, GROUP_GLOBAL));
  247. ASSERT(!Group_GetGroup(g0, g0));
  248. ASSERT(!Group_GetGroup(g1, g1));
  249. ASSERT(!Group_GetGroup(g2, g2));
  250. // Check there are no relationships at all.
  251. ASSERT(!Group_GetGroup(g0, g1));
  252. ASSERT(!Group_GetGroup(g0, g2));
  253. ASSERT(!Group_GetGroup(g1, g0));
  254. ASSERT(!Group_GetGroup(g1, g2));
  255. ASSERT(!Group_GetGroup(g2, g0));
  256. ASSERT(!Group_GetGroup(g2, g1));
  257. // Grlobal group.
  258. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g0));
  259. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g1));
  260. ASSERT(!Group_GetGroup(GROUP_GLOBAL, g2));
  261. ASSERT(!Group_GetGroup(g0, GROUP_GLOBAL));
  262. ASSERT(!Group_GetGroup(g1, GROUP_GLOBAL));
  263. ASSERT(!Group_GetGroup(g2, GROUP_GLOBAL));
  264. Group_Destroy(g0),
  265. Group_Destroy(g1),
  266. Group_Destroy(g2);
  267. }
  268. Test:y_groups_Children3()
  269. {
  270. new
  271. Group:g0 = Group_Create(),
  272. Group:g1 = Group_Create(),
  273. Group:g2 = Group_Create();
  274. Group_AddChild(g0, g1);
  275. ASSERT(Group_IsDescendant(g0, g1));
  276. // Check there are no other relationships.
  277. ASSERT(!Group_IsDescendant(g0, g2));
  278. ASSERT(!Group_IsDescendant(g1, g0));
  279. ASSERT(!Group_IsDescendant(g1, g2));
  280. ASSERT(!Group_IsDescendant(g2, g0));
  281. ASSERT(!Group_IsDescendant(g2, g1));
  282. Group_Destroy(g0),
  283. Group_Destroy(g1),
  284. Group_Destroy(g2);
  285. }
  286. Test:y_groups_Children4()
  287. {
  288. new
  289. Group:g0 = Group_Create(),
  290. Group:g1 = Group_Create(),
  291. Group:g2 = Group_Create();
  292. Group_AddChild(g0, g1);
  293. Group_AddChild(g1, g2);
  294. // Test chaining.
  295. ASSERT(Group_IsDescendant(g0, g1));
  296. ASSERT(Group_IsDescendant(g1, g2));
  297. ASSERT(Group_IsDescendant(g0, g2));
  298. // Check there are no reverse relationships.
  299. ASSERT(!Group_IsDescendant(g1, g0));
  300. ASSERT(!Group_IsDescendant(g2, g0));
  301. ASSERT(!Group_IsDescendant(g2, g1));
  302. Group_Destroy(g0),
  303. Group_Destroy(g1),
  304. Group_Destroy(g2);
  305. }
  306. Test:y_groups_Children5()
  307. {
  308. new
  309. Group:g0 = Group_Create(),
  310. Group:g1 = Group_Create(),
  311. Group:g2 = Group_Create(),
  312. Group:g3 = Group_Create(),
  313. Group:g4 = Group_Create();
  314. Group_AddChild(g0, g1);
  315. Group_AddChild(g1, g2);
  316. Group_AddChild(g2, g0);
  317. Group_AddChild(g4, g0);
  318. // Test cycles don't hang.
  319. ASSERT(!Group_IsDescendant(g4, g3));
  320. ASSERT(!Group_IsDescendant(g3, g4));
  321. // Test cycles work.
  322. ASSERT(Group_IsDescendant(g4, g2));
  323. ASSERT(!Group_IsDescendant(g2, g4));
  324. ASSERT(Group_IsDescendant(g0, g2));
  325. ASSERT(Group_IsDescendant(g2, g0));
  326. Group_Destroy(g0),
  327. Group_Destroy(g1),
  328. Group_Destroy(g2);
  329. Group_Destroy(g3);
  330. Group_Destroy(g4);
  331. }
  332. Test:y_groups_Children6()
  333. {
  334. new
  335. Group:g0 = Group_Create(),
  336. Group:g1 = Group_Create(),
  337. Group:g2 = Group_Create();
  338. Group_AddChild(g0, g1);
  339. Group_AddChild(g1, g2);
  340. // Test removal
  341. ASSERT(Group_IsDescendant(g0, g2));
  342. Group_RemoveChild(g1, g2);
  343. ASSERT(!Group_IsDescendant(g0, g2));
  344. Group_AddChild(g1, g2);
  345. ASSERT(Group_IsDescendant(g0, g2));
  346. Group_Destroy(g1);
  347. ASSERT(!Group_IsDescendant(g0, g2));
  348. Group_Destroy(g0),
  349. Group_Destroy(g2);
  350. }
  351. Test:y_groups_Children7()
  352. {
  353. new
  354. Group:g0 = Group_Create(),
  355. Group:g1 = Group_Create(),
  356. Group:g2 = Group_Create();
  357. Group_AddChild(g0, g1);
  358. Group_AddChild(g1, g2);
  359. // Test chaining.
  360. ASSERT(Group_IsDescendant(g0, g1));
  361. ASSERT(Group_IsDescendant(g1, g2));
  362. ASSERT(Group_IsDescendant(g0, g2));
  363. // Check there are no reverse relationships.
  364. ASSERT(!Group_IsChild(g0, g2));
  365. Group_Destroy(g0),
  366. Group_Destroy(g1),
  367. Group_Destroy(g2);
  368. }
  369. Test:y_groups_ChildIterator0()
  370. {
  371. new
  372. Group:g0 = Group_Create(),
  373. Group:g1 = Group_Create(),
  374. Group:g2 = Group_Create();
  375. Group_AddChild(g0, g1);
  376. Group_AddChild(g0, g2);
  377. new
  378. total = 0;
  379. foreach (new Group:g : GroupChild(g0))
  380. {
  381. ++total;
  382. }
  383. ASSERT(total == 2);
  384. Group_Destroy(g0),
  385. Group_Destroy(g1),
  386. Group_Destroy(g2);
  387. }
  388. Test:y_groups_ChildIterator1()
  389. {
  390. new
  391. Group:g0 = Group_Create(),
  392. Group:g1 = Group_Create(),
  393. Group:g2 = Group_Create();
  394. Group_AddChild(g0, g1);
  395. Group_AddChild(g0, g2);
  396. ASSERT(Group_IsValid(g0));
  397. ASSERT(Group_IsValid(g1));
  398. ASSERT(Group_IsValid(g2));
  399. foreach (new Group:g : GroupChild(g0))
  400. {
  401. Group_Destroy(g);
  402. }
  403. ASSERT(Group_IsValid(g0));
  404. ASSERT(!Group_IsValid(g1));
  405. ASSERT(!Group_IsValid(g2));
  406. Group_Destroy(g0),
  407. ASSERT(!Group_IsValid(g0));
  408. }
  409. Test:y_groups_ChildIterator2()
  410. {
  411. new
  412. Group:g0 = Group_Create(),
  413. Group:g1 = Group_Create(),
  414. Group:g2 = Group_Create();
  415. Group_AddChild(g0, g1);
  416. Group_AddChild(g0, g2);
  417. ASSERT(Group_IsValid(g0));
  418. ASSERT(Group_IsValid(g1));
  419. ASSERT(Group_IsValid(g2));
  420. new
  421. total = 0;
  422. foreach (new Group:g : GroupChild[g0])
  423. {
  424. Group_Destroy(g);
  425. ++total;
  426. }
  427. ASSERT(total == 2);
  428. ASSERT(Group_IsValid(g0));
  429. ASSERT(!Group_IsValid(g1));
  430. ASSERT(!Group_IsValid(g2));
  431. Group_Destroy(g0),
  432. ASSERT(!Group_IsValid(g0));
  433. }
  434. Test:y_groups_Iterator0()
  435. {
  436. new
  437. Group:g0 = Group_Create(),
  438. Group:g1 = Group_Create(),
  439. Group:g2 = Group_Create();
  440. new
  441. total = 0;
  442. foreach (new Group:g : CreatedGroup)
  443. {
  444. ++total;
  445. }
  446. ASSERT(total >= 3);
  447. total = 0;
  448. foreach (new Group:g : CreatedGroup())
  449. {
  450. ++total;
  451. }
  452. ASSERT(total >= 3);
  453. Group_Destroy(g0),
  454. Group_Destroy(g1),
  455. Group_Destroy(g2);
  456. }
  457. #undef _GROUP_MAKE_LIMIT
  458. #undef _GROUP_MAKE_NAME
  459. #tryinclude "..\YSI_Core\y_master"
  460. #tryinclude "..\..\YSI_Core\y_master"