| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007 |
- /*
- Legal:
- Version: MPL 1.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 the "License"; you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is the YSI framework.
-
- The Initial Developer of the Original Code is Alex "Y_Less" Cole.
- Portions created by the Initial Developer are Copyright C 2011
- the Initial Developer. All Rights Reserved.
- Contributors:
- Y_Less
- koolk
- JoeBullet/Google63
- g_aSlice/Slice
- Misiur
- samphunter
- tianmeta
- maddinat0r
- spacemud
- Crayder
- Dayvison
- Ahmad45123
- Zeex
- irinel1996
- Yiin-
- Chaprnks
- Konstantinos
- Masterchen09
- Southclaws
- PatchwerkQWER
- m0k1
- paulommu
- udan111
- Thanks:
- JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
- ZeeX - Very productive conversations.
- koolk - IsPlayerinAreaEx code.
- TheAlpha - Danish translation.
- breadfish - German translation.
- Fireburn - Dutch translation.
- yom - French translation.
- 50p - Polish translation.
- Zamaroht - Spanish translation.
- Los - Portuguese translation.
- Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes for
- me to strive to better.
- Pixels^ - Running XScripters where the idea was born.
- Matite - Pestering me to release it and using it.
- Very special thanks to:
- Thiadmer - PAWN, whose limits continue to amaze me!
- Kye/Kalcor - SA:MP.
- SA:MP Team past, present and future - SA:MP.
- Optional plugins:
- Gamer_Z - GPS.
- Incognito - Streamer.
- Me - sscanf2, fixes2, Whirlpool.
- */
- #assert MAX_PLAYERS >= 50
- Test:000_y_groups_Global()
- {
- // Need a certain number just to run this code.
- call OnPlayerConnect(42);
- ASSERT(Group_GetPlayer(GROUP_GLOBAL, 42));
- //call OnPlayerDisconnect(42, 0);
- }
- Test:y_groups_Valid()
- {
- new
- Group:g = Group_Create("Valid"),
- Group:i = Group_Create("Invalid");
- Group_Destroy(i);
- ASSERT_TRUE(Group_IsValid(g));
- ASSERT_FALSE(Group_IsValid(i));
- ASSERT_FALSE(Group_IsValid(Group:3));
- Group_Destroy(g);
- }
- Test:y_groups_Create0()
- {
- new
- Group:g = Group_Create();
- ASSERT(g != INVALID_GROUP);
- Group_Destroy(g);
- }
- Test:y_groups_Create0b()
- {
- new
- Group:g0 = Group_Create("hello"),
- Group:g1 = Group_Create("there");
- ASSERT(g0 != INVALID_GROUP);
- ASSERT(g1 != INVALID_GROUP);
- ASSERT(g0 != g1);
- Group_Destroy(g0);
- Group_Destroy(g1);
- }
- Test:y_groups_Create1()
- {
- new
- Group:g = Group_Create("Group 1");
- ASSERT(g != INVALID_GROUP);
- Group_Destroy(g);
- }
- Test:y_groups_GetID()
- {
- new
- Group:g = Group_Create("Group 2");
- ASSERT(g == Group_GetID("Group 2"));
- ASSERT(!strcmp("Group 2", Group_GetName(g)));
- Group_Destroy(g);
- }
- Test:y_groups_GetGang0()
- {
- new
- Group:g = Group_Create("Group 3");
- ASSERT_FALSE(Group_GetGang(g));
- Group_Destroy(g);
- }
- Test:y_groups_GetGang1()
- {
- new
- Group:g = Group_Create("Group 4");
- Group_SetGang(g, true);
- ASSERT_TRUE(Group_GetGang(g));
- Group_Destroy(g);
- }
- Test:y_groups_GetGang2()
- {
- new
- Group:g = Group_Create("Group 5");
- Group_SetGang(g, true);
- Group_SetGang(g, false);
- ASSERT_FALSE(Group_GetGang(g));
- Group_Destroy(g);
- }
- Test:y_groups_GetColour()
- {
- new
- Group:g = Group_Create("Group 6");
- Group_SetColour(g, 0x11227654);
- ASSERT(Group_GetColor(g) == 0x112276AA);
- Group_SetColour(g, 0x76541122);
- ASSERT(Group_GetColor(g) == 0x765411AA);
- Group_SetColour(g, 0x65127412);
- ASSERT(Group_GetColor(g) == 0x651274AA);
- Group_Destroy(g);
- }
- Test:y_groups_Set1()
- {
- new
- Group:g = Group_Create("Group 7");
- ASSERT(Group_GetCount(g) == 0);
- Group_SetPlayer(g, 42, true);
- ASSERT_TRUE(Group_GetPlayer(g, 42));
- ASSERT(Group_GetCount(g) == 1);
- new
- c = 0;
- foreach (new p : GroupMember[g])
- {
- ASSERT(p == 42);
- ++c;
- }
- ASSERT(c == 1);
- Group_Destroy(g);
- }
- Test:y_groups_Set2()
- {
- new
- Group:g = Group_Create("Group 8");
- ASSERT(Group_GetCount(g) == 0);
- //new k = Group_SetPlayer(g, 42, true);
- Group_SetPlayer(g, 42, true);
- ASSERT(Group_GetCount(g) == 1);
- Group_SetPlayer(g, 42, false);
- ASSERT(Group_GetCount(g) == 0);
- new
- c = 0;
- foreach (new p : GroupMember(g))
- {
- ++c;
- }
- ASSERT(c == 0);
- Group_Destroy(g);
- }
- Test:y_groups_Set3()
- {
- new
- Group:g = Group_Create("Group 8");
- Group_SetPlayer(g, 42, true);
- ASSERT(Group_GetCount(g) == 1);
- call OnPlayerDisconnect(42, 0);
- Group_Destroy(g);
- }
- Test:y_groups_SetBalanced0()
- {
- new
- Group:g1 = Group_Create("Group 1"),
- Group:g2 = Group_Create("Group 2");
-
- call OnPlayerConnect(22);
-
- Group_SetPlayer(g2, 22, true);
- Group_SetBalanced(22, g1, g2);
-
- ASSERT(Group_GetCount(g1) == 0 && Group_GetCount(g2) == 1);
-
- call OnPlayerDisconnect(22, 0);
-
- Group_Destroy(g1);
- Group_Destroy(g2);
- }
- Test:y_groups_SetBalanced1()
- {
- new
- Group:g1 = Group_Create("Group 1"),
- Group:g2 = Group_Create("Group 2");
-
- call OnPlayerConnect(23);
- call OnPlayerConnect(32);
-
- Group_SetBalanced(23, g1, g2);
- Group_SetBalanced(32, g1, g2);
-
- ASSERT(Group_GetCount(g1) == 1 && Group_GetCount(g2) == 1);
-
- call OnPlayerDisconnect(23, 0);
- call OnPlayerDisconnect(32, 0);
-
- Group_Destroy(g1);
- Group_Destroy(g2);
- }
- Test:y_groups_SetBalanced2()
- {
- new
- Group:g1 = Group_Create("Group 1"),
- Group:g2 = Group_Create("Group 2"),
- Group:g3 = Group_Create("Group 3");
-
- call OnPlayerConnect(1);
- call OnPlayerConnect(2);
- call OnPlayerConnect(3);
- call OnPlayerConnect(4);
- call OnPlayerConnect(5);
- call OnPlayerConnect(6);
-
- Group_SetBalanced(1, g1, g2, g3);
- Group_SetBalanced(2, g1, g2, g3);
- Group_SetBalanced(3, g1, g2, g3);
- Group_SetBalanced(4, g1, g2, g3);
- Group_SetBalanced(5, g1, g2, g3);
- Group_SetBalanced(6, g1, g2, g3);
-
- ASSERT(Group_GetCount(g1) == 2 && Group_GetCount(g2) == 2 && Group_GetCount(g3) == 2);
-
- call OnPlayerDisconnect(1, 0);
- call OnPlayerDisconnect(2, 0);
- call OnPlayerDisconnect(3, 0);
- call OnPlayerDisconnect(4, 0);
- call OnPlayerDisconnect(5, 0);
- call OnPlayerDisconnect(6, 0);
-
- Group_Destroy(g1);
- Group_Destroy(g2);
- Group_Destroy(g3);
- }
- Test:y_groups_SetBalanced3()
- {
- new
- Group:g[3];
- g[0] = Group_Create("Group 1");
- g[1] = Group_Create("Group 2");
- g[2] = Group_Create("Group 3");
- call OnPlayerConnect(0);
- call OnPlayerConnect(1);
- call OnPlayerConnect(2);
- call OnPlayerConnect(3);
- call OnPlayerConnect(4);
- call OnPlayerConnect(5);
- call OnPlayerConnect(6);
- Group_SetBalancedArray(0, g, sizeof(g));
- Group_SetBalancedArray(1, g, sizeof(g));
- Group_SetBalancedArray(2, g, sizeof(g));
- Group_SetBalancedArray(3, g, sizeof(g));
- Group_SetBalancedArray(4, g, sizeof(g));
- Group_SetBalancedArray(5, g, sizeof(g));
- Group_SetBalancedArray(6, g, sizeof(g));
- ASSERT(Group_GetCount(g[0]) == 3);
- ASSERT(Group_GetCount(g[1]) == 2);
- ASSERT(Group_GetCount(g[2]) == 2);
- call OnPlayerDisconnect(0, 0);
- call OnPlayerDisconnect(1, 0);
- call OnPlayerDisconnect(2, 0);
- call OnPlayerDisconnect(3, 0);
- call OnPlayerDisconnect(4, 0);
- call OnPlayerDisconnect(5, 0);
- call OnPlayerDisconnect(6, 0);
- Group_Destroy(g[0]);
- Group_Destroy(g[1]);
- Group_Destroy(g[2]);
- }
- Test:y_groups_SetBalancedIn1()
- {
- new
- Group:g[3];
- g[0] = Group_Create("Group 1");
- g[1] = Group_Create("Group 2");
- g[2] = Group_Create("Group 3");
- call OnPlayerConnect(0);
- call OnPlayerConnect(1);
- call OnPlayerConnect(2);
- call OnPlayerConnect(3);
- call OnPlayerConnect(4);
- call OnPlayerConnect(5);
- call OnPlayerConnect(6);
-
- Group_SetPlayer(g[0], 0, true);
- Group_SetPlayer(g[0], 1, true);
- Group_SetPlayer(g[0], 2, true);
- Group_SetPlayer(g[2], 3, true);
- Group_SetPlayer(g[2], 4, true);
- Group_SetPlayer(g[2], 5, true);
- Group_SetBalancedArray(6, g, sizeof(g));
- ASSERT(Group_GetCount(g[0]) == 3);
- ASSERT(Group_GetCount(g[1]) == 1);
- ASSERT(Group_GetCount(g[2]) == 3);
- call OnPlayerDisconnect(0, 0);
- call OnPlayerDisconnect(1, 0);
- call OnPlayerDisconnect(2, 0);
- call OnPlayerDisconnect(3, 0);
- call OnPlayerDisconnect(4, 0);
- call OnPlayerDisconnect(5, 0);
- call OnPlayerDisconnect(6, 0);
- Group_Destroy(g[0]);
- Group_Destroy(g[1]);
- Group_Destroy(g[2]);
- }
- Test:y_groups_SetBalancedIn2()
- {
- new
- Group:g[3];
- g[0] = Group_Create("Group 1");
- g[1] = Group_Create("Group 2");
- g[2] = Group_Create("Group 3");
- call OnPlayerConnect(0);
- call OnPlayerConnect(1);
- call OnPlayerConnect(2);
- call OnPlayerConnect(3);
- call OnPlayerConnect(4);
- call OnPlayerConnect(5);
- call OnPlayerConnect(6);
-
- Group_SetPlayer(g[0], 0, true);
- Group_SetPlayer(g[0], 1, true);
- Group_SetPlayer(g[0], 2, true);
- Group_SetPlayer(g[2], 3, true);
- Group_SetPlayer(g[2], 4, true);
- Group_SetPlayer(g[2], 5, true);
- Group_SetBalancedArray(0, g, sizeof(g));
- ASSERT(Group_GetCount(g[0]) == 3);
- ASSERT(Group_GetCount(g[1]) == 0);
- ASSERT(Group_GetCount(g[2]) == 3);
- call OnPlayerDisconnect(0, 0);
- call OnPlayerDisconnect(1, 0);
- call OnPlayerDisconnect(2, 0);
- call OnPlayerDisconnect(3, 0);
- call OnPlayerDisconnect(4, 0);
- call OnPlayerDisconnect(5, 0);
- call OnPlayerDisconnect(6, 0);
- Group_Destroy(g[0]);
- Group_Destroy(g[1]);
- Group_Destroy(g[2]);
- }
- Test:y_groups_SetBalancedIn3()
- {
- new
- Group:g[3];
- g[0] = Group_Create("Group 1");
- g[1] = Group_Create("Group 2");
- g[2] = Group_Create("Group 3");
- call OnPlayerConnect(0);
- call OnPlayerConnect(1);
- call OnPlayerConnect(2);
- call OnPlayerConnect(3);
- call OnPlayerConnect(4);
- call OnPlayerConnect(5);
- call OnPlayerConnect(6);
-
- Group_SetPlayer(g[0], 0, true);
- Group_SetPlayer(g[0], 1, true);
- Group_SetPlayer(g[0], 2, true);
- Group_SetPlayer(g[2], 3, true);
- Group_SetPlayer(g[2], 4, true);
- Group_SetPlayer(g[2], 5, true);
- Group_SetBalancedArray(4, g, sizeof(g));
- ASSERT(Group_GetCount(g[0]) == 3);
- ASSERT(Group_GetCount(g[1]) == 0);
- ASSERT(Group_GetCount(g[2]) == 3);
- call OnPlayerDisconnect(0, 0);
- call OnPlayerDisconnect(1, 0);
- call OnPlayerDisconnect(2, 0);
- call OnPlayerDisconnect(3, 0);
- call OnPlayerDisconnect(4, 0);
- call OnPlayerDisconnect(5, 0);
- call OnPlayerDisconnect(6, 0);
- Group_Destroy(g[0]);
- Group_Destroy(g[1]);
- Group_Destroy(g[2]);
- }
- Test:y_groups_SetBalancedIn3a()
- {
- new
- Group:g[3];
- g[0] = Group_Create("Group 1");
- g[1] = Group_Create("Group 2");
- g[2] = Group_Create("Group 3");
- call OnPlayerConnect(0);
- call OnPlayerConnect(1);
- call OnPlayerConnect(2);
- call OnPlayerConnect(3);
- call OnPlayerConnect(4);
- call OnPlayerConnect(5);
- call OnPlayerConnect(6);
-
- Group_SetPlayer(g[0], 0, true);
- Group_SetPlayer(g[0], 1, true);
- Group_SetPlayer(g[1], 2, true);
- Group_SetPlayer(g[1], 3, true);
- Group_SetPlayer(g[2], 4, true);
- Group_SetPlayer(g[2], 5, true);
-
- Group_SetPlayer(g[0], 6, true);
- Group_SetBalancedArray(0, g, sizeof(g));
- ASSERT(Group_GetCount(g[0]) == 3);
- ASSERT(Group_GetCount(g[1]) == 2);
- ASSERT(Group_GetCount(g[2]) == 2);
- call OnPlayerDisconnect(0, 0);
- call OnPlayerDisconnect(1, 0);
- call OnPlayerDisconnect(2, 0);
- call OnPlayerDisconnect(3, 0);
- call OnPlayerDisconnect(4, 0);
- call OnPlayerDisconnect(5, 0);
- call OnPlayerDisconnect(6, 0);
- Group_Destroy(g[0]);
- Group_Destroy(g[1]);
- Group_Destroy(g[2]);
- }
- Test:y_groups_SetBalancedIn3b()
- {
- new
- Group:g[3];
- g[0] = Group_Create("Group 1");
- g[1] = Group_Create("Group 2");
- g[2] = Group_Create("Group 3");
- call OnPlayerConnect(0);
- call OnPlayerConnect(1);
- call OnPlayerConnect(2);
- call OnPlayerConnect(3);
- call OnPlayerConnect(4);
- call OnPlayerConnect(5);
- call OnPlayerConnect(6);
-
- Group_SetPlayer(g[0], 0, true);
- Group_SetPlayer(g[0], 1, true);
- Group_SetPlayer(g[1], 2, true);
- Group_SetPlayer(g[1], 3, true);
- Group_SetPlayer(g[2], 4, true);
- Group_SetPlayer(g[2], 5, true);
-
- Group_SetPlayer(g[1], 6, true);
- Group_SetBalancedArray(0, g, sizeof(g));
- ASSERT(Group_GetCount(g[0]) == 2);
- ASSERT(Group_GetCount(g[1]) == 3);
- ASSERT(Group_GetCount(g[2]) == 2);
- call OnPlayerDisconnect(0, 0);
- call OnPlayerDisconnect(1, 0);
- call OnPlayerDisconnect(2, 0);
- call OnPlayerDisconnect(3, 0);
- call OnPlayerDisconnect(4, 0);
- call OnPlayerDisconnect(5, 0);
- call OnPlayerDisconnect(6, 0);
- Group_Destroy(g[0]);
- Group_Destroy(g[1]);
- Group_Destroy(g[2]);
- }
- Test:y_groups_SetBalancedIn3c()
- {
- new
- Group:g[3];
- g[0] = Group_Create("Group 1");
- g[1] = Group_Create("Group 2");
- g[2] = Group_Create("Group 3");
- call OnPlayerConnect(0);
- call OnPlayerConnect(1);
- call OnPlayerConnect(2);
- call OnPlayerConnect(3);
- call OnPlayerConnect(4);
- call OnPlayerConnect(5);
- call OnPlayerConnect(6);
-
- Group_SetPlayer(g[0], 0, true);
- Group_SetPlayer(g[0], 1, true);
- Group_SetPlayer(g[1], 2, true);
- Group_SetPlayer(g[1], 3, true);
- Group_SetPlayer(g[2], 4, true);
- Group_SetPlayer(g[2], 5, true);
-
- Group_SetPlayer(g[2], 6, true);
- Group_SetBalancedArray(0, g, sizeof(g));
- ASSERT(Group_GetCount(g[0]) == 2);
- ASSERT(Group_GetCount(g[1]) == 2);
- ASSERT(Group_GetCount(g[2]) == 3);
- call OnPlayerDisconnect(0, 0);
- call OnPlayerDisconnect(1, 0);
- call OnPlayerDisconnect(2, 0);
- call OnPlayerDisconnect(3, 0);
- call OnPlayerDisconnect(4, 0);
- call OnPlayerDisconnect(5, 0);
- call OnPlayerDisconnect(6, 0);
- Group_Destroy(g[0]);
- Group_Destroy(g[1]);
- Group_Destroy(g[2]);
- }
- Test:y_groups_SetBalancedIn4()
- {
- new
- Group:g[3];
- g[0] = Group_Create("Group 1");
- g[1] = Group_Create("Group 2");
- g[2] = Group_Create("Group 3");
- call OnPlayerConnect(0);
- call OnPlayerConnect(1);
- call OnPlayerConnect(2);
- call OnPlayerConnect(3);
- call OnPlayerConnect(4);
- call OnPlayerConnect(5);
- call OnPlayerConnect(6);
-
- Group_SetPlayer(g[0], 0, true);
- Group_SetPlayer(g[0], 1, true);
- Group_SetPlayer(g[1], 2, true);
- Group_SetPlayer(g[1], 3, true);
- Group_SetPlayer(g[2], 4, true);
-
- Group_SetPlayer(g[1], 6, true);
- Group_SetBalancedArray(2, g, sizeof(g));
- ASSERT(Group_GetCount(g[0]) == 2);
- ASSERT(Group_GetCount(g[1]) == 3);
- ASSERT(Group_GetCount(g[2]) == 1);
- call OnPlayerDisconnect(0, 0);
- call OnPlayerDisconnect(1, 0);
- call OnPlayerDisconnect(2, 0);
- call OnPlayerDisconnect(3, 0);
- call OnPlayerDisconnect(4, 0);
- call OnPlayerDisconnect(5, 0);
- call OnPlayerDisconnect(6, 0);
- Group_Destroy(g[0]);
- Group_Destroy(g[1]);
- Group_Destroy(g[2]);
- }
- Test:y_groups_SetBalancedSingle()
- {
- new
- Group:g1 = Group_Create("Group 1"),
- Group:result;
- call OnPlayerConnect(0);
-
- result = Group_SetBalanced(0, g1, Group:11);
- ASSERT(result == g1);
-
- call OnPlayerDisconnect(0, 0);
- Group_Destroy(g1);
- }
- Test:y_groups_SetBalancedInvalid()
- {
- new
- Group:result;
- call OnPlayerConnect(0);
-
- result = Group_SetBalanced(0, Group:99, Group:88);
- ASSERT(result == INVALID_GROUP);
-
- call OnPlayerDisconnect(0, 0);
- }
- #define MASTER 60
- #tryinclude "..\YSI_Core\y_master"
- #tryinclude "..\..\YSI_Core\y_master"
- #define _GROUP_MAKE_NAME<%0...%1> %0Test%1
- #define _GROUP_MAKE_LIMIT 123
- #tryinclude "y_groups\_funcs"
- #tryinclude "_funcs"
- static
- gPl,
- gEl,
- bool:gS;
- Test_SetPlayer(el, playerid, bool:s)
- {
- P:1("Test_SetPlayer called: %d %d %d", el, playerid, s);
- gPl = playerid;
- gEl = el;
- gS = s;
- return 1;
- }
- Test:0_y_groups_Connect0()
- {
- gPl = INVALID_PLAYER_ID;
- gEl = 100;
- gS = false;
- //new
- // Group:g = Group_Create();
- call OnPlayerConnect(45);
- ASSERT(gPl == INVALID_PLAYER_ID);
- ASSERT(gEl == 100);
- ASSERT(gS == false);
- //printf("%d %d %d", gPl, gEl, gS);
- Test_InitialiseFromGroups(7);
- ASSERT(gPl == 45);
- ASSERT(gEl == 7);
- ASSERT(gS == true);
- call OnPlayerDisconnect(45, 0);
- }
- Test:0_y_groups_Connect1()
- {
- gPl = INVALID_PLAYER_ID;
- gEl = 100;
- gS = false;
- //new
- // Group:g = Group_Create();
- Test_InitialiseFromGroups(8);
- ASSERT(gPl != INVALID_PLAYER_ID);
- ASSERT(gEl != 100);
- ASSERT(gS != false);
- call OnPlayerConnect(43);
- ASSERT(gPl == 43);
- ASSERT(gEl == 8);
- ASSERT(gS == true);
- call OnPlayerDisconnect(43, 0);
- }
- Test:y_groups_Chains()
- {
- new
- Group:g = Group_Create();
- call OnPlayerConnect(44);
- ASSERT_FALSE(Group_GetPlayer(g, 44));
- Group_SetGlobalGroup(g, true);
- ASSERT_TRUE(Group_GetPlayer(g, 44));
- call OnPlayerDisconnect(44, 0);
- }
- Test:y_groups_Children0()
- {
- new
- Group:g0 = Group_Create();
- ASSERT(!Group_GetGlobalGroup(g0));
- Group_Destroy(g0);
- }
- Test:y_groups_Children1()
- {
- new
- Group:g0 = Group_Create(),
- Group:g1 = Group_Create(),
- Group:g2 = Group_Create();
- // Check groups ARE descendants of themselves.
- ASSERT(Group_IsDescendant(GROUP_GLOBAL, GROUP_GLOBAL));
- ASSERT(Group_IsDescendant(g0, g0));
- ASSERT(Group_IsDescendant(g1, g1));
- ASSERT(Group_IsDescendant(g2, g2));
- // Check there are no relationships at all.
- ASSERT(!Group_IsDescendant(g0, g1));
- ASSERT(!Group_IsDescendant(g0, g2));
- ASSERT(!Group_IsDescendant(g1, g0));
- ASSERT(!Group_IsDescendant(g1, g2));
- ASSERT(!Group_IsDescendant(g2, g0));
- ASSERT(!Group_IsDescendant(g2, g1));
- // Grlobal group.
- ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g0));
- ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g1));
- ASSERT(!Group_IsDescendant(GROUP_GLOBAL, g2));
- ASSERT(!Group_IsDescendant(g0, GROUP_GLOBAL));
- ASSERT(!Group_IsDescendant(g1, GROUP_GLOBAL));
- ASSERT(!Group_IsDescendant(g2, GROUP_GLOBAL));
- Group_Destroy(g0),
- Group_Destroy(g1),
- Group_Destroy(g2);
- }
- Test:y_groups_Children2()
- {
- new
- Group:g0 = Group_Create(),
- Group:g1 = Group_Create(),
- Group:g2 = Group_Create();
- // Check groups are children of themselves.
- ASSERT(!Group_GetGroup(GROUP_GLOBAL, GROUP_GLOBAL));
- ASSERT(!Group_GetGroup(g0, g0));
- ASSERT(!Group_GetGroup(g1, g1));
- ASSERT(!Group_GetGroup(g2, g2));
- // Check there are no relationships at all.
- ASSERT(!Group_GetGroup(g0, g1));
- ASSERT(!Group_GetGroup(g0, g2));
- ASSERT(!Group_GetGroup(g1, g0));
- ASSERT(!Group_GetGroup(g1, g2));
- ASSERT(!Group_GetGroup(g2, g0));
- ASSERT(!Group_GetGroup(g2, g1));
- // Grlobal group.
- ASSERT(!Group_GetGroup(GROUP_GLOBAL, g0));
- ASSERT(!Group_GetGroup(GROUP_GLOBAL, g1));
- ASSERT(!Group_GetGroup(GROUP_GLOBAL, g2));
- ASSERT(!Group_GetGroup(g0, GROUP_GLOBAL));
- ASSERT(!Group_GetGroup(g1, GROUP_GLOBAL));
- ASSERT(!Group_GetGroup(g2, GROUP_GLOBAL));
- Group_Destroy(g0),
- Group_Destroy(g1),
- Group_Destroy(g2);
- }
- Test:y_groups_Children3()
- {
- new
- Group:g0 = Group_Create(),
- Group:g1 = Group_Create(),
- Group:g2 = Group_Create();
- Group_AddChild(g0, g1);
- ASSERT(Group_IsDescendant(g0, g1));
- // Check there are no other relationships.
- ASSERT(!Group_IsDescendant(g0, g2));
- ASSERT(!Group_IsDescendant(g1, g0));
- ASSERT(!Group_IsDescendant(g1, g2));
- ASSERT(!Group_IsDescendant(g2, g0));
- ASSERT(!Group_IsDescendant(g2, g1));
- Group_Destroy(g0),
- Group_Destroy(g1),
- Group_Destroy(g2);
- }
- Test:y_groups_Children4()
- {
- new
- Group:g0 = Group_Create(),
- Group:g1 = Group_Create(),
- Group:g2 = Group_Create();
- Group_AddChild(g0, g1);
- Group_AddChild(g1, g2);
- // Test chaining.
- ASSERT(Group_IsDescendant(g0, g1));
- ASSERT(Group_IsDescendant(g1, g2));
- ASSERT(Group_IsDescendant(g0, g2));
- // Check there are no reverse relationships.
- ASSERT(!Group_IsDescendant(g1, g0));
- ASSERT(!Group_IsDescendant(g2, g0));
- ASSERT(!Group_IsDescendant(g2, g1));
- Group_Destroy(g0),
- Group_Destroy(g1),
- Group_Destroy(g2);
- }
- Test:y_groups_Children5()
- {
- new
- Group:g0 = Group_Create(),
- Group:g1 = Group_Create(),
- Group:g2 = Group_Create(),
- Group:g3 = Group_Create(),
- Group:g4 = Group_Create();
- Group_AddChild(g0, g1);
- Group_AddChild(g1, g2);
- Group_AddChild(g2, g0);
- Group_AddChild(g4, g0);
- // Test cycles don't hang.
- ASSERT(!Group_IsDescendant(g4, g3));
- ASSERT(!Group_IsDescendant(g3, g4));
- // Test cycles work.
- ASSERT(Group_IsDescendant(g4, g2));
- ASSERT(!Group_IsDescendant(g2, g4));
- ASSERT(Group_IsDescendant(g0, g2));
- ASSERT(Group_IsDescendant(g2, g0));
- Group_Destroy(g0),
- Group_Destroy(g1),
- Group_Destroy(g2);
- Group_Destroy(g3);
- Group_Destroy(g4);
- }
- Test:y_groups_Children6()
- {
- new
- Group:g0 = Group_Create(),
- Group:g1 = Group_Create(),
- Group:g2 = Group_Create();
- Group_AddChild(g0, g1);
- Group_AddChild(g1, g2);
- // Test removal
- ASSERT(Group_IsDescendant(g0, g2));
- Group_RemoveChild(g1, g2);
- ASSERT(!Group_IsDescendant(g0, g2));
- Group_AddChild(g1, g2);
- ASSERT(Group_IsDescendant(g0, g2));
- Group_Destroy(g1);
- ASSERT(!Group_IsDescendant(g0, g2));
- Group_Destroy(g0),
- Group_Destroy(g2);
- }
- Test:y_groups_Children7()
- {
- new
- Group:g0 = Group_Create(),
- Group:g1 = Group_Create(),
- Group:g2 = Group_Create();
- Group_AddChild(g0, g1);
- Group_AddChild(g1, g2);
- // Test chaining.
- ASSERT(Group_IsDescendant(g0, g1));
- ASSERT(Group_IsDescendant(g1, g2));
- ASSERT(Group_IsDescendant(g0, g2));
- // Check there are no reverse relationships.
- ASSERT(!Group_IsChild(g0, g2));
- Group_Destroy(g0),
- Group_Destroy(g1),
- Group_Destroy(g2);
- }
- Test:y_groups_ChildIterator0()
- {
- new
- Group:g0 = Group_Create(),
- Group:g1 = Group_Create(),
- Group:g2 = Group_Create();
- Group_AddChild(g0, g1);
- Group_AddChild(g0, g2);
- new
- total = 0;
- foreach (new Group:g : GroupChild(g0))
- {
- ++total;
- }
- ASSERT(total == 2);
- Group_Destroy(g0),
- Group_Destroy(g1),
- Group_Destroy(g2);
- }
- Test:y_groups_ChildIterator1()
- {
- new
- Group:g0 = Group_Create(),
- Group:g1 = Group_Create(),
- Group:g2 = Group_Create();
- Group_AddChild(g0, g1);
- Group_AddChild(g0, g2);
- ASSERT(Group_IsValid(g0));
- ASSERT(Group_IsValid(g1));
- ASSERT(Group_IsValid(g2));
- foreach (new Group:g : GroupChild(g0))
- {
- Group_Destroy(g);
- }
- ASSERT(Group_IsValid(g0));
- ASSERT(!Group_IsValid(g1));
- ASSERT(!Group_IsValid(g2));
- Group_Destroy(g0),
- ASSERT(!Group_IsValid(g0));
- }
- Test:y_groups_ChildIterator2()
- {
- new
- Group:g0 = Group_Create(),
- Group:g1 = Group_Create(),
- Group:g2 = Group_Create();
- Group_AddChild(g0, g1);
- Group_AddChild(g0, g2);
- ASSERT(Group_IsValid(g0));
- ASSERT(Group_IsValid(g1));
- ASSERT(Group_IsValid(g2));
- new
- total = 0;
- foreach (new Group:g : GroupChild[g0])
- {
- Group_Destroy(g);
- ++total;
- }
- ASSERT(total == 2);
- ASSERT(Group_IsValid(g0));
- ASSERT(!Group_IsValid(g1));
- ASSERT(!Group_IsValid(g2));
- Group_Destroy(g0),
- ASSERT(!Group_IsValid(g0));
- }
- Test:y_groups_Iterator0()
- {
- new
- Group:g0 = Group_Create(),
- Group:g1 = Group_Create(),
- Group:g2 = Group_Create();
- new
- total = 0;
- foreach (new Group:g : CreatedGroup)
- {
- ++total;
- }
- ASSERT(total >= 3);
- total = 0;
- foreach (new Group:g : CreatedGroup())
- {
- ++total;
- }
- ASSERT(total >= 3);
- Group_Destroy(g0),
- Group_Destroy(g1),
- Group_Destroy(g2);
- }
- #undef _GROUP_MAKE_LIMIT
- #undef _GROUP_MAKE_NAME
- #tryinclude "..\YSI_Core\y_master"
- #tryinclude "..\..\YSI_Core\y_master"
|