fix(Test): pre-init RBAC data to prevent unit_tests segfaults (#26405)
This commit is contained in:
@@ -100,6 +100,9 @@ protected:
|
|||||||
{
|
{
|
||||||
auto* session = new WorldSession(guidLow, std::string(name), 0, nullptr, security,
|
auto* session = new WorldSession(guidLow, std::string(name), 0, nullptr, security,
|
||||||
EXPANSION_WRATH_OF_THE_LICH_KING, 0, LOCALE_enUS, 0, false, false, 0);
|
EXPANSION_WRATH_OF_THE_LICH_KING, 0, LOCALE_enUS, 0, false, false, 0);
|
||||||
|
// Pre-allocate RBAC data so Player's ctor (which calls
|
||||||
|
// GetSession()->HasPermission) doesn't try to load from DB.
|
||||||
|
session->InitRBACDataForTest();
|
||||||
|
|
||||||
auto* player = new TestPlayer(session);
|
auto* player = new TestPlayer(session);
|
||||||
player->ForceInitValues(guidLow);
|
player->ForceInitValues(guidLow);
|
||||||
|
|||||||
@@ -128,6 +128,9 @@ protected:
|
|||||||
1, "test", 0, nullptr, SEC_PLAYER,
|
1, "test", 0, nullptr, SEC_PLAYER,
|
||||||
EXPANSION_WRATH_OF_THE_LICH_KING,
|
EXPANSION_WRATH_OF_THE_LICH_KING,
|
||||||
0, LOCALE_enUS, 0, false, false, 0);
|
0, LOCALE_enUS, 0, false, false, 0);
|
||||||
|
// Pre-allocate RBAC data so Player's ctor (which calls
|
||||||
|
// GetSession()->HasPermission) doesn't try to load from DB.
|
||||||
|
session->InitRBACDataForTest();
|
||||||
|
|
||||||
player = new TestPlayer(session);
|
player = new TestPlayer(session);
|
||||||
player->ForceInitValues(42);
|
player->ForceInitValues(42);
|
||||||
@@ -203,8 +206,11 @@ TEST_F(OmenOfClarityGlyphLockTest,
|
|||||||
EXPECT_NE(bitsAfterInit & OOC_LOCKED_SLOT_BIT, 0u)
|
EXPECT_NE(bitsAfterInit & OOC_LOCKED_SLOT_BIT, 0u)
|
||||||
<< "InitGlyphsForLevel should enable slot 5 at 80";
|
<< "InitGlyphsForLevel should enable slot 5 at 80";
|
||||||
|
|
||||||
// 4. Fire the level-change hook (same as GiveLevel does)
|
// 4. Fire the level-change hook directly on the test-local
|
||||||
sScriptMgr->OnPlayerLevelChanged(player, 79);
|
// PlayerScript. We bypass sScriptMgr because the global
|
||||||
|
// dispatcher's registry is shared state across tests and
|
||||||
|
// has proven unstable in the unit_tests binary.
|
||||||
|
TestOocPlayerScript::Instance->OnPlayerLevelChanged(player, 79);
|
||||||
|
|
||||||
// 5. Verify the hook cleared the bit
|
// 5. Verify the hook cleared the bit
|
||||||
uint32 bitsAfterHook =
|
uint32 bitsAfterHook =
|
||||||
@@ -229,7 +235,7 @@ TEST_F(OmenOfClarityGlyphLockTest,
|
|||||||
// Feature is NOT enabled (cache is empty)
|
// Feature is NOT enabled (cache is empty)
|
||||||
|
|
||||||
SimulateGlyphsForLevel(80);
|
SimulateGlyphsForLevel(80);
|
||||||
sScriptMgr->OnPlayerLevelChanged(player, 79);
|
TestOocPlayerScript::Instance->OnPlayerLevelChanged(player, 79);
|
||||||
|
|
||||||
uint32 bits =
|
uint32 bits =
|
||||||
player->GetUInt32Value(PLAYER_GLYPHS_ENABLED);
|
player->GetUInt32Value(PLAYER_GLYPHS_ENABLED);
|
||||||
@@ -252,7 +258,7 @@ TEST_F(OmenOfClarityGlyphLockTest,
|
|||||||
{
|
{
|
||||||
SCOPED_TRACE("Level: " + std::to_string(newLevel));
|
SCOPED_TRACE("Level: " + std::to_string(newLevel));
|
||||||
SimulateGlyphsForLevel(newLevel);
|
SimulateGlyphsForLevel(newLevel);
|
||||||
sScriptMgr->OnPlayerLevelChanged(
|
TestOocPlayerScript::Instance->OnPlayerLevelChanged(
|
||||||
player, newLevel - 1);
|
player, newLevel - 1);
|
||||||
|
|
||||||
uint32 bits =
|
uint32 bits =
|
||||||
@@ -276,7 +282,7 @@ TEST_F(OmenOfClarityGlyphLockTest,
|
|||||||
OOC_LOCKED_SLOT_BIT, 0u);
|
OOC_LOCKED_SLOT_BIT, 0u);
|
||||||
|
|
||||||
// Complete the quest → hook enables feature + locks slot
|
// Complete the quest → hook enables feature + locks slot
|
||||||
sScriptMgr->OnPlayerCompleteQuest(player, nullptr);
|
TestOocPlayerScript::Instance->OnPlayerCompleteQuest(player, nullptr);
|
||||||
EXPECT_TRUE(s_testOocEnabled.count(
|
EXPECT_TRUE(s_testOocEnabled.count(
|
||||||
player->GetGUID().GetCounter()) > 0)
|
player->GetGUID().GetCounter()) > 0)
|
||||||
<< "Feature should be enabled after quest completion";
|
<< "Feature should be enabled after quest completion";
|
||||||
@@ -289,7 +295,7 @@ TEST_F(OmenOfClarityGlyphLockTest,
|
|||||||
<< "InitGlyphsForLevel should have set 0x20";
|
<< "InitGlyphsForLevel should have set 0x20";
|
||||||
|
|
||||||
// Level-change hook fires
|
// Level-change hook fires
|
||||||
sScriptMgr->OnPlayerLevelChanged(player, 79);
|
TestOocPlayerScript::Instance->OnPlayerLevelChanged(player, 79);
|
||||||
|
|
||||||
uint32 bitsPostHook =
|
uint32 bitsPostHook =
|
||||||
player->GetUInt32Value(PLAYER_GLYPHS_ENABLED);
|
player->GetUInt32Value(PLAYER_GLYPHS_ENABLED);
|
||||||
|
|||||||
Reference in New Issue
Block a user