mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Improve ConditionalMetadata tests
This commit is contained in:
+1
-1
@@ -245,7 +245,7 @@ set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/version_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/helpers/yaml_set_helpers_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata/condition_grammar_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata/test_conditional_metadata.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata/conditional_metadata_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata/test_file.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata/test_location.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata/test_message.h"
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2014-2016 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_BACKEND_METADATA_CONDITIONAL_METADATA
|
||||
#define LOOT_TEST_BACKEND_METADATA_CONDITIONAL_METADATA
|
||||
|
||||
#include "backend/error.h"
|
||||
#include "backend/metadata/conditional_metadata.h"
|
||||
#include "tests/base_game_test.h"
|
||||
|
||||
namespace loot {
|
||||
namespace test {
|
||||
class ConditionalMetadataTest : public BaseGameTest {
|
||||
protected:
|
||||
ConditionalMetadata conditionalMetadata;
|
||||
};
|
||||
|
||||
// Pass an empty first argument, as it's a prefix for the test instantation,
|
||||
// but we only have the one so no prefix is necessary.
|
||||
INSTANTIATE_TEST_CASE_P(,
|
||||
ConditionalMetadataTest,
|
||||
::testing::Values(
|
||||
GameSettings::tes4,
|
||||
GameSettings::tes5,
|
||||
GameSettings::fo3,
|
||||
GameSettings::fonv,
|
||||
GameSettings::fo4));
|
||||
|
||||
TEST_P(ConditionalMetadataTest, defaultConstructorShouldSetEmptyConditionString) {
|
||||
EXPECT_TRUE(conditionalMetadata.Condition().empty());
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, stringConstructorShouldSetConditionToGivenString) {
|
||||
std::string condition("condition");
|
||||
conditionalMetadata = ConditionalMetadata(condition);
|
||||
|
||||
EXPECT_EQ(condition, conditionalMetadata.Condition());
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, isConditionalShouldBeFalseForAnEmptyConditionString) {
|
||||
EXPECT_FALSE(conditionalMetadata.IsConditional());
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, isConditionalShouldBeTrueForANonEmptyConditionString) {
|
||||
conditionalMetadata = ConditionalMetadata("condition");
|
||||
EXPECT_TRUE(conditionalMetadata.IsConditional());
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, evalConditionShouldReturnTrueForAnEmptyCondition) {
|
||||
Game game(GetParam());
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
|
||||
EXPECT_TRUE(conditionalMetadata.EvalCondition(game));
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, evalConditionShouldThrowForAnInvalidCondition) {
|
||||
Game game(GetParam());
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
|
||||
conditionalMetadata = ConditionalMetadata("condition");
|
||||
EXPECT_THROW(conditionalMetadata.EvalCondition(game), error);
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, evalConditionShouldReturnTrueForAConditionThatIsTrue) {
|
||||
Game game(GetParam());
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
|
||||
conditionalMetadata = ConditionalMetadata("file(\"" + blankEsm + "\")");
|
||||
EXPECT_TRUE(conditionalMetadata.EvalCondition(game));
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, evalConditionShouldReturnFalseForAConditionThatIsFalse) {
|
||||
Game game(GetParam());
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
|
||||
conditionalMetadata = ConditionalMetadata("file(\"" + missingEsp + "\")");
|
||||
EXPECT_FALSE(conditionalMetadata.EvalCondition(game));
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, parseConditionShouldNotThrowForAnEmptyCondition) {
|
||||
EXPECT_NO_THROW(conditionalMetadata.ParseCondition());
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, parseConditionShouldThrowForAnInvalidCondition) {
|
||||
conditionalMetadata = ConditionalMetadata("condition");
|
||||
EXPECT_THROW(conditionalMetadata.ParseCondition(), error);
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, parseConditionShouldNotThrowForATrueCondition) {
|
||||
conditionalMetadata = ConditionalMetadata("file(\"" + blankEsm + "\")");
|
||||
EXPECT_NO_THROW(conditionalMetadata.ParseCondition());
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, parseConditionShouldNotThrowForAFalseCondition) {
|
||||
conditionalMetadata = ConditionalMetadata("file(\"" + missingEsp + "\")");
|
||||
EXPECT_NO_THROW(conditionalMetadata.ParseCondition());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,90 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2014-2016 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_BACKEND_METADATA_CONDITIONAL_METADATA
|
||||
#define LOOT_TEST_BACKEND_METADATA_CONDITION_GRAMMAR
|
||||
|
||||
#include "backend/error.h"
|
||||
#include "backend/metadata/conditional_metadata.h"
|
||||
#include "tests/fixtures.h"
|
||||
|
||||
namespace loot {
|
||||
namespace test {
|
||||
class ConditionalMetadataTest : public SkyrimTest {};
|
||||
|
||||
TEST_F(ConditionalMetadataTest, ConstructorAndDataAccess) {
|
||||
ConditionalMetadata cm;
|
||||
EXPECT_EQ("", cm.Condition());
|
||||
|
||||
cm = ConditionalMetadata("condition");
|
||||
EXPECT_EQ("condition", cm.Condition());
|
||||
}
|
||||
|
||||
TEST_F(ConditionalMetadataTest, IsConditional) {
|
||||
ConditionalMetadata cm;
|
||||
EXPECT_FALSE(cm.IsConditional());
|
||||
|
||||
cm = ConditionalMetadata("condition");
|
||||
EXPECT_TRUE(cm.IsConditional());
|
||||
}
|
||||
|
||||
TEST_F(ConditionalMetadataTest, EvalCondition) {
|
||||
Game game(Game::tes5);
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
ASSERT_NO_THROW(game.Init(false, localPath));
|
||||
|
||||
ConditionalMetadata cm;
|
||||
EXPECT_TRUE(cm.EvalCondition(game));
|
||||
|
||||
cm = ConditionalMetadata("condition");
|
||||
EXPECT_THROW(cm.EvalCondition(game), error);
|
||||
|
||||
cm = ConditionalMetadata("file(\"Blank.esm\")");
|
||||
EXPECT_TRUE(cm.EvalCondition(game));
|
||||
|
||||
cm = ConditionalMetadata("file(\"Blank.missing.esm\")");
|
||||
EXPECT_FALSE(cm.EvalCondition(game));
|
||||
}
|
||||
|
||||
TEST_F(ConditionalMetadataTest, ParseCondition) {
|
||||
ConditionalMetadata cm;
|
||||
EXPECT_NO_THROW(cm.ParseCondition());
|
||||
|
||||
cm = ConditionalMetadata("condition");
|
||||
EXPECT_THROW(cm.ParseCondition(), error);
|
||||
|
||||
// Check that invalid regex also throws.
|
||||
cm = ConditionalMetadata("regex(\"RagnvaldBook(Farengar(+Ragnvald)?)?\\.esp\")");
|
||||
EXPECT_THROW(cm.ParseCondition(), error);
|
||||
|
||||
cm = ConditionalMetadata("file(\"Blank.esm\")");
|
||||
EXPECT_NO_THROW(cm.ParseCondition());
|
||||
|
||||
cm = ConditionalMetadata("file(\"Blank.missing.esm\")");
|
||||
EXPECT_NO_THROW(cm.ParseCondition());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -51,7 +51,7 @@
|
||||
#include "backend/helpers/version_test.h"
|
||||
#include "backend/helpers/yaml_set_helpers_test.h"
|
||||
#include "backend/metadata/condition_grammar_test.h"
|
||||
#include "backend/metadata/test_conditional_metadata.h"
|
||||
#include "backend/metadata/conditional_metadata_test.h"
|
||||
#include "backend/metadata/test_file.h"
|
||||
#include "backend/metadata/test_location.h"
|
||||
#include "backend/metadata/test_message.h"
|
||||
|
||||
Reference in New Issue
Block a user