| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 |
- #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);
- //W@(#On#PlayerDisconnect ,x:#ii#,42, 0);
- call OnPlayerDisconnect(42, 0);
- //ASSERT(Group_GetCount(g) == 0);
- //call OnPlayerConnect(42);
- //ASSERT(Group_GetCount(g) == 0);
- Group_Destroy(g);
- }
- #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"
|