void GamePair::initialize(GameSettingsPtr settings, const Vector<string> &levelCode, S32 clientCount) { settings->resolveDirs(); // Need to start Lua before we add any clients. Might as well do it now. LuaScriptRunner::startLua(settings->getFolderManager()->getLuaDir()); LevelSourcePtr levelSource = LevelSourcePtr(new StringLevelSource(levelCode)); initHosting(settings, levelSource, true, false); // Creates a game and adds it to GameManager server = GameManager::getServerGame(); // Get the game created in initHosting // Give the host name something meaningful... in this case the name of the test if(::testing::UnitTest::GetInstance()->current_test_case()) { const char *name = ::testing::UnitTest::GetInstance()->current_test_case()->name(); const char *name2 = ::testing::UnitTest::GetInstance()->current_test_info()->name(); server->getSettings()->setHostName(string(name) + "_" + name2, false); } server->startHosting(); // This will load levels and wipe out any teams for(S32 i = 0; i < clientCount; i++) addClient("TestPlayer" + itos(i)); idle(1, 5); // Give GameType and game objects time to propagate to client(s) }
// Note that clientLevelSource could be NULL void GamePair::initialize(GameSettingsPtr serverSettings, GameSettingsPtr clientSettings, LevelSourcePtr serverLevelSource, S32 clientCount, bool skipInitialIdle) { GameManager::reset(); // Still needed? serverSettings->resolveDirs(); clientSettings->resolveDirs(); // Need to start Lua before we add any clients. Might as well do it now. LuaScriptRunner::startLua(serverSettings->getFolderManager()->getLuaDir()); initHosting(serverSettings, serverLevelSource, true, false); // Creates a ServerGame and adds it to GameManager server = GameManager::getServerGame(); // Get the game created in initHosting // Give the host name something meaningful... in this case the name of the test if(::testing::UnitTest::GetInstance()->current_test_case()) { const char *name = ::testing::UnitTest::GetInstance()->current_test_case()->name(); const char *name2 = ::testing::UnitTest::GetInstance()->current_test_info()->name(); server->getSettings()->setHostName(string(name) + "_" + name2, false); } bool ok = server->startHosting(); // This will load levels and wipe out any teams ASSERT_TRUE(ok) << "Ooops!"; for(S32 i = 0; i < clientCount; i++) addClient("TestPlayer" + itos(i), clientSettings); // SPECIAL CASE ALERT -- IF YOU PROVIDE A CLIENT AND SERVER PLAYLIST, WE WILL SKIP THE IDLE BELOW TO THAT WE // CAN TEST THE INITIAL STATE OF CLIENT GAME BEFORE THERE IS ANY MEANINGFUL INTERACTION WITH THE SERVER. BE // SURE TO RUN IDLE YOURSELF! if(skipInitialIdle) return; idle(1, 5); // Give GameType and game objects time to propagate to client(s) }
// This one is a little more involved, as we will be simulating an entire editor session, including level testing TEST(ObjectCleanupTests, TestEditorObjectManagement) { GameSettingsPtr settings = GameSettingsPtr(new GameSettings()); settings->setSetting(IniKey::Nickname, string("Alfonso")); // Set this to bypass startup screen settings->getFolderManager()->setLevelDir("levels"); // Need something for hosting to work settings->updatePlayerName("Alfonso"); Address addr; ClientGame *clientGame = new ClientGame(addr, settings, new UIManager()); // ClientGame destructor will clean up UIManager GameManager::addClientGame(clientGame); UIManager *uiMgr = clientGame->getUIManager(); uiMgr->activate<MainMenuUserInterface>(); ASSERT_TRUE(uiMgr->isCurrentUI<MainMenuUserInterface>()); // Cheat a little; go directly to editor uiMgr->getUI<EditorUserInterface>()->setLevelFileName("xyzzy"); // Reset this so we get the level entry screen uiMgr->activate<EditorUserInterface>(); ASSERT_TRUE(uiMgr->isCurrentUI<EditorUserInterface>()); EditorUserInterface *editor = uiMgr->getUI<EditorUserInterface>(); ///// Test basic object deletion, undo system not activated SafePtr<TestItem> testItem = new TestItem(); // To track deletion... see "Basics" test above ASSERT_FALSE(testItem.isNull()) << "Just created this!"; editor->addToEditor(testItem.getPointer()); editor->deleteItem(0, false); // Low level method doesn't save undo state; object should be deleted ASSERT_TRUE(testItem.isNull()) << "Obj should be gone!"; ///// Check deleting object with undo system -- do things get deleted as expected? testItem = new TestItem(); ASSERT_FALSE(testItem.isNull()) << "Just created this -- shouldn't be gone yet!"; editor->addToEditor(testItem.getPointer()); testItem->setSelected(true); ASSERT_EQ(1, editor->getLevel()->findObjects_fast()->size()) << "Started with one object"; editor->handleKeyPress(KEY_Z, "Del"); // Triggers deleteSelection(false) ASSERT_TRUE(testItem.isNull()) << "Obj should be gone!"; ASSERT_EQ(0, editor->getLevel()->findObjects_fast()->size()) << "All objects deleted... none should be present"; editor->handleKeyPress(KEY_Z, editor->getEditorBindingString(BINDING_UNDO_ACTION)); // Undo ASSERT_EQ(1, editor->getLevel()->findObjects_fast()->size()) << "Undeleted one object"; ASSERT_FALSE(testItem.isValid()); testItem = dynamic_cast<TestItem *>(editor->getLevel()->findObjects_fast()->get(0)); ASSERT_TRUE(testItem.isValid()); editor->handleKeyPress(KEY_Z, editor->getEditorBindingString(BINDING_REDO_ACTION)); ASSERT_EQ(0, editor->getLevel()->findObjects_fast()->size()) << "Redid delete... none should be present"; ASSERT_FALSE(testItem.isValid()); ///// Test level Level *level = editor->getLevel(); // Keep track of the level we were editing editor->testLevelStart(); ASSERT_TRUE(uiMgr->isCurrentUI<EditorUserInterface>()) << "Still in editor"; ASSERT_TRUE(editor->getLevel()->getGameType()) << "Have valid GameType"; GameType *gt = editor->getLevel()->getGameType(); GameManager::getServerGame()->loadNextLevelInfo(); ASSERT_EQ(GameManager::DoneLoadingLevels, GameManager::getHostingModePhase()) << "Only loading one level here..."; ASSERT_TRUE(GameManager::hostGame()) << "Failure to host game!"; ASSERT_TRUE(uiMgr->isCurrentUI<GameUserInterface>()) << "In game UI"; GameManager::localClientQuits(GameManager::getClientGames()->get(0)); ASSERT_TRUE(uiMgr->isCurrentUI<EditorUserInterface>()) << "Back to the editor"; ASSERT_EQ(editor, uiMgr->getCurrentUI()) << "Expect same object"; ASSERT_EQ(level, editor->getLevel()) << "Level should not have changed"; ASSERT_TRUE(editor->getLevel()->getGameType()) << "Expect valid GameType"; ASSERT_EQ(gt, editor->getLevel()->getGameType()) << "GameType should not have changed"; }