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(); }
// Simulates player joining game from new client ClientGame *GamePair::addClient(const string &name) { ClientGame *clientGame = newClientGame(); clientGame->userEnteredLoginCredentials(name, "password", false); // Simulates entry from NameEntryUserInterface // Get a base UI going, so if we enter the game, and exit again, we'll have a place to land clientGame->activateMainMenuUI(); GameManager::addClientGame(clientGame); return addClient(clientGame); }
// Create a new ClientGame with one dummy team -- be sure to delete this somewhere! ClientGame *newClientGame() { GameSettingsPtr settings = GameSettingsPtr(new GameSettings()); return newClientGame(settings); }
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; }