// Scenario 11 -- Player is editing loadout when level changes --> TEST NOT COMPLETE!!!! static void doScenario11(GamePair &gamePair) { ClientGame *clientGame = gamePair.getClient(0); ServerGame *serverGame = gamePair.server; serverGame->setGameTime(.5); // 30 seconds GameUserInterface *gameUI = clientGame->getUIManager()->getUI<GameUserInterface>(); ASSERT_FALSE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); gameUI->activateHelper(HelperMenu::LoadoutHelperType); ASSERT_TRUE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); ASSERT_EQ("", serverGame->getClientInfo(0)->getOnDeckLoadout().toString(true)); // Prove there's no on deck loadout // See static const OverlayMenuItem loadoutModuleMenuItems[] in loadoutHelper.cpp // Feed the UI some keys... like we're configuring a loadout! gameUI->onKeyDown(KEY_1); gameUI->onKeyDown(KEY_3); // First 2 modules... gameUI->onKeyDown(KEY_1); gameUI->onKeyDown(KEY_2); gameUI->onKeyDown(KEY_3); // ...then 3 weapons ASSERT_FALSE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); gamePair.idle(10, 10); // Check the on deck loadout on server -- does not get set on the client ASSERT_EQ("Turbo,Repair,Phaser,Bouncer,Triple", serverGame->getClientInfo(0)->getOnDeckLoadout().toString(true)); gameUI->activateHelper(HelperMenu::LoadoutHelperType); ASSERT_TRUE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); gamePair.idle(100, 350); // Idle until game ends gameUI->onKeyDown(KEY_1); gameUI->onKeyDown(KEY_4); gameUI->onKeyDown(KEY_1); gameUI->onKeyDown(KEY_2); gameUI->onKeyDown(KEY_3); ASSERT_FALSE(gameUI->isHelperActive(HelperMenu::LoadoutHelperType)); gamePair.idle(10, 10); ASSERT_EQ("Turbo,Sensor,Phaser,Bouncer,Triple", serverGame->getClientInfo(0)->getOnDeckLoadout().toString(true)); }
GameUserInterface *GamePair::getGameUI(S32 clientIndex) { EXPECT_TRUE(clientIndex >= 0 && clientIndex < getClientCount()) << "Index out of bounds!"; ClientGame *client = getClient(clientIndex); GameUserInterface *ui = dynamic_cast<GameUserInterface *>(client->getUIManager()->getCurrentUI()); EXPECT_TRUE(ui != NULL) << "Are we in the game?"; return ui; }
TEST(EditorTest, findSnapVertexTest) { GamePair pair; ClientGame *clientGame = pair.getClient(0); ASSERT_TRUE(clientGame) << "Shouldn't be NULL here..."; EditorUserInterface *editorUi = clientGame->getUIManager()->getUI<EditorUserInterface>(); editorUi->setLevel(boost::shared_ptr<Level>(new Level())); ASSERT_EQ(0, editorUi->getLevel()->getObjectCount()); // Confirm level starts empty // 5 vertex wall in stair-step pattern, with middle vertex on 0,0 editorUi->getLevel()->parseLevelLine("BarrierMaker 10 -100 -100 0 -100 0 0 100 0 100 100", "NoFile"); ASSERT_EQ(1, editorUi->getLevel()->getObjectCount()); // Confirm object was added properly // Mark first 3 vertices as being selected WallItem *wall = static_cast<WallItem *>(editorUi->getLevel()->getObjectByIndex(0)); wall->aselectVert(0); wall->aselectVert(1); wall->aselectVert(2); ASSERT_TRUE(wall->vertSelected(0)); ASSERT_TRUE(wall->vertSelected(1)); ASSERT_TRUE(wall->vertSelected(2)); ASSERT_FALSE(wall->vertSelected(3)); ASSERT_FALSE(wall->vertSelected(4)); editorUi->mMousePos.set(3,3); // In canvas coords; near vertex 2 editorUi->findSnapVertex(); EXPECT_EQ(2, editorUi->mSnapVertexIndex); editorUi->mMousePos.set(95,105); // Near vertex 4, which is not selected --> closest selected is 2 editorUi->findSnapVertex(); EXPECT_EQ(2, editorUi->mSnapVertexIndex); editorUi->mMousePos.set(-88,-106); // Near vertex 0, which is selected editorUi->findSnapVertex(); EXPECT_EQ(0, editorUi->mSnapVertexIndex); wall->unselectVert(0); ASSERT_FALSE(wall->vertSelected(0)); ASSERT_TRUE(wall->vertSelected(1)); ASSERT_TRUE(wall->vertSelected(2)); ASSERT_FALSE(wall->vertSelected(3)); ASSERT_FALSE(wall->vertSelected(4)); editorUi->mMousePos.set(-88, -106); // Near vertex 0, which is not selected --> closest selected is 1 editorUi->findSnapVertex(); EXPECT_EQ(1, editorUi->mSnapVertexIndex); editorUi->mMousePos.set(3, 3); // In canvas coords; near vertex 2 editorUi->findSnapVertex(); EXPECT_EQ(2, editorUi->mSnapVertexIndex); // Cleanup delete newClientGame(); }
// 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"; }
TEST(LevelMenuSelectUserInterfaceTests, GetIndexOfNext) { ClientGame *game = newClientGame(); // Want to test getIndexOfNext(), which is a slightly complex function. Need to start by setting up a menu. LevelMenuSelectUserInterface *ui = game->getUIManager()->getUI<LevelMenuSelectUserInterface>(); // Cleaned up when game goes out of scope // These should be alphabetically sorted ui->addMenuItem(new MenuItem("Aardvark")); // 0 ui->addMenuItem(new MenuItem("Assinine")); // 1 ui->addMenuItem(new MenuItem("Bouy")); // 2 ui->addMenuItem(new MenuItem("Boy")); // 3 ui->addMenuItem(new MenuItem("C")); // 4 ui->addMenuItem(new MenuItem("Cat")); // 5 ui->addMenuItem(new MenuItem("Cc")); // 6 ui->addMenuItem(new MenuItem("Chop")); // 7 ui->addMenuItem(new MenuItem("Chump")); // 8 ui->addMenuItem(new MenuItem("Dog")); // 9 ui->addMenuItem(new MenuItem("Doug")); // 10 ui->addMenuItem(new MenuItem("Eat")); // 11 ui->addMenuItem(new MenuItem("Eating")); // 12 ui->addMenuItem(new MenuItem("Eel")); // 13 ui->addMenuItem(new MenuItem("Eels")); // 14 ui->addMenuItem(new MenuItem("Eggs")); // 15 // Some random checks ui->selectedIndex = 1; ASSERT_EQ(ui->getIndexOfNext("a"), 0); ASSERT_EQ(ui->getIndexOfNext("boy"), 3); ASSERT_EQ(ui->getIndexOfNext("c"), 4); ASSERT_EQ(ui->getIndexOfNext("ch"), 7); ASSERT_EQ(ui->getIndexOfNext("cho"), 7); ASSERT_EQ(ui->getIndexOfNext("chop"), 7); // Check cycling of the Cs ui->selectedIndex = 3; ASSERT_EQ(ui->getIndexOfNext("c"), 4); ui->selectedIndex = 4; ASSERT_EQ(ui->getIndexOfNext("c"), 5); ui->selectedIndex = 5; ASSERT_EQ(ui->getIndexOfNext("c"), 6); ui->selectedIndex = 6; ASSERT_EQ(ui->getIndexOfNext("c"), 7); ui->selectedIndex = 7; ASSERT_EQ(ui->getIndexOfNext("c"), 8); ui->selectedIndex = 8; ASSERT_EQ(ui->getIndexOfNext("c"), 4); // Check wrapping ui->selectedIndex = 9; ASSERT_EQ(ui->getIndexOfNext("a"), 0); ui->selectedIndex = 15; // last item ASSERT_EQ(ui->getIndexOfNext("a"), 0); // Check repeated hammering on current item ui->selectedIndex = 12; ASSERT_EQ(ui->getIndexOfNext("e"), 13); // Single letter advances to next of that letter ASSERT_EQ(ui->getIndexOfNext("ea"), 12); ASSERT_EQ(ui->getIndexOfNext("eat"), 12); ASSERT_EQ(ui->getIndexOfNext("eati"), 12); ASSERT_EQ(ui->getIndexOfNext("eatin"), 12); ASSERT_EQ(ui->getIndexOfNext("eating"), 12); // Check for not found items -- should return current index ASSERT_EQ(ui->getIndexOfNext("eatingx"), 12); ASSERT_EQ(ui->getIndexOfNext("flummoxed"), 12); ui->selectedIndex = 8; ASSERT_EQ(ui->getIndexOfNext("chop"), 7); delete game; }