mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Add tests for LootState's unapplied changes counter
This commit is contained in:
+3
-1
@@ -165,6 +165,7 @@ set (LOOT_VALIDATOR_HEADERS ${LOOT_HEADERS})
|
||||
set (LOOT_TESTS_SRC ${LOOT_SRC}
|
||||
"${CMAKE_SOURCE_DIR}/src/api/loot_db.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/gui/loot_settings.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/gui/loot_state.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/main.cpp")
|
||||
|
||||
set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/fixtures.h"
|
||||
@@ -193,7 +194,8 @@ set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/fixtures.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/test_metadata_list.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/test_masterlist.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/test_plugin_sorter.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/gui/test_loot_settings.h")
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/gui/test_loot_settings.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/gui/test_loot_state.h")
|
||||
|
||||
source_group("Header Files" FILES ${LOOT_HEADERS} ${LOOT_GUI_HEADERS} ${LOOT_API_HEADERS} ${LOOT_TESTS_HEADERS})
|
||||
|
||||
|
||||
@@ -239,7 +239,8 @@ namespace loot {
|
||||
}
|
||||
|
||||
void LootState::decrementUnappliedChangeCounter() {
|
||||
--unappliedChangeCounter;
|
||||
if (unappliedChangeCounter > 0)
|
||||
--unappliedChangeCounter;
|
||||
}
|
||||
|
||||
void LootState::SelectGame(std::string preferredGame) {
|
||||
@@ -252,12 +253,12 @@ namespace loot {
|
||||
}
|
||||
|
||||
// Get iterator to preferred game.
|
||||
_currentGame = find_if(begin(_games), end(_games), [&](auto& game) {
|
||||
_currentGame = find_if(begin(_games), end(_games), [&](Game& game) {
|
||||
return (preferredGame.empty() || preferredGame == game.FolderName()) && game.IsInstalled();
|
||||
});
|
||||
// If the preferred game cannot be found, get the first installed game.
|
||||
if (_currentGame == end(_games)) {
|
||||
_currentGame = find_if(begin(_games), end(_games), [](auto& game) {
|
||||
_currentGame = find_if(begin(_games), end(_games), [](Game& game) {
|
||||
return game.IsInstalled();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2014-2015 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_TEST_GUI_LOOT_STATE
|
||||
#define LOOT_TEST_GUI_LOOT_STATE
|
||||
|
||||
#include "gui/loot_state.h"
|
||||
|
||||
#include "tests/fixtures.h"
|
||||
|
||||
namespace loot {
|
||||
namespace test {
|
||||
class LootState : public ::testing::Test {
|
||||
protected:
|
||||
loot::LootState lootState;
|
||||
};
|
||||
|
||||
TEST_F(LootState, hasUnappliedChangesShouldBeFalseByDefault) {
|
||||
EXPECT_FALSE(lootState.hasUnappliedChanges());
|
||||
}
|
||||
|
||||
TEST_F(LootState, shouldNotHaveUnappliedChangesIfCounterIsDeccremented) {
|
||||
lootState.decrementUnappliedChangeCounter();
|
||||
EXPECT_FALSE(lootState.hasUnappliedChanges());
|
||||
}
|
||||
|
||||
TEST_F(LootState, shouldHaveUnappliedChangesIfCounterIsIncremented) {
|
||||
lootState.incrementUnappliedChangeCounter();
|
||||
EXPECT_TRUE(lootState.hasUnappliedChanges());
|
||||
}
|
||||
|
||||
TEST_F(LootState, incrementingTheChangeCounterMoreThanItIsDecrementedShouldLeaveUnappliedChanges) {
|
||||
lootState.incrementUnappliedChangeCounter();
|
||||
lootState.incrementUnappliedChangeCounter();
|
||||
lootState.decrementUnappliedChangeCounter();
|
||||
EXPECT_TRUE(lootState.hasUnappliedChanges());
|
||||
}
|
||||
|
||||
TEST_F(LootState, incrementingTheChangeCounterLessThanItIsDecrementedShouldLeaveNoUnappliedChanges) {
|
||||
lootState.incrementUnappliedChangeCounter();
|
||||
lootState.decrementUnappliedChangeCounter();
|
||||
lootState.decrementUnappliedChangeCounter();
|
||||
EXPECT_FALSE(lootState.hasUnappliedChanges());
|
||||
}
|
||||
|
||||
TEST_F(LootState, incrementingTheChangeCounterThenDecrementingItEquallyShouldLeaveNoUnappliedChanges) {
|
||||
lootState.incrementUnappliedChangeCounter();
|
||||
lootState.incrementUnappliedChangeCounter();
|
||||
lootState.decrementUnappliedChangeCounter();
|
||||
lootState.decrementUnappliedChangeCounter();
|
||||
EXPECT_FALSE(lootState.hasUnappliedChanges());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -52,6 +52,7 @@
|
||||
#include "backend/test_masterlist.h"
|
||||
#include "backend/test_plugin_sorter.h"
|
||||
#include "gui/test_loot_settings.h"
|
||||
#include "gui/test_loot_state.h"
|
||||
|
||||
#include <boost/log/core.hpp>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user