From ed77fa9fbfd6b3f5ed4ecb7079f6e0859812a873 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 20 Apr 2025 16:00:22 +0100 Subject: [PATCH] Add C++ tests for the C++ API metadata types Taken from the same files in libloot v0.26.0, with the YAML tests removed. --- cxx/cmake/tests.cmake | 19 +- cxx/src/tests/api/internals/main.cpp | 10 + .../metadata/condition_evaluator_test.h | 267 ++++++++++++ .../metadata/conditional_metadata_test.h | 77 ++++ .../tests/api/internals/metadata/file_test.h | 386 +++++++++++++++++ .../tests/api/internals/metadata/group_test.h | 355 ++++++++++++++++ .../api/internals/metadata/location_test.h | 239 +++++++++++ .../internals/metadata/message_content_test.h | 335 +++++++++++++++ .../api/internals/metadata/message_test.h | 347 +++++++++++++++ .../metadata/plugin_cleaning_data_test.h | 315 ++++++++++++++ .../internals/metadata/plugin_metadata_test.h | 397 ++++++++++++++++++ .../tests/api/internals/metadata/tag_test.h | 289 +++++++++++++ 12 files changed, 3031 insertions(+), 5 deletions(-) create mode 100644 cxx/src/tests/api/internals/metadata/condition_evaluator_test.h create mode 100644 cxx/src/tests/api/internals/metadata/conditional_metadata_test.h create mode 100644 cxx/src/tests/api/internals/metadata/file_test.h create mode 100644 cxx/src/tests/api/internals/metadata/group_test.h create mode 100644 cxx/src/tests/api/internals/metadata/location_test.h create mode 100644 cxx/src/tests/api/internals/metadata/message_content_test.h create mode 100644 cxx/src/tests/api/internals/metadata/message_test.h create mode 100644 cxx/src/tests/api/internals/metadata/plugin_cleaning_data_test.h create mode 100644 cxx/src/tests/api/internals/metadata/plugin_metadata_test.h create mode 100644 cxx/src/tests/api/internals/metadata/tag_test.h diff --git a/cxx/cmake/tests.cmake b/cxx/cmake/tests.cmake index 4ff94610..8eed90d0 100644 --- a/cxx/cmake/tests.cmake +++ b/cxx/cmake/tests.cmake @@ -36,7 +36,16 @@ set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_INITIAL}) set(LIBLOOT_SRC_TESTS_INTERNALS_CPP_FILES "${CMAKE_SOURCE_DIR}/src/tests/api/internals/main.cpp") -# set(LIBLOOT_SRC_TESTS_INTERNALS_H_FILES ) +set(LIBLOOT_SRC_TESTS_INTERNALS_H_FILES + "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/conditional_metadata_test.h" + "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/file_test.h" + "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/group_test.h" + "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/location_test.h" + "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/message_test.h" + "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/message_content_test.h" + "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/plugin_cleaning_data_test.h" + "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/plugin_metadata_test.h" + "${CMAKE_SOURCE_DIR}/src/tests/api/internals/metadata/tag_test.h") set(LIBLOOT_SRC_TESTS_INTERFACE_CPP_FILES "${CMAKE_SOURCE_DIR}/src/tests/api/interface/main.cpp") @@ -52,9 +61,9 @@ source_group(TREE "${CMAKE_SOURCE_DIR}/src/tests/api/internals" PREFIX "Source Files" FILES ${LIBLOOT_SRC_TESTS_INTERNALS_CPP_FILES}) -# source_group(TREE "${CMAKE_SOURCE_DIR}/src/tests/api/internals" -# PREFIX "Header Files" -# FILES ${LIBLOOT_SRC_TESTS_INTERNALS_H_FILES}) +source_group(TREE "${CMAKE_SOURCE_DIR}/src/tests/api/internals" + PREFIX "Header Files" + FILES ${LIBLOOT_SRC_TESTS_INTERNALS_H_FILES}) source_group(TREE "${CMAKE_SOURCE_DIR}/src/tests/api/interface" PREFIX "Source Files" @@ -68,7 +77,7 @@ source_group(TREE "${CMAKE_SOURCE_DIR}/src/tests/api/interface" set(LIBLOOT_INTERNALS_TESTS_ALL_SOURCES ${LIBLOOT_ALL_SOURCES} ${LIBLOOT_SRC_TESTS_INTERNALS_CPP_FILES} - # ${LIBLOOT_SRC_TESTS_INTERNALS_H_FILES} + ${LIBLOOT_SRC_TESTS_INTERNALS_H_FILES} "${CMAKE_SOURCE_DIR}/src/tests/common_game_test_fixture.h" "${CMAKE_SOURCE_DIR}/src/tests/test_helpers.h" "${CMAKE_SOURCE_DIR}/src/tests/printers.h") diff --git a/cxx/src/tests/api/internals/main.cpp b/cxx/src/tests/api/internals/main.cpp index a2ed24fa..9ecbe6a8 100644 --- a/cxx/src/tests/api/internals/main.cpp +++ b/cxx/src/tests/api/internals/main.cpp @@ -5,6 +5,16 @@ #include "libloot-cxx/src/lib.rs.h" #include "rust/cxx.h" +#include "tests/api/internals/metadata/conditional_metadata_test.h" +#include "tests/api/internals/metadata/file_test.h" +#include "tests/api/internals/metadata/group_test.h" +#include "tests/api/internals/metadata/location_test.h" +#include "tests/api/internals/metadata/message_content_test.h" +#include "tests/api/internals/metadata/message_test.h" +#include "tests/api/internals/metadata/plugin_cleaning_data_test.h" +#include "tests/api/internals/metadata/plugin_metadata_test.h" +#include "tests/api/internals/metadata/tag_test.h" + namespace rust { template bool operator==(const Vec& lhs, const Vec& rhs) { diff --git a/cxx/src/tests/api/internals/metadata/condition_evaluator_test.h b/cxx/src/tests/api/internals/metadata/condition_evaluator_test.h new file mode 100644 index 00000000..deab40c3 --- /dev/null +++ b/cxx/src/tests/api/internals/metadata/condition_evaluator_test.h @@ -0,0 +1,267 @@ +/* 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 +. +*/ + +#ifndef LOOT_TESTS_API_INTERNALS_METADATA_CONDITION_EVALUATOR_TEST +#define LOOT_TESTS_API_INTERNALS_METADATA_CONDITION_EVALUATOR_TEST + +#include "api/metadata/condition_evaluator.h" +#include "loot/exception/condition_syntax_error.h" +#include "tests/common_game_test_fixture.h" + +namespace loot { +namespace test { +class ConditionEvaluatorTest : public CommonGameTestFixture, + public testing::WithParamInterface { +protected: + ConditionEvaluatorTest() : + CommonGameTestFixture(GetParam()), + info_(std::vector({ + MessageContent("info"), + })), + nonAsciiEsm(u8"non\u00C1scii.esm"), + nonAsciiNestedFile(u8"non\u00C1scii/test.txt"), + game_(GetParam(), gamePath, localPath), + evaluator_(game_.GetType(), game_.DataPath()) { + // Make sure the plugin with a non-ASCII filename exists. + std::filesystem::copy_file(dataPath / blankEsm, + dataPath / std::filesystem::u8path(nonAsciiEsm)); + + touch(dataPath / std::filesystem::u8path(nonAsciiNestedFile)); + + loadInstalledPlugins(); + evaluator_.RefreshLoadedPluginsState(game_.GetLoadedPlugins()); + evaluator_.RefreshActivePluginsState( + game_.GetLoadOrderHandler().GetActivePlugins()); + } + + std::string IntToHexString(const uint32_t value) { + std::stringstream stream; + stream << std::hex << value; + return stream.str(); + } + + void loadInstalledPlugins() { + auto plugins = GetInstalledPlugins(); + + plugins.push_back(std::filesystem::u8path(nonAsciiEsm)); + + game_.LoadCurrentLoadOrderState(); + game_.LoadPlugins(plugins, true); + } + + const std::vector info_; + const std::string nonAsciiEsm; + const std::string nonAsciiNestedFile; + + Game game_; + ConditionEvaluator evaluator_; +}; + +// 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_SUITE_P(, + ConditionEvaluatorTest, + ::testing::Values(GameType::tes3, + GameType::tes4, + GameType::tes5, + GameType::fo3, + GameType::fonv, + GameType::fo4, + GameType::tes5se, + GameType::openmw)); + +TEST_P(ConditionEvaluatorTest, + evaluateShouldReturnTrueForAnEmptyConditionString) { + EXPECT_TRUE(evaluator_.Evaluate("")); +} + +TEST_P(ConditionEvaluatorTest, evaluateShouldThrowForAnInvalidConditionString) { + EXPECT_THROW(evaluator_.Evaluate("condition"), ConditionSyntaxError); +} + +TEST_P(ConditionEvaluatorTest, + evaluateShouldReturnTrueForAConditionThatIsTrue) { + EXPECT_TRUE(evaluator_.Evaluate("file(\"" + blankEsm + "\")")); +} + +TEST_P(ConditionEvaluatorTest, evaluateShouldUseAllGivenDataPaths) { + ASSERT_FALSE( + evaluator_.Evaluate("file(\"" + localPath.filename().u8string() + "\")")); + + evaluator_.ClearConditionCache(); + evaluator_.SetAdditionalDataPaths({localPath.parent_path()}); + + EXPECT_TRUE( + evaluator_.Evaluate("file(\"" + localPath.filename().u8string() + "\")")); +} + +TEST_P(ConditionEvaluatorTest, + evaluateFileConditionShouldReturnTrueForANonAsciiFileThatExists) { + EXPECT_TRUE(evaluator_.Evaluate("file(\"" + nonAsciiEsm + "\")")); +} + +TEST_P(ConditionEvaluatorTest, + evaluateChecksumConditionShouldBeAbleToGetTheCrcOfANonAsciiFile) { + std::string condition("checksum(\"" + nonAsciiEsm + "\", " + + IntToHexString(blankEsmCrc) + ")"); + EXPECT_TRUE(evaluator_.Evaluate(condition)); +} + +TEST_P(ConditionEvaluatorTest, + evaluateVersionConditionShouldBeAbleToGetTheVersionOfANonAsciiFile) { + std::string condition("version(\"" + nonAsciiEsm + "\", \"5.0\", ==)"); + EXPECT_TRUE(evaluator_.Evaluate(condition)); +} + +TEST_P(ConditionEvaluatorTest, + evaluateActiveConditionShouldReturnTrueForAnActivePlugin) { + std::string condition("active(\"" + blankEsm + "\")"); + EXPECT_TRUE(evaluator_.Evaluate(condition)); +} + +TEST_P(ConditionEvaluatorTest, + evaluateRegexFileConditionShouldReturnTrueForANonAsciiFileThatExists) { + std::string condition(u8"file(\"non\u00C1scii.*\\.esm\")"); + EXPECT_TRUE(evaluator_.Evaluate(condition)); +} + +TEST_P( + ConditionEvaluatorTest, + evaluateRegexFileConditionShouldReturnTrueForANonAsciiNestedFileThatExists) { + std::string condition(u8"file(\"non\u00C1scii/.+\\.txt\")"); + EXPECT_TRUE(evaluator_.Evaluate(condition)); +} + +TEST_P(ConditionEvaluatorTest, + evaluateShouldReturnFalseForAConditionThatIsFalse) { + EXPECT_FALSE(evaluator_.Evaluate("file(\"" + missingEsp + "\")")); +} + +TEST_P(ConditionEvaluatorTest, evaluateAllShouldEvaluateAllMetadataConditions) { + PluginMetadata plugin(nonAsciiEsm); + plugin.SetGroup("group1"); + + File file1(blankEsp); + File file2(blankDifferentEsm, "", "file(\"" + missingEsp + "\")"); + plugin.SetLoadAfterFiles({file1, file2}); + plugin.SetRequirements({file1, file2}); + plugin.SetIncompatibilities({file1, file2}); + + Message message1(MessageType::say, "content"); + Message message2(MessageType::say, "content", "file(\"" + missingEsp + "\")"); + plugin.SetMessages({message1, message2}); + + Tag tag1("Relev"); + Tag tag2("Relev", true, "file(\"" + missingEsp + "\")"); + plugin.SetTags({tag1, tag2}); + + PluginCleaningData info1(blankEsmCrc, "utility", info_, 1, 2, 3); + PluginCleaningData info2(0xDEADBEEF, "utility", info_, 1, 2, 3); + plugin.SetDirtyInfo({info1, info2}); + plugin.SetCleanInfo({info1, info2}); + + EXPECT_NO_THROW(plugin = evaluator_.EvaluateAll(plugin)); + + std::vector expectedFiles({file1}); + EXPECT_EQ("group1", plugin.GetGroup().value()); + EXPECT_EQ(expectedFiles, plugin.GetLoadAfterFiles()); + EXPECT_EQ(expectedFiles, plugin.GetRequirements()); + EXPECT_EQ(expectedFiles, plugin.GetIncompatibilities()); + EXPECT_EQ(std::vector({message1}), plugin.GetMessages()); + EXPECT_EQ(std::vector({tag1}), plugin.GetTags()); + EXPECT_EQ(std::vector({info1}), plugin.GetDirtyInfo()); + EXPECT_EQ(std::vector({info1}), plugin.GetCleanInfo()); +} + +TEST_P(ConditionEvaluatorTest, evaluateAllShouldPreserveGroupExplicitness) { + PluginMetadata plugin(blankEsm); + + EXPECT_NO_THROW(plugin = evaluator_.EvaluateAll(plugin)); + EXPECT_FALSE(plugin.GetGroup()); +} + +TEST_P(ConditionEvaluatorTest, + refreshActivePluginsStateShouldClearTheConditionCache) { + std::string condition("active(\"" + blankEsm + "\")"); + ASSERT_TRUE(evaluator_.Evaluate(condition)); + + evaluator_.RefreshActivePluginsState({blankEsp}); + + EXPECT_FALSE(evaluator_.Evaluate(condition)); +} + +TEST_P( + ConditionEvaluatorTest, + refreshActivePluginsStateShouldClearTheActivePluginsCacheIfGivenAnEmptyVector) { + std::string condition("active(\"" + blankEsm + "\")"); + ASSERT_TRUE(evaluator_.Evaluate(condition)); + + evaluator_.RefreshActivePluginsState({}); + + EXPECT_FALSE(evaluator_.Evaluate(condition)); +} + +TEST_P(ConditionEvaluatorTest, + refreshLoadedPluginsStateShouldClearTheConditionCache) { + std::string condition("version(\"" + blankEsm + "\", \"5.0\", ==)"); + + ASSERT_TRUE(evaluator_.Evaluate(condition)); + + auto plugins = game_.GetLoadedPlugins(); + auto pluginsIt = + std::find_if(plugins.cbegin(), plugins.cend(), [&](auto plugin) { + return plugin->GetName() == blankEsm; + }); + plugins.erase(pluginsIt); + evaluator_.RefreshLoadedPluginsState(plugins); + + EXPECT_FALSE(evaluator_.Evaluate(condition)); +} + +TEST_P( + ConditionEvaluatorTest, + refreshLoadedPluginsStateShouldClearTheVersionsCacheIfGivenAnEmptyVector) { + std::string condition("version(\"" + blankEsm + "\", \"5.0\", ==)"); + + ASSERT_TRUE(evaluator_.Evaluate(condition)); + + evaluator_.RefreshLoadedPluginsState({}); + + EXPECT_FALSE(evaluator_.Evaluate(condition)); +} + +TEST_P(ConditionEvaluatorTest, + setAdditionalDataPathsShouldAcceptAnEmptyVector) { + EXPECT_NO_THROW(evaluator_.SetAdditionalDataPaths({})); +} + +TEST_P(ConditionEvaluatorTest, + setAdditionalDataPathsShouldAcceptANonEmptyVector) { + EXPECT_NO_THROW(evaluator_.SetAdditionalDataPaths( + {std::filesystem::u8path("a"), std::filesystem::u8path("b")})); +} +} +} + +#endif diff --git a/cxx/src/tests/api/internals/metadata/conditional_metadata_test.h b/cxx/src/tests/api/internals/metadata/conditional_metadata_test.h new file mode 100644 index 00000000..4fdf0012 --- /dev/null +++ b/cxx/src/tests/api/internals/metadata/conditional_metadata_test.h @@ -0,0 +1,77 @@ +/* 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 +. +*/ + +#ifndef LOOT_TESTS_API_INTERNALS_METADATA_CONDITIONAL_METADATA_TEST +#define LOOT_TESTS_API_INTERNALS_METADATA_CONDITIONAL_METADATA_TEST + +#include "loot/metadata/conditional_metadata.h" +#include "tests/common_game_test_fixture.h" + +namespace loot { +namespace test { +class ConditionalMetadataTest : public CommonGameTestFixture, + public testing::WithParamInterface { +protected: + ConditionalMetadataTest() : CommonGameTestFixture(GetParam()) {} + 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_SUITE_P(, + ConditionalMetadataTest, + ::testing::Values(GameType::tes4, + GameType::tes5, + GameType::fo3, + GameType::fonv, + GameType::fo4, + GameType::tes5se)); + +TEST_P(ConditionalMetadataTest, + defaultConstructorShouldSetEmptyConditionString) { + EXPECT_TRUE(conditionalMetadata_.GetCondition().empty()); +} + +TEST_P(ConditionalMetadataTest, + stringConstructorShouldSetConditionToGivenString) { + std::string condition("condition"); + conditionalMetadata_ = ConditionalMetadata(condition); + + EXPECT_EQ(condition, conditionalMetadata_.GetCondition()); +} + +TEST_P(ConditionalMetadataTest, + isConditionalShouldBeFalseForAnEmptyConditionString) { + EXPECT_FALSE(conditionalMetadata_.IsConditional()); +} + +TEST_P(ConditionalMetadataTest, + isConditionalShouldBeTrueForANonEmptyConditionString) { + conditionalMetadata_ = ConditionalMetadata("condition"); + EXPECT_TRUE(conditionalMetadata_.IsConditional()); +} +} +} + +#endif diff --git a/cxx/src/tests/api/internals/metadata/file_test.h b/cxx/src/tests/api/internals/metadata/file_test.h new file mode 100644 index 00000000..e1ae3a2d --- /dev/null +++ b/cxx/src/tests/api/internals/metadata/file_test.h @@ -0,0 +1,386 @@ +/* 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 +. +*/ + +#ifndef LOOT_TESTS_API_INTERNALS_METADATA_FILE_TEST +#define LOOT_TESTS_API_INTERNALS_METADATA_FILE_TEST + +#include + +#include "loot/metadata/file.h" + +namespace loot { +namespace test { +TEST(File, defaultConstructorShouldInitialiseEmptyStrings) { + File file; + + EXPECT_EQ("", std::string(file.GetName())); + EXPECT_EQ("", file.GetDisplayName()); + EXPECT_EQ("", file.GetCondition()); + EXPECT_EQ("", file.GetConstraint()); +} + +TEST(File, stringsConstructorShouldStoreGivenStrings) { + std::vector detail = {MessageContent("text", "en")}; + File file("name", "display", "condition", detail, "constraint"); + + EXPECT_EQ("name", std::string(file.GetName())); + EXPECT_EQ("display", file.GetDisplayName()); + EXPECT_EQ("condition", file.GetCondition()); + EXPECT_EQ(detail, file.GetDetail()); + EXPECT_EQ("constraint", file.GetConstraint()); +} + +TEST(File, equalityShouldBeCaseInsensitiveOnName) { + File file1("name", "display", "condition"); + File file2("name", "display", "condition"); + + EXPECT_TRUE(file1 == file2); + + file1 = File("name", "display", "condition"); + file2 = File("Name", "display", "condition"); + + EXPECT_TRUE(file1 == file2); + + file1 = File("name1", "display", "condition"); + file2 = File("name2", "display", "condition"); + + EXPECT_FALSE(file1 == file2); +} + +TEST(File, equalityShouldBeCaseSensitiveOnDisplayAndConditionAndConstraint) { + File file1("name", "display", "condition"); + File file2("name", "display", "condition"); + + EXPECT_TRUE(file1 == file2); + + file1 = File("name", "display", "condition"); + file2 = File("name", "Display", "condition"); + + EXPECT_FALSE(file1 == file2); + + file1 = File("name", "display", "condition"); + file2 = File("name", "display", "Condition"); + + EXPECT_FALSE(file1 == file2); + + file1 = File("name", "display", "condition", {}, "constraint"); + file2 = File("name", "display", "condition", {}, "Constraint"); + + EXPECT_FALSE(file1 == file2); + + file1 = File("name", "display1", "condition"); + file2 = File("name", "display2", "condition"); + + EXPECT_FALSE(file1 == file2); + + file1 = File("name", "display", "condition1"); + file2 = File("name", "display", "condition2"); + + EXPECT_FALSE(file1 == file2); + + file1 = File("name", "display", "condition", {}, "constraint1"); + file2 = File("name", "display", "condition", {}, "constraint2"); + + EXPECT_FALSE(file1 == file2); +} + +TEST(File, equalityShouldCompareTheDetailVectors) { + File file1("", "", "", {MessageContent("text", "en")}); + File file2("", "", "", {MessageContent("text", "en")}); + + EXPECT_TRUE(file1 == file2); + + file1 = File("", "", "", {MessageContent("text", "en")}); + file2 = File("", "", "", {MessageContent("Text", "en")}); + + EXPECT_FALSE(file1 == file2); + + file1 = File("", "", "", {MessageContent("text", "en")}); + file2 = File("", "", "", {MessageContent("text", "En")}); + + EXPECT_FALSE(file1 == file2); + + file1 = File( + "", "", "", {MessageContent("text", "en"), MessageContent("text", "en")}); + file2 = File("", "", "", {MessageContent("text", "en")}); + + EXPECT_FALSE(file1 == file2); +} + +TEST(File, inequalityShouldBeTheInverseOfEquality) { + File file1("name", "display", "condition", {MessageContent("text", "en")}); + File file2("name", "display", "condition", {MessageContent("text", "en")}); + + EXPECT_FALSE(file1 != file2); + + file1 = File("name", "display", "condition"); + file2 = File("name", "Display", "condition"); + + EXPECT_TRUE(file1 != file2); + + file1 = File("name", "display", "condition"); + file2 = File("name", "display", "Condition"); + + EXPECT_TRUE(file1 != file2); + + file1 = File("name", "display", "condition", {}, "constraint"); + file2 = File("name", "display", "condition", {}, "Constraint"); + + EXPECT_TRUE(file1 != file2); + + file1 = File("name", "display1", "condition"); + file2 = File("name", "display2", "condition"); + + EXPECT_TRUE(file1 != file2); + + file1 = File("name", "display", "condition1"); + file2 = File("name", "display", "condition2"); + + EXPECT_TRUE(file1 != file2); + + file1 = File("", "", "", {MessageContent("text", "en")}); + file2 = File("", "", "", {MessageContent("Text", "en")}); + + EXPECT_TRUE(file1 != file2); + + file1 = File("name", "display", "condition", {}, "constraint1"); + file2 = File("name", "display", "condition", {}, "constraint2"); + + EXPECT_TRUE(file1 != file2); +} + +TEST(File, + lessThanOperatorShouldUseCaseInsensitiveLexicographicalComparisonForName) { + File file1("name", "display", "condition"); + File file2("name", "display", "condition"); + + EXPECT_FALSE(file1 < file2); + EXPECT_FALSE(file2 < file1); + + file1 = File("name", "display", "condition"); + file2 = File("Name", "display", "condition"); + + EXPECT_FALSE(file1 < file2); + EXPECT_FALSE(file2 < file1); + + file1 = File("name1"); + file2 = File("name2"); + + EXPECT_TRUE(file1 < file2); + EXPECT_FALSE(file2 < file1); +} + +TEST( + File, + lessThanOperatorShouldUseCaseSensitiveLexicographicalComparisonForDisplayAndConditionAndConstraint) { + File file1("name", "display", "condition"); + File file2("name", "display", "condition"); + + EXPECT_FALSE(file1 < file2); + EXPECT_FALSE(file2 < file1); + + file1 = File("name", "display", "condition"); + file2 = File("name", "Display", "condition"); + + EXPECT_TRUE(file2 < file1); + EXPECT_FALSE(file1 < file2); + + file1 = File("name", "display", "condition"); + file2 = File("name", "display", "Condition"); + + EXPECT_TRUE(file2 < file1); + EXPECT_FALSE(file1 < file2); + + file1 = File("name", "display", "condition", {}, "constraint"); + file2 = File("name", "display", "condition", {}, "Constraint"); + + EXPECT_TRUE(file2 < file1); + EXPECT_FALSE(file1 < file2); + + file1 = File("name", "display1"); + file2 = File("name", "display2"); + + EXPECT_TRUE(file1 < file2); + EXPECT_FALSE(file2 < file1); + + file1 = File("name", "display", "condition1"); + file2 = File("name", "display", "condition2"); + + EXPECT_TRUE(file1 < file2); + EXPECT_FALSE(file2 < file1); + + file1 = File("name", "display", "condition", {}, "constraint1"); + file2 = File("name", "display", "condition", {}, "constraint2"); + + EXPECT_TRUE(file1 < file2); + EXPECT_FALSE(file2 < file1); +} + +TEST(File, lessThanOperatorShouldCompareTheDetailVectors) { + File file1("", "", "", {MessageContent("text", "en")}); + File file2("", "", "", {MessageContent("text", "en")}); + + EXPECT_FALSE(file1 < file2); + + file1 = File("", "", "", {MessageContent("text", "en")}); + file2 = File("", "", "", {MessageContent("Text", "en")}); + + EXPECT_FALSE(file1 < file2); + + file1 = File("", "", "", {MessageContent("text", "en")}); + file2 = File("", "", "", {MessageContent("text", "En")}); + + EXPECT_FALSE(file1 < file2); + + file1 = File( + "", "", "", {MessageContent("text", "en"), MessageContent("text", "en")}); + file2 = File("", "", "", {MessageContent("text", "en")}); + + EXPECT_FALSE(file1 < file2); +} + +TEST(File, shouldAllowComparisonUsingGreaterThanOperator) { + File file1("name", "display", "condition", {MessageContent("text", "en")}); + File file2("name", "display", "condition", {MessageContent("text", "en")}); + + EXPECT_FALSE(file1 > file2); + EXPECT_FALSE(file2 > file1); + + file1 = File("name", "display", "condition"); + file2 = File("name", "Display", "condition"); + + EXPECT_FALSE(file2 > file1); + EXPECT_TRUE(file1 > file2); + + file1 = File("name", "display", "condition"); + file2 = File("name", "display", "Condition"); + + EXPECT_FALSE(file2 > file1); + EXPECT_TRUE(file1 > file2); + + file1 = File("name", "display1"); + file2 = File("name", "display2"); + + EXPECT_FALSE(file1 > file2); + EXPECT_TRUE(file2 > file1); + + file1 = File("name", "display", "condition1"); + file2 = File("name", "display", "condition2"); + + EXPECT_FALSE(file1 > file2); + EXPECT_TRUE(file2 > file1); + + file1 = File("", "", "", {MessageContent("text", "en")}); + file2 = File("", "", "", {MessageContent("Text", "en")}); + + EXPECT_TRUE(file1 > file2); +} + +TEST( + File, + lessThanOrEqualToOperatorShouldReturnTrueIfFirstFileIsNotGreaterThanSecondFile) { + File file1("name", "display", "condition", {MessageContent("text", "en")}); + File file2("name", "display", "condition", {MessageContent("text", "en")}); + + EXPECT_TRUE(file1 <= file2); + EXPECT_TRUE(file2 <= file1); + + file1 = File("name", "display", "condition"); + file2 = File("name", "Display", "condition"); + + EXPECT_TRUE(file2 <= file1); + EXPECT_FALSE(file1 <= file2); + + file1 = File("name", "display", "condition"); + file2 = File("name", "display", "Condition"); + + EXPECT_TRUE(file2 <= file1); + EXPECT_FALSE(file1 <= file2); + + file1 = File("name", "display1"); + file2 = File("name", "display2"); + + EXPECT_TRUE(file1 <= file2); + EXPECT_FALSE(file2 <= file1); + + file1 = File("name", "display", "condition1"); + file2 = File("name", "display", "condition2"); + + EXPECT_TRUE(file1 <= file2); + EXPECT_FALSE(file2 <= file1); + + file1 = File("", "", "", {MessageContent("text", "en")}); + file2 = File("", "", "", {MessageContent("Text", "en")}); + + EXPECT_FALSE(file1 <= file2); +} + +TEST( + File, + greaterThanOrEqualToOperatorShouldReturnTrueIfFirstFileIsNotLessThanSecondFile) { + File file1("name", "display", "condition", {MessageContent("text", "en")}); + File file2("name", "display", "condition", {MessageContent("text", "en")}); + + EXPECT_TRUE(file1 >= file2); + EXPECT_TRUE(file2 >= file1); + + file1 = File("name", "display", "condition"); + file2 = File("name", "Display", "condition"); + + EXPECT_FALSE(file2 >= file1); + EXPECT_TRUE(file1 >= file2); + + file1 = File("name", "display", "condition"); + file2 = File("name", "display", "Condition"); + + EXPECT_FALSE(file2 >= file1); + EXPECT_TRUE(file1 >= file2); + + file1 = File("name", "display1"); + file2 = File("name", "display2"); + + EXPECT_FALSE(file1 >= file2); + EXPECT_TRUE(file2 >= file1); + + file1 = File("name", "display", "condition1"); + file2 = File("name", "display", "condition2"); + + EXPECT_FALSE(file1 >= file2); + EXPECT_TRUE(file2 >= file1); + + file1 = File("", "", "", {MessageContent("text", "en")}); + file2 = File("", "", "", {MessageContent("Text", "en")}); + + EXPECT_TRUE(file1 >= file2); +} + +TEST(File, getDisplayNameShouldReturnDisplayString) { + File file("name", "display"); + + EXPECT_EQ("display", file.GetDisplayName()); +} +} +} + +#endif diff --git a/cxx/src/tests/api/internals/metadata/group_test.h b/cxx/src/tests/api/internals/metadata/group_test.h new file mode 100644 index 00000000..ae670152 --- /dev/null +++ b/cxx/src/tests/api/internals/metadata/group_test.h @@ -0,0 +1,355 @@ +/* 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 +. +*/ + +#ifndef LOOT_TESTS_API_INTERNALS_METADATA_GROUP_TEST +#define LOOT_TESTS_API_INTERNALS_METADATA_GROUP_TEST + +#include + +#include "loot/metadata/group.h" + +namespace loot { +namespace test { +TEST(Group, defaultConstructorShouldCreateDefaultGroup) { + Group group; + + EXPECT_EQ("default", group.GetName()); + EXPECT_TRUE(group.GetAfterGroups().empty()); +} + +TEST(Group, + allArgsConstructorShouldSetDescriptionAndAfterGroupsDefaultsAsEmpty) { + Group group("group1"); + + EXPECT_EQ("group1", group.GetName()); + EXPECT_TRUE(group.GetDescription().empty()); + EXPECT_TRUE(group.GetAfterGroups().empty()); +} + +TEST(Group, allArgsConstructorShouldStoreGivenValues) { + Group group("group1", {"other_group"}, "test"); + + EXPECT_EQ("group1", group.GetName()); + EXPECT_EQ("test", group.GetDescription()); + EXPECT_EQ(std::vector({"other_group"}), group.GetAfterGroups()); +} + +TEST(Group, equalityShouldBeCaseSensitiveOnNameAndDescription) { + Group group1("name", {}, "description"); + Group group2("name", {}, "description"); + + EXPECT_TRUE(group1 == group2); + + group1 = Group("name"); + group2 = Group("Name"); + + EXPECT_FALSE(group1 == group2); + + group1 = Group("name", {}, "description"); + group2 = Group("name", {}, "Description"); + + EXPECT_FALSE(group1 == group2); + + group1 = Group("name1"); + group2 = Group("name2"); + + EXPECT_FALSE(group1 == group2); + + group1 = Group("name", {}, "description1"); + group2 = Group("name", {}, "description2"); + + EXPECT_FALSE(group1 == group2); +} + +TEST(Group, equalityShouldRequireEqualAfterGroups) { + Group group1("name", {}, "description"); + Group group2("name", {}, "description"); + + EXPECT_TRUE(group1 == group2); + + group1 = Group("name", {}, "description"); + group2 = Group("name", {"after1"}, "Description"); + + EXPECT_FALSE(group1 == group2); +} + +TEST(Group, inequalityShouldBeTheInverseOfEquality) { + Group group1("name", {}, "description"); + Group group2("name", {}, "description"); + + EXPECT_FALSE(group1 != group2); + + group1 = Group("name"); + group2 = Group("Name"); + + EXPECT_TRUE(group1 != group2); + + group1 = Group("name", {}, "description"); + group2 = Group("name", {}, "Description"); + + EXPECT_TRUE(group1 != group2); + + group1 = Group("name1"); + group2 = Group("name2"); + + EXPECT_TRUE(group1 != group2); + + group1 = Group("name", {}, "description1"); + group2 = Group("name", {}, "description2"); + + EXPECT_TRUE(group1 != group2); + + group1 = Group("name", {}, "description"); + group2 = Group("name", {"after1"}, "Description"); + + EXPECT_TRUE(group1 != group2); +} + +TEST(Group, + lessThanOperatorShouldUseCaseSensitiveLexicographicalComparisonForNames) { + Group group1("name", {}, "description"); + Group group2("name", {}, "description"); + + EXPECT_FALSE(group1 < group2); + EXPECT_FALSE(group2 < group1); + + group1 = Group("Name", {}, "description"); + group2 = Group("name", {}, "description"); + + EXPECT_TRUE(group1 < group2); + EXPECT_FALSE(group2 < group1); + + group1 = Group("name1", {}, "description"); + group2 = Group("name2", {}, "description"); + + EXPECT_TRUE(group1 < group2); + EXPECT_FALSE(group2 < group1); +} + +TEST( + Group, + lessThanOperatorShouldUseCaseSensitiveLexicographicalComparisonForDescriptions) { + Group group1("name", {}, "description"); + Group group2("name", {}, "description"); + + EXPECT_FALSE(group1 < group2); + EXPECT_FALSE(group2 < group1); + + group1 = Group("name", {}, "Description"); + group2 = Group("name", {}, "description"); + + EXPECT_TRUE(group1 < group2); + EXPECT_FALSE(group2 < group1); + + group1 = Group("name", {}, "description1"); + group2 = Group("name", {}, "description2"); + + EXPECT_TRUE(group1 < group2); + EXPECT_FALSE(group2 < group1); +} + +TEST(Group, lessThanOperatorShouldCompareAfterGroups) { + Group group1("name", {}, "description"); + Group group2("name", {}, "description"); + + EXPECT_FALSE(group1 < group2); + EXPECT_FALSE(group2 < group1); + + group1 = Group("name", {}, "description"); + group2 = Group("name", {"group"}, "description"); + + EXPECT_TRUE(group1 < group2); + EXPECT_FALSE(group2 < group1); + + group1 = Group("name", {"Group"}, "description"); + group2 = Group("name", {"group"}, "description"); + + EXPECT_TRUE(group1 < group2); + EXPECT_FALSE(group2 < group1); + + group1 = Group("name", {"group1"}, "description"); + group2 = Group("name", {"group2"}, "description"); + + EXPECT_TRUE(group1 < group2); + EXPECT_FALSE(group2 < group1); +} + +TEST(Group, + greaterThanOperatorShouldReturnTrueIfTheSecondGroupIsLessThanTheFirst) { + Group group1("name", {}, "description"); + Group group2("name", {}, "description"); + + EXPECT_FALSE(group1 > group2); + EXPECT_FALSE(group2 > group1); + + group1 = Group("Name", {}, "description"); + group2 = Group("name", {}, "description"); + + EXPECT_FALSE(group1 > group2); + EXPECT_TRUE(group2 > group1); + + group1 = Group("name1", {}, "description"); + group2 = Group("name2", {}, "description"); + + EXPECT_FALSE(group1 > group2); + EXPECT_TRUE(group2 > group1); + + group1 = Group("name", {}, "Description"); + group2 = Group("name", {}, "description"); + + EXPECT_FALSE(group1 > group2); + EXPECT_TRUE(group2 > group1); + + group1 = Group("name", {}, "description1"); + group2 = Group("name", {}, "description2"); + + EXPECT_FALSE(group1 > group2); + EXPECT_TRUE(group2 > group1); + + group1 = Group("name", {}, "description"); + group2 = Group("name", {"group"}, "description"); + + EXPECT_FALSE(group1 > group2); + EXPECT_TRUE(group2 > group1); + + group1 = Group("name", {"Group"}, "description"); + group2 = Group("name", {"group"}, "description"); + + EXPECT_FALSE(group1 > group2); + EXPECT_TRUE(group2 > group1); + + group1 = Group("name", {"group1"}, "description"); + group2 = Group("name", {"group2"}, "description"); + + EXPECT_FALSE(group1 > group2); + EXPECT_TRUE(group2 > group1); +} + +TEST( + Group, + lessThanOrEqualToOperatorShouldReturnTrueIfTheFirstGroupIsNotGreaterThanTheSecond) { + Group group1("name", {}, "description"); + Group group2("name", {}, "description"); + + EXPECT_TRUE(group1 <= group2); + EXPECT_TRUE(group2 <= group1); + + group1 = Group("Name", {}, "description"); + group2 = Group("name", {}, "description"); + + EXPECT_TRUE(group1 <= group2); + EXPECT_FALSE(group2 <= group1); + + group1 = Group("name1", {}, "description"); + group2 = Group("name2", {}, "description"); + + EXPECT_TRUE(group1 <= group2); + EXPECT_FALSE(group2 <= group1); + + group1 = Group("name", {}, "Description"); + group2 = Group("name", {}, "description"); + + EXPECT_TRUE(group1 <= group2); + EXPECT_FALSE(group2 <= group1); + + group1 = Group("name", {}, "description1"); + group2 = Group("name", {}, "description2"); + + EXPECT_TRUE(group1 <= group2); + EXPECT_FALSE(group2 <= group1); + + group1 = Group("name", {}, "description"); + group2 = Group("name", {"group"}, "description"); + + EXPECT_TRUE(group1 <= group2); + EXPECT_FALSE(group2 <= group1); + + group1 = Group("name", {"Group"}, "description"); + group2 = Group("name", {"group"}, "description"); + + EXPECT_TRUE(group1 <= group2); + EXPECT_FALSE(group2 <= group1); + + group1 = Group("name", {"group1"}, "description"); + group2 = Group("name", {"group2"}, "description"); + + EXPECT_TRUE(group1 <= group2); + EXPECT_FALSE(group2 <= group1); +} + +TEST( + Group, + greaterThanOrEqualToOperatorShouldReturnTrueIfTheFirstGroupIsNotLessThanTheSecond) { + Group group1("name", {}, "description"); + Group group2("name", {}, "description"); + + EXPECT_TRUE(group1 >= group2); + EXPECT_TRUE(group2 >= group1); + + group1 = Group("Name", {}, "description"); + group2 = Group("name", {}, "description"); + + EXPECT_FALSE(group1 >= group2); + EXPECT_TRUE(group2 >= group1); + + group1 = Group("name1", {}, "description"); + group2 = Group("name2", {}, "description"); + + EXPECT_FALSE(group1 >= group2); + EXPECT_TRUE(group2 >= group1); + + group1 = Group("name", {}, "Description"); + group2 = Group("name", {}, "description"); + + EXPECT_FALSE(group1 >= group2); + EXPECT_TRUE(group2 >= group1); + + group1 = Group("name", {}, "description1"); + group2 = Group("name", {}, "description2"); + + EXPECT_FALSE(group1 >= group2); + EXPECT_TRUE(group2 >= group1); + + group1 = Group("name", {}, "description"); + group2 = Group("name", {"group"}, "description"); + + EXPECT_FALSE(group1 >= group2); + EXPECT_TRUE(group2 >= group1); + + group1 = Group("name", {"Group"}, "description"); + group2 = Group("name", {"group"}, "description"); + + EXPECT_FALSE(group1 >= group2); + EXPECT_TRUE(group2 >= group1); + + group1 = Group("name", {"group1"}, "description"); + group2 = Group("name", {"group2"}, "description"); + + EXPECT_FALSE(group1 >= group2); + EXPECT_TRUE(group2 >= group1); +} +} +} + +#endif diff --git a/cxx/src/tests/api/internals/metadata/location_test.h b/cxx/src/tests/api/internals/metadata/location_test.h new file mode 100644 index 00000000..6d9d3bcd --- /dev/null +++ b/cxx/src/tests/api/internals/metadata/location_test.h @@ -0,0 +1,239 @@ +/* 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 +. +*/ + +#ifndef LOOT_TESTS_API_INTERNALS_METADATA_LOCATION_TEST +#define LOOT_TESTS_API_INTERNALS_METADATA_LOCATION_TEST + +#include + +#include "loot/metadata/location.h" + +namespace loot { +namespace test { +TEST(Location, defaultConstructorShouldInitialiseEmptyStrings) { + Location location; + + EXPECT_EQ("", location.GetURL()); + EXPECT_EQ("", location.GetName()); +} + +TEST(Location, stringsConstructorShouldStoreGivenStrings) { + Location location("http://www.example.com", "example"); + + EXPECT_EQ("http://www.example.com", location.GetURL()); + EXPECT_EQ("example", location.GetName()); +} + +TEST(Location, equalityShouldBeCaseSensitiveOnUrlAndName) { + Location location1("http://www.example.com", "example"); + Location location2("http://www.example.com", "example"); + + EXPECT_TRUE(location1 == location2); + + location1 = Location("http://www.example.com", "example"); + location2 = Location("HTTP://WWW.EXAMPLE.COM", "example"); + + EXPECT_FALSE(location1 == location2); + + location1 = Location("http://www.example.com", "example"); + location2 = Location("http://www.example.com", "Example"); + + EXPECT_FALSE(location1 == location2); + + location1 = Location("http://www.example1.com", "example"); + location2 = Location("http://www.example2.com", "example"); + + EXPECT_FALSE(location1 == location2); + + location1 = Location("http://www.example.com", "example1"); + location2 = Location("http://www.example.com", "example2"); + + EXPECT_FALSE(location1 == location2); +} + +TEST(Location, inequalityShouldBeTheInverseOfEquality) { + Location location1("http://www.example.com", "example"); + Location location2("http://www.example.com", "example"); + + EXPECT_FALSE(location1 != location2); + + location1 = Location("http://www.example.com", "example"); + location2 = Location("HTTP://WWW.EXAMPLE.COM", "example"); + + EXPECT_TRUE(location1 != location2); + + location1 = Location("http://www.example.com", "example"); + location2 = Location("http://www.example.com", "Example"); + + EXPECT_TRUE(location1 != location2); + + location1 = Location("http://www.example1.com", "example"); + location2 = Location("http://www.example2.com", "example"); + + EXPECT_TRUE(location1 != location2); + + location1 = Location("http://www.example.com", "example1"); + location2 = Location("http://www.example.com", "example2"); + + EXPECT_TRUE(location1 != location2); +} + +TEST( + Location, + lessThanOperatorShouldUseCaseSensitiveLexicographicalComparisonForNameAndUrl) { + Location location1("http://www.example.com", "example"); + Location location2("http://www.example.com", "example"); + + EXPECT_FALSE(location1 < location2); + EXPECT_FALSE(location2 < location1); + + location1 = Location("http://www.example.com"); + location2 = Location("HTTP://WWW.EXAMPLE.COM"); + + EXPECT_FALSE(location1 < location2); + EXPECT_TRUE(location2 < location1); + + location1 = Location("http://www.example.com", "example"); + location2 = Location("http://www.example.com", "Example"); + + EXPECT_FALSE(location1 < location2); + EXPECT_TRUE(location2 < location1); + + location1 = Location("http://www.example1.com"); + location2 = Location("http://www.example2.com"); + + EXPECT_TRUE(location1 < location2); + EXPECT_FALSE(location2 < location1); + + location1 = Location("http://www.example.com", "example1"); + location2 = Location("http://www.example.com", "example2"); + + EXPECT_FALSE(location2 < location1); + EXPECT_TRUE(location1 < location2); +} + +TEST(Location, + greaterThanOperatorShouldReturnTrueIfTheSecondLocationIsLessThanTheFirst) { + Location location1("http://www.example.com", "example"); + Location location2("http://www.example.com", "example"); + + EXPECT_FALSE(location1 > location2); + EXPECT_FALSE(location2 > location1); + + location1 = Location("http://www.example.com"); + location2 = Location("HTTP://WWW.EXAMPLE.COM"); + + EXPECT_TRUE(location1 > location2); + EXPECT_FALSE(location2 > location1); + + location1 = Location("http://www.example.com", "example"); + location2 = Location("http://www.example.com", "Example"); + + EXPECT_TRUE(location1 > location2); + EXPECT_FALSE(location2 > location1); + + location1 = Location("http://www.example1.com"); + location2 = Location("http://www.example2.com"); + + EXPECT_FALSE(location1 > location2); + EXPECT_TRUE(location2 > location1); + + location1 = Location("http://www.example.com", "example1"); + location2 = Location("http://www.example.com", "example2"); + + EXPECT_TRUE(location2 > location1); + EXPECT_FALSE(location1 > location2); +} + +TEST( + Location, + lessThanOrEqualOperatorShouldReturnTrueIfTheFirstLocationIsNotGreaterThanTheSecond) { + Location location1("http://www.example.com", "example"); + Location location2("http://www.example.com", "example"); + + EXPECT_TRUE(location1 <= location2); + EXPECT_TRUE(location2 <= location1); + + location1 = Location("http://www.example.com"); + location2 = Location("HTTP://WWW.EXAMPLE.COM"); + + EXPECT_FALSE(location1 <= location2); + EXPECT_TRUE(location2 <= location1); + + location1 = Location("http://www.example.com", "example"); + location2 = Location("http://www.example.com", "Example"); + + EXPECT_FALSE(location1 <= location2); + EXPECT_TRUE(location2 <= location1); + + location1 = Location("http://www.example1.com"); + location2 = Location("http://www.example2.com"); + + EXPECT_TRUE(location1 <= location2); + EXPECT_FALSE(location2 <= location1); + + location1 = Location("http://www.example.com", "example1"); + location2 = Location("http://www.example.com", "example2"); + + EXPECT_FALSE(location2 <= location1); + EXPECT_TRUE(location1 <= location2); +} + +TEST( + Location, + greaterThanOrEqualToOperatorShouldReturnTrueIfTheFirstLocationIsNotLessThanTheSecond) { + Location location1("http://www.example.com", "example"); + Location location2("http://www.example.com", "example"); + + EXPECT_TRUE(location1 >= location2); + EXPECT_TRUE(location2 >= location1); + + location1 = Location("http://www.example.com"); + location2 = Location("HTTP://WWW.EXAMPLE.COM"); + + EXPECT_TRUE(location1 >= location2); + EXPECT_FALSE(location2 >= location1); + + location1 = Location("http://www.example.com", "example"); + location2 = Location("http://www.example.com", "Example"); + + EXPECT_TRUE(location1 >= location2); + EXPECT_FALSE(location2 >= location1); + + location1 = Location("http://www.example1.com"); + location2 = Location("http://www.example2.com"); + + EXPECT_FALSE(location1 >= location2); + EXPECT_TRUE(location2 >= location1); + + location1 = Location("http://www.example.com", "example1"); + location2 = Location("http://www.example.com", "example2"); + + EXPECT_TRUE(location2 >= location1); + EXPECT_FALSE(location1 >= location2); +} +} +} + +#endif diff --git a/cxx/src/tests/api/internals/metadata/message_content_test.h b/cxx/src/tests/api/internals/metadata/message_content_test.h new file mode 100644 index 00000000..f5f20cfb --- /dev/null +++ b/cxx/src/tests/api/internals/metadata/message_content_test.h @@ -0,0 +1,335 @@ +/* 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 +. +*/ + +#ifndef LOOT_TESTS_API_INTERNALS_METADATA_MESSAGE_CONTENT_TEST +#define LOOT_TESTS_API_INTERNALS_METADATA_MESSAGE_CONTENT_TEST + +#include + +#include "loot/metadata/message_content.h" + +namespace loot { +namespace test { +const std::string french = "fr"; + +TEST(MessageContent, defaultConstructorShouldSetEmptyEnglishLanguageString) { + MessageContent content; + + EXPECT_TRUE(content.GetText().empty()); + EXPECT_EQ(MessageContent::DEFAULT_LANGUAGE, content.GetLanguage()); +} + +TEST(MessageContent, contentConstructorShouldStoreGivenStringAndLanguage) { + MessageContent content("content", french); + + EXPECT_EQ("content", content.GetText()); + EXPECT_EQ(french, content.GetLanguage()); +} + +TEST(MessageContent, + equalityShouldRequireCaseSensitiveEqualityOnTextAndLanguage) { + MessageContent content1("content", "fr"); + MessageContent content2("content", "fr"); + + EXPECT_TRUE(content1 == content2); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("Content", "fr"); + + EXPECT_FALSE(content1 == content2); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "Fr"); + + EXPECT_FALSE(content1 == content2); + + content1 = MessageContent("content1", "fr"); + content2 = MessageContent("content2", "fr"); + + EXPECT_FALSE(content1 == content2); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "de"); + + EXPECT_FALSE(content1 == content2); +} + +TEST(MessageContent, inequalityShouldBeTheInverseOfEquality) { + MessageContent content1("content", "fr"); + MessageContent content2("content", "fr"); + + EXPECT_FALSE(content1 != content2); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("Content", "fr"); + + EXPECT_TRUE(content1 != content2); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "Fr"); + + EXPECT_TRUE(content1 != content2); + + content1 = MessageContent("content1", "fr"); + content2 = MessageContent("content2", "fr"); + + EXPECT_TRUE(content1 != content2); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "de"); + + EXPECT_TRUE(content1 != content2); +} + +TEST( + MessageContent, + lessThanOperatorShouldUseCaseSensitiveLexicographicalComparisonForTextAndLanguage) { + MessageContent content1("content", "fr"); + MessageContent content2("content", "fr"); + + EXPECT_FALSE(content1 < content2); + EXPECT_FALSE(content2 < content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("Content", "fr"); + + EXPECT_FALSE(content1 < content2); + EXPECT_TRUE(content2 < content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "Fr"); + + EXPECT_TRUE(content2 < content1); + EXPECT_FALSE(content1 < content2); + + content1 = MessageContent("content1", "fr"); + content2 = MessageContent("content2", "fr"); + + EXPECT_TRUE(content1 < content2); + EXPECT_FALSE(content2 < content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "de"); + + EXPECT_TRUE(content2 < content1); + EXPECT_FALSE(content1 < content2); +} + +TEST( + MessageContent, + greaterThanOperatorShouldReturnTrueIfTheSecondMessageContentIsLessThanTheFirst) { + MessageContent content1("content", "fr"); + MessageContent content2("content", "fr"); + + EXPECT_FALSE(content1 > content2); + EXPECT_FALSE(content2 > content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("Content", "fr"); + + EXPECT_TRUE(content1 > content2); + EXPECT_FALSE(content2 > content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "Fr"); + + EXPECT_FALSE(content2 > content1); + EXPECT_TRUE(content1 > content2); + + content1 = MessageContent("content1", "fr"); + content2 = MessageContent("content2", "fr"); + + EXPECT_FALSE(content1 > content2); + EXPECT_TRUE(content2 > content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "de"); + + EXPECT_FALSE(content2 > content1); + EXPECT_TRUE(content1 > content2); +} + +TEST( + MessageContent, + lessThanOrEqualOperatorShouldReturnTrueIfTheFirstMessageContentIsNotGreaterThanTheSecond) { + MessageContent content1("content", "fr"); + MessageContent content2("content", "fr"); + + EXPECT_TRUE(content1 <= content2); + EXPECT_TRUE(content2 <= content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("Content", "fr"); + + EXPECT_FALSE(content1 <= content2); + EXPECT_TRUE(content2 <= content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "Fr"); + + EXPECT_TRUE(content2 <= content1); + EXPECT_FALSE(content1 <= content2); + + content1 = MessageContent("content1", "fr"); + content2 = MessageContent("content2", "fr"); + + EXPECT_TRUE(content1 <= content2); + EXPECT_FALSE(content2 <= content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "de"); + + EXPECT_TRUE(content2 <= content1); + EXPECT_FALSE(content1 <= content2); +} + +TEST( + MessageContent, + greaterThanOrEqualToOperatorShouldReturnTrueIfTheFirstMessageContentIsNotLessThanTheSecond) { + MessageContent content1("content", "fr"); + MessageContent content2("content", "fr"); + + EXPECT_TRUE(content1 >= content2); + EXPECT_TRUE(content2 >= content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("Content", "fr"); + + EXPECT_TRUE(content1 >= content2); + EXPECT_FALSE(content2 >= content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "Fr"); + + EXPECT_FALSE(content2 >= content1); + EXPECT_TRUE(content1 >= content2); + + content1 = MessageContent("content1", "fr"); + content2 = MessageContent("content2", "fr"); + + EXPECT_FALSE(content1 >= content2); + EXPECT_TRUE(content2 >= content1); + + content1 = MessageContent("content", "fr"); + content2 = MessageContent("content", "de"); + + EXPECT_FALSE(content2 >= content1); + EXPECT_TRUE(content1 >= content2); +} + +TEST(SelectMessageContent, shouldReturnANulloptIfTheVectorIsEmpty) { + auto content = SelectMessageContent(std::vector(), "fr"); + + EXPECT_FALSE(content.has_value()); +} + +TEST(SelectMessageContent, shouldReturnTheOnlyElementOfASingleElementVector) { + MessageContent content("test", "de"); + auto chosen = SelectMessageContent({MessageContent("test", "de")}, "fr"); + + EXPECT_EQ(content, chosen); +} + +TEST( + SelectMessageContent, + shouldReturnAnEmptyEnglishMessageIfTheVectorHasNoEnglishOrMatchingLanguageContentWithTwoOrMoreElements) { + auto contents = {MessageContent("test1", "de"), + MessageContent("test2", "fr")}; + auto content = SelectMessageContent(contents, "pt"); + + EXPECT_FALSE(content.has_value()); +} + +TEST(SelectMessageContent, + shouldReturnElementWithExactlyMatchingLocaleCodeIfPresent) { + auto contents = {MessageContent("test1", "en"), + MessageContent("test2", "de"), + MessageContent("test3", "pt"), + MessageContent("test4", "pt_PT"), + MessageContent("test5", "pt_BR")}; + auto content = SelectMessageContent(contents, "pt_BR"); + + EXPECT_TRUE(content.has_value()); + EXPECT_EQ("pt_BR", content.value().GetLanguage()); + EXPECT_EQ("test5", content.value().GetText()); +} + +TEST( + SelectMessageContent, + shouldReturnElementWithMatchingLanguageCodeIfExactlyMatchingLocaleCodeIsNotPresent) { + auto contents = {MessageContent("test1", "en"), + MessageContent("test2", "de"), + MessageContent("test3", "pt_PT"), + MessageContent("test4", "pt")}; + auto content = SelectMessageContent(contents, "pt_BR"); + + EXPECT_TRUE(content.has_value()); + EXPECT_EQ("pt", content.value().GetLanguage()); + EXPECT_EQ("test4", content.value().GetText()); +} + +TEST(SelectMessageContent, + shouldReturnElementWithEnLanguageCodeIfNoMatchingLanguageCodeIsPresent) { + auto contents = {MessageContent("test1", "en"), + MessageContent("test2", "de"), + MessageContent("test3", "pt_PT")}; + auto content = SelectMessageContent(contents, "pt_BR"); + + EXPECT_TRUE(content.has_value()); + EXPECT_EQ("en", content.value().GetLanguage()); + EXPECT_EQ("test1", content.value().GetText()); +} + +TEST(SelectMessageContent, + shouldReturnElementWithExactlyMatchingLanguageCodeIfLanguageCodeIsGiven) { + auto contents = { + MessageContent("test1", "en"), + MessageContent("test2", "de"), + MessageContent("test3", "pt_BR"), + MessageContent("test4", "pt"), + }; + auto content = SelectMessageContent(contents, "pt"); + + EXPECT_TRUE(content.has_value()); + EXPECT_EQ("pt", content.value().GetLanguage()); + EXPECT_EQ("test4", content.value().GetText()); +} + +TEST( + SelectMessageContent, + shouldReturnFirstElementWithMatchingLanguageCodeIfLanguageCodeIsGivenAndNoExactMatchIsPresent) { + auto contents = {MessageContent("test1", "en"), + MessageContent("test2", "de"), + MessageContent("test3", "pt_PT"), + MessageContent("test4", "pt_BR")}; + auto content = SelectMessageContent(contents, "pt"); + + EXPECT_TRUE(content.has_value()); + EXPECT_EQ("pt_PT", content.value().GetLanguage()); + EXPECT_EQ("test3", content.value().GetText()); +} +} +} + +#endif diff --git a/cxx/src/tests/api/internals/metadata/message_test.h b/cxx/src/tests/api/internals/metadata/message_test.h new file mode 100644 index 00000000..8939440f --- /dev/null +++ b/cxx/src/tests/api/internals/metadata/message_test.h @@ -0,0 +1,347 @@ +/* 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 +. +*/ + +#ifndef LOOT_TESTS_API_INTERNALS_METADATA_MESSAGE_TEST +#define LOOT_TESTS_API_INTERNALS_METADATA_MESSAGE_TEST + +#include "loot/metadata/message.h" +#include "tests/common_game_test_fixture.h" + +namespace loot { +namespace test { +class MessageTest : public CommonGameTestFixture { +protected: + MessageTest() : CommonGameTestFixture(GameType::tes4) {} + typedef std::vector MessageContents; +}; + +TEST_F(MessageTest, defaultConstructorShouldCreateNoteWithNoContent) { + Message message; + EXPECT_EQ(MessageType::say, message.GetType()); + EXPECT_EQ(MessageContents(), message.GetContent()); +} + +TEST_F(MessageTest, + scalarContentConstructorShouldCreateAMessageWithASingleContentString) { + MessageContent content = MessageContent("content1"); + Message message(MessageType::warn, content.GetText(), "condition1"); + + EXPECT_EQ(MessageType::warn, message.GetType()); + EXPECT_EQ(MessageContents({content}), message.GetContent()); + EXPECT_EQ("condition1", message.GetCondition()); +} + +TEST_F(MessageTest, + vectorContentConstructorShouldCreateAMessageWithGivenContentStrings) { + MessageContents contents({ + MessageContent("content1"), + MessageContent("content2", french), + }); + Message message(MessageType::error, contents, "condition1"); + + EXPECT_EQ(MessageType::error, message.GetType()); + EXPECT_EQ(contents, message.GetContent()); + EXPECT_EQ("condition1", message.GetCondition()); +} + +TEST_F( + MessageTest, + vectorContentConstructorShouldThrowIfMultipleContentStringsAreGivenAndNoneAreEnglish) { + MessageContents contents({ + MessageContent("content1", german), + MessageContent("content2", french), + }); + EXPECT_THROW(Message(MessageType::error, contents, "condition1"), + std::invalid_argument); +} + +TEST_F(MessageTest, equalityShouldRequireEqualMessageTypes) { + Message message1(MessageType::say, "content"); + Message message2(MessageType::say, "content"); + + EXPECT_TRUE(message1 == message2); + + message1 = Message(MessageType::say, "content"); + message2 = Message(MessageType::warn, "content"); + + EXPECT_FALSE(message1 == message2); +} + +TEST_F(MessageTest, equalityShouldRequireCaseSensitiveEqualityOnCondition) { + Message message1(MessageType::say, "content", "condition"); + Message message2(MessageType::say, "content", "condition"); + + EXPECT_TRUE(message1 == message2); + + message1 = Message(MessageType::say, "content", "condition"); + message2 = Message(MessageType::say, "content", "Condition"); + + EXPECT_FALSE(message1 == message2); + + message1 = Message(MessageType::say, "content", "condition1"); + message2 = Message(MessageType::say, "content", "condition2"); + + EXPECT_FALSE(message1 == message2); +} + +TEST_F(MessageTest, equalityShouldRequireEqualContent) { + Message message1(MessageType::say, "content"); + Message message2(MessageType::say, "content"); + + EXPECT_TRUE(message1 == message2); + + message1 = Message(MessageType::say, "content1"); + message2 = Message(MessageType::say, "content2"); + + EXPECT_FALSE(message1 == message2); +} + +TEST_F(MessageTest, inequalityShouldBeTheInverseOfEquality) { + Message message1(MessageType::say, "content"); + Message message2(MessageType::say, "content"); + + EXPECT_FALSE(message1 != message2); + + message1 = Message(MessageType::say, "content"); + message2 = Message(MessageType::warn, "content"); + + EXPECT_TRUE(message1 != message2); + + message1 = Message(MessageType::say, "content", "condition"); + message2 = Message(MessageType::say, "content", "condition"); + + EXPECT_FALSE(message1 != message2); + + message1 = Message(MessageType::say, "content", "condition"); + message2 = Message(MessageType::say, "content", "Condition"); + + EXPECT_TRUE(message1 != message2); + + message1 = Message(MessageType::say, "content", "condition1"); + message2 = Message(MessageType::say, "content", "condition2"); + + EXPECT_TRUE(message1 != message2); + + message1 = Message(MessageType::say, "content"); + message2 = Message(MessageType::say, "content"); + + EXPECT_FALSE(message1 != message2); + + message1 = Message(MessageType::say, "content1"); + message2 = Message(MessageType::say, "content2"); + + EXPECT_TRUE(message1 != message2); +} + +TEST_F(MessageTest, lessThanOperatorShouldCompareMessageTypes) { + Message message1(MessageType::say, "content"); + Message message2(MessageType::say, "content"); + + EXPECT_FALSE(message1 < message2); + EXPECT_FALSE(message2 < message1); + + message1 = Message(MessageType::say, "content"); + message2 = Message(MessageType::warn, "content"); + + EXPECT_TRUE(message1 < message2); + EXPECT_FALSE(message2 < message1); +} + +TEST_F(MessageTest, lessThanOperatorShouldCompareContent) { + Message message1(MessageType::say, "content"); + Message message2(MessageType::say, "content"); + + EXPECT_FALSE(message1 < message2); + EXPECT_FALSE(message2 < message1); + + message1 = Message(MessageType::say, "content1"); + message2 = Message(MessageType::say, "content2"); + + EXPECT_TRUE(message1 < message2); + EXPECT_FALSE(message2 < message1); +} + +TEST_F( + MessageTest, + lessThanOperatorShouldUseCaseSensitiveLexicographicalComparisonForConditions) { + Message message1(MessageType::say, "content", "condition"); + Message message2(MessageType::say, "content", "condition"); + + EXPECT_FALSE(message1 < message2); + EXPECT_FALSE(message2 < message1); + + message1 = Message(MessageType::say, "content", "condition"); + message2 = Message(MessageType::say, "content", "Condition"); + + EXPECT_TRUE(message2 < message1); + EXPECT_FALSE(message1 < message2); + + message1 = Message(MessageType::say, "content", "condition1"); + message2 = Message(MessageType::say, "content", "condition2"); + + EXPECT_TRUE(message1 < message2); + EXPECT_FALSE(message2 < message1); +} + +TEST_F( + MessageTest, + greaterThanOperatorShouldReturnTrueIfTheSecondMessageIsLessThanTheFirst) { + Message message1(MessageType::say, "content"); + Message message2(MessageType::say, "content"); + + EXPECT_FALSE(message1 > message2); + EXPECT_FALSE(message2 > message1); + + message1 = Message(MessageType::say, "content"); + message2 = Message(MessageType::warn, "content"); + + EXPECT_FALSE(message1 > message2); + EXPECT_TRUE(message2 > message1); + + message1 = Message(MessageType::say, "content"); + message2 = Message(MessageType::say, "content"); + + EXPECT_FALSE(message1 > message2); + EXPECT_FALSE(message2 > message1); + + message1 = Message(MessageType::say, "content1"); + message2 = Message(MessageType::say, "content2"); + + EXPECT_FALSE(message1 > message2); + EXPECT_TRUE(message2 > message1); + + message1 = Message(MessageType::say, "content", "condition"); + message2 = Message(MessageType::say, "content", "condition"); + + EXPECT_FALSE(message1 > message2); + EXPECT_FALSE(message2 > message1); + + message1 = Message(MessageType::say, "content", "condition"); + message2 = Message(MessageType::say, "content", "Condition"); + + EXPECT_FALSE(message2 > message1); + EXPECT_TRUE(message1 > message2); + + message1 = Message(MessageType::say, "content", "condition1"); + message2 = Message(MessageType::say, "content", "condition2"); + + EXPECT_FALSE(message1 > message2); + EXPECT_TRUE(message2 > message1); +} + +TEST_F( + MessageTest, + lessThanOrEqualOperatorShouldReturnTrueIfTheFirstMessageIsNotGreaterThanTheSecond) { + Message message1(MessageType::say, "content"); + Message message2(MessageType::say, "content"); + + EXPECT_TRUE(message1 <= message2); + EXPECT_TRUE(message2 <= message1); + + message1 = Message(MessageType::say, "content"); + message2 = Message(MessageType::warn, "content"); + + EXPECT_TRUE(message1 <= message2); + EXPECT_FALSE(message2 <= message1); + + message1 = Message(MessageType::say, "content"); + message2 = Message(MessageType::say, "content"); + + EXPECT_TRUE(message1 <= message2); + EXPECT_TRUE(message2 <= message1); + + message1 = Message(MessageType::say, "content1"); + message2 = Message(MessageType::say, "content2"); + + EXPECT_TRUE(message1 <= message2); + EXPECT_FALSE(message2 <= message1); + + message1 = Message(MessageType::say, "content", "condition"); + message2 = Message(MessageType::say, "content", "condition"); + + EXPECT_TRUE(message1 <= message2); + EXPECT_TRUE(message2 <= message1); + + message1 = Message(MessageType::say, "content", "condition"); + message2 = Message(MessageType::say, "content", "Condition"); + + EXPECT_TRUE(message2 <= message1); + EXPECT_FALSE(message1 <= message2); + + message1 = Message(MessageType::say, "content", "condition1"); + message2 = Message(MessageType::say, "content", "condition2"); + + EXPECT_TRUE(message1 <= message2); + EXPECT_FALSE(message2 <= message1); +} + +TEST_F( + MessageTest, + greaterThanOrEqualToOperatorShouldReturnTrueIfTheFirstMessageIsNotLessThanTheSecond) { + Message message1(MessageType::say, "content"); + Message message2(MessageType::say, "content"); + + EXPECT_TRUE(message1 >= message2); + EXPECT_TRUE(message2 >= message1); + + message1 = Message(MessageType::say, "content"); + message2 = Message(MessageType::warn, "content"); + + EXPECT_FALSE(message1 >= message2); + EXPECT_TRUE(message2 >= message1); + + message1 = Message(MessageType::say, "content"); + message2 = Message(MessageType::say, "content"); + + EXPECT_TRUE(message1 >= message2); + EXPECT_TRUE(message2 >= message1); + + message1 = Message(MessageType::say, "content1"); + message2 = Message(MessageType::say, "content2"); + + EXPECT_FALSE(message1 >= message2); + EXPECT_TRUE(message2 >= message1); + + message1 = Message(MessageType::say, "content", "condition"); + message2 = Message(MessageType::say, "content", "condition"); + + EXPECT_TRUE(message1 >= message2); + EXPECT_TRUE(message2 >= message1); + + message1 = Message(MessageType::say, "content", "condition"); + message2 = Message(MessageType::say, "content", "Condition"); + + EXPECT_FALSE(message2 >= message1); + EXPECT_TRUE(message1 >= message2); + + message1 = Message(MessageType::say, "content", "condition1"); + message2 = Message(MessageType::say, "content", "condition2"); + + EXPECT_FALSE(message1 >= message2); + EXPECT_TRUE(message2 >= message1); +} +} +} + +#endif diff --git a/cxx/src/tests/api/internals/metadata/plugin_cleaning_data_test.h b/cxx/src/tests/api/internals/metadata/plugin_cleaning_data_test.h new file mode 100644 index 00000000..890e5cc7 --- /dev/null +++ b/cxx/src/tests/api/internals/metadata/plugin_cleaning_data_test.h @@ -0,0 +1,315 @@ +/* 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 +. +*/ + +#ifndef LOOT_TESTS_API_INTERNALS_METADATA_PLUGIN_CLEANING_DATA +#define LOOT_TESTS_API_INTERNALS_METADATA_PLUGIN_CLEANING_DATA + +#include "loot/metadata/plugin_cleaning_data.h" +#include "tests/common_game_test_fixture.h" + +namespace loot { +namespace test { +class PluginCleaningDataTest : public CommonGameTestFixture { +protected: + PluginCleaningDataTest() : + CommonGameTestFixture(GameType::tes4), + info_(std::vector({ + MessageContent("info"), + })) {} + + const std::vector info_; +}; + +TEST_F(PluginCleaningDataTest, + defaultConstructorShouldLeaveAllCountsAtZeroAndTheUtilityStringEmpty) { + PluginCleaningData info; + EXPECT_EQ(0u, info.GetCRC()); + EXPECT_EQ(0u, info.GetITMCount()); + EXPECT_EQ(0u, info.GetDeletedReferenceCount()); + EXPECT_EQ(0u, info.GetDeletedNavmeshCount()); + EXPECT_TRUE(info.GetCleaningUtility().empty()); + EXPECT_TRUE(info.GetDetail().empty()); +} + +TEST_F(PluginCleaningDataTest, contentConstructorShouldStoreAllGivenData) { + PluginCleaningData info(0x12345678, "cleaner", info_, 2, 10, 30); + EXPECT_EQ(0x12345678u, info.GetCRC()); + EXPECT_EQ(2u, info.GetITMCount()); + EXPECT_EQ(10u, info.GetDeletedReferenceCount()); + EXPECT_EQ(30u, info.GetDeletedNavmeshCount()); + EXPECT_EQ("cleaner", info.GetCleaningUtility()); + EXPECT_EQ(info_, info.GetDetail()); +} + +TEST_F(PluginCleaningDataTest, equalityShouldCheckEqualityOfAllFields) { + PluginCleaningData info1(0x12345678, "cleaner", info_, 2, 10, 30); + PluginCleaningData info2(0x12345678, "cleaner", info_, 2, 10, 30); + EXPECT_TRUE(info1 == info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x87654321, "cleaner", info_, 2, 10, 30); + EXPECT_FALSE(info1 == info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "Cleaner", info_, 2, 10, 30); + EXPECT_FALSE(info1 == info2); + + info1 = PluginCleaningData(0x12345678, "cleaner1", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner2", info_, 2, 10, 30); + EXPECT_FALSE(info1 == info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData( + 0x12345678, "cleaner", std::vector(), 2, 10, 30); + EXPECT_FALSE(info1 == info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 4, 10, 30); + EXPECT_FALSE(info1 == info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 20, 30); + EXPECT_FALSE(info1 == info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 60); + EXPECT_FALSE(info1 == info2); +} + +TEST_F(PluginCleaningDataTest, inequalityShouldBeTheInverseOfEquality) { + PluginCleaningData info1(0x12345678, "cleaner", info_, 2, 10, 30); + PluginCleaningData info2(0x12345678, "cleaner", info_, 2, 10, 30); + EXPECT_FALSE(info1 != info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x87654321, "cleaner", info_, 2, 10, 30); + EXPECT_TRUE(info1 != info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "Cleaner", info_, 2, 10, 30); + EXPECT_TRUE(info1 != info2); + + info1 = PluginCleaningData(0x12345678, "cleaner1", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner2", info_, 2, 10, 30); + EXPECT_TRUE(info1 != info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData( + 0x12345678, "cleaner", std::vector(), 2, 10, 30); + EXPECT_TRUE(info1 != info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 4, 10, 30); + EXPECT_TRUE(info1 != info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 20, 30); + EXPECT_TRUE(info1 != info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 60); + EXPECT_TRUE(info1 != info2); +} + +TEST_F(PluginCleaningDataTest, lessThanOperatorShouldCompareAllFields) { + PluginCleaningData info1(0x12345678, "cleaner", info_, 2, 10, 30); + PluginCleaningData info2(0x12345678, "cleaner", info_, 2, 10, 30); + EXPECT_FALSE(info1 < info2); + EXPECT_FALSE(info2 < info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x87654321, "cleaner", info_, 2, 10, 30); + EXPECT_TRUE(info1 < info2); + EXPECT_FALSE(info2 < info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "Cleaner", info_, 2, 10, 30); + EXPECT_TRUE(info2 < info1); + EXPECT_FALSE(info1 < info2); + + info1 = PluginCleaningData(0x12345678, "cleaner1", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner2", info_, 2, 10, 30); + EXPECT_TRUE(info1 < info2); + EXPECT_FALSE(info2 < info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData( + 0x12345678, "cleaner", std::vector(), 2, 10, 30); + EXPECT_TRUE(info2 < info1); + EXPECT_FALSE(info1 < info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 4, 10, 30); + EXPECT_TRUE(info1 < info2); + EXPECT_FALSE(info2 < info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 20, 30); + EXPECT_TRUE(info1 < info2); + EXPECT_FALSE(info2 < info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 60); + EXPECT_TRUE(info1 < info2); + EXPECT_FALSE(info2 < info1); +} + +TEST_F( + PluginCleaningDataTest, + greaterThanOperatorShouldReturnTrueIfTheSecondPluginCleaningDataIsLessThanTheFirst) { + PluginCleaningData info1(0x12345678, "cleaner", info_, 2, 10, 30); + PluginCleaningData info2(0x12345678, "cleaner", info_, 2, 10, 30); + EXPECT_FALSE(info1 > info2); + EXPECT_FALSE(info2 > info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x87654321, "cleaner", info_, 2, 10, 30); + EXPECT_FALSE(info1 > info2); + EXPECT_TRUE(info2 > info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "Cleaner", info_, 2, 10, 30); + EXPECT_FALSE(info2 > info1); + EXPECT_TRUE(info1 > info2); + + info1 = PluginCleaningData(0x12345678, "cleaner1", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner2", info_, 2, 10, 30); + EXPECT_FALSE(info1 > info2); + EXPECT_TRUE(info2 > info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData( + 0x12345678, "cleaner", std::vector(), 2, 10, 30); + EXPECT_FALSE(info2 > info1); + EXPECT_TRUE(info1 > info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 4, 10, 30); + EXPECT_FALSE(info1 > info2); + EXPECT_TRUE(info2 > info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 20, 30); + EXPECT_FALSE(info1 > info2); + EXPECT_TRUE(info2 > info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 60); + EXPECT_FALSE(info1 > info2); + EXPECT_TRUE(info2 > info1); +} + +TEST_F( + PluginCleaningDataTest, + lessThanOrEqualOperatorShouldReturnTrueIfTheFirstPluginCleaningDataIsNotGreaterThanTheSecond) { + PluginCleaningData info1(0x12345678, "cleaner", info_, 2, 10, 30); + PluginCleaningData info2(0x12345678, "cleaner", info_, 2, 10, 30); + EXPECT_TRUE(info1 <= info2); + EXPECT_TRUE(info2 <= info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x87654321, "cleaner", info_, 2, 10, 30); + EXPECT_TRUE(info1 < info2); + EXPECT_FALSE(info2 < info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "Cleaner", info_, 2, 10, 30); + EXPECT_TRUE(info2 < info1); + EXPECT_FALSE(info1 < info2); + + info1 = PluginCleaningData(0x12345678, "cleaner1", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner2", info_, 2, 10, 30); + EXPECT_TRUE(info1 < info2); + EXPECT_FALSE(info2 < info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData( + 0x12345678, "cleaner", std::vector(), 2, 10, 30); + EXPECT_TRUE(info2 < info1); + EXPECT_FALSE(info1 < info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 4, 10, 30); + EXPECT_TRUE(info1 < info2); + EXPECT_FALSE(info2 < info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 20, 30); + EXPECT_TRUE(info1 < info2); + EXPECT_FALSE(info2 < info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 60); + EXPECT_TRUE(info1 < info2); + EXPECT_FALSE(info2 < info1); +} + +TEST_F( + PluginCleaningDataTest, + greaterThanOrEqualToOperatorShouldReturnTrueIfTheFirstPluginCleaningDataIsNotLessThanTheSecond) { + PluginCleaningData info1(0x12345678, "cleaner", info_, 2, 10, 30); + PluginCleaningData info2(0x12345678, "cleaner", info_, 2, 10, 30); + EXPECT_TRUE(info1 >= info2); + EXPECT_TRUE(info2 >= info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x87654321, "cleaner", info_, 2, 10, 30); + EXPECT_FALSE(info1 > info2); + EXPECT_TRUE(info2 > info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "Cleaner", info_, 2, 10, 30); + EXPECT_FALSE(info2 > info1); + EXPECT_TRUE(info1 > info2); + + info1 = PluginCleaningData(0x12345678, "cleaner1", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner2", info_, 2, 10, 30); + EXPECT_FALSE(info1 > info2); + EXPECT_TRUE(info2 > info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData( + 0x12345678, "cleaner", std::vector(), 2, 10, 30); + EXPECT_FALSE(info2 > info1); + EXPECT_TRUE(info1 > info2); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 4, 10, 30); + EXPECT_FALSE(info1 > info2); + EXPECT_TRUE(info2 > info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 20, 30); + EXPECT_FALSE(info1 > info2); + EXPECT_TRUE(info2 > info1); + + info1 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 30); + info2 = PluginCleaningData(0x12345678, "cleaner", info_, 2, 10, 60); + EXPECT_FALSE(info1 > info2); + EXPECT_TRUE(info2 > info1); +} +} +} + +#endif diff --git a/cxx/src/tests/api/internals/metadata/plugin_metadata_test.h b/cxx/src/tests/api/internals/metadata/plugin_metadata_test.h new file mode 100644 index 00000000..4629c3de --- /dev/null +++ b/cxx/src/tests/api/internals/metadata/plugin_metadata_test.h @@ -0,0 +1,397 @@ +/* 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 +. +*/ + +#ifndef LOOT_TESTS_API_INTERNALS_METADATA_PLUGIN_METADATA_TEST +#define LOOT_TESTS_API_INTERNALS_METADATA_PLUGIN_METADATA_TEST + +#include "loot/metadata/plugin_metadata.h" +#include "tests/common_game_test_fixture.h" + +namespace loot { +namespace test { +class PluginMetadataTest : public CommonGameTestFixture { +protected: + PluginMetadataTest() : + CommonGameTestFixture(GameType::tes5), + info_(std::vector({ + MessageContent("info"), + })) {} + + const std::vector info_; +}; + +TEST_F( + PluginMetadataTest, + defaultConstructorShouldLeaveNameEmptyAndEnableMetadataAndLeaveGroupUnset) { + PluginMetadata plugin; + + EXPECT_TRUE(plugin.GetName().empty()); + EXPECT_FALSE(plugin.GetGroup()); +} + +TEST_F( + PluginMetadataTest, + stringConstructorShouldSetNameToGivenStringAndEnableMetadataAndLeaveGroupUnset) { + PluginMetadata plugin(blankEsm); + + EXPECT_EQ(blankEsm, plugin.GetName()); + EXPECT_FALSE(plugin.GetGroup()); +} + +TEST_F(PluginMetadataTest, + nameMatchesShouldUseCaseInsensitiveNameComparisonForNonRegexNames) { + PluginMetadata plugin(blankEsm); + + EXPECT_TRUE(plugin.NameMatches("blank.esm")); + EXPECT_FALSE(plugin.NameMatches(blankDifferentEsm)); +} + +TEST_F(PluginMetadataTest, + nameMatchesShouldTreatGivenPluginNameStringsAsLiterals) { + PluginMetadata plugin(blankEsm); + std::string regex = "blan.\\.esm"; + + EXPECT_FALSE(plugin.NameMatches(regex)); +} + +TEST_F(PluginMetadataTest, + nameMatchesShouldUseCaseInsensitiveRegexMatchingForARegexName) { + PluginMetadata plugin("Blan.\\.esm"); + + EXPECT_TRUE(plugin.NameMatches("blank.esm")); + EXPECT_FALSE(plugin.NameMatches(blankDifferentEsm)); +} + +TEST_F(PluginMetadataTest, mergeMetadataShouldNotChangeName) { + PluginMetadata plugin1(blankEsm); + PluginMetadata plugin2(blankDifferentEsm); + + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ(blankEsm, plugin1.GetName()); +} + +TEST_F(PluginMetadataTest, + mergeMetadataShouldNotUseMergedGroupIfItAndCurrentGroupAreBothExplicit) { + PluginMetadata plugin1; + PluginMetadata plugin2; + + plugin1.SetGroup("group1"); + plugin2.SetGroup("group2"); + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ("group1", plugin1.GetGroup()); +} + +TEST_F(PluginMetadataTest, + mergeMetadataShouldNotUseMergedGroupIfItAndCurrentGroupAreBothImplicit) { + PluginMetadata plugin1; + PluginMetadata plugin2; + + plugin1.MergeMetadata(plugin2); + + EXPECT_FALSE(plugin1.GetGroup().has_value()); +} + +TEST_F( + PluginMetadataTest, + mergeMetadataShouldNotUseMergedGroupIfItIsImplicitAndCurrentGroupIsExplicit) { + PluginMetadata plugin1; + PluginMetadata plugin2; + + plugin1.SetGroup("group1"); + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ("group1", plugin1.GetGroup()); +} + +TEST_F( + PluginMetadataTest, + mergeMetadataShouldUseMergedGroupIfItIsExplicitAndCurrentGroupIsImplicit) { + PluginMetadata plugin1; + PluginMetadata plugin2; + + plugin2.SetGroup("group2"); + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ("group2", plugin1.GetGroup()); +} + +TEST_F(PluginMetadataTest, mergeMetadataShouldMergeLoadAfterData) { + PluginMetadata plugin1; + PluginMetadata plugin2; + File file1(blankEsm); + File file2(blankDifferentEsm); + + plugin1.SetLoadAfterFiles({file1}); + plugin2.SetLoadAfterFiles({file1, file2}); + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ(std::vector({file1, file2}), plugin1.GetLoadAfterFiles()); +} + +TEST_F(PluginMetadataTest, mergeMetadataShouldMergeRequirementData) { + PluginMetadata plugin1; + PluginMetadata plugin2; + File file1(blankEsm); + File file2(blankDifferentEsm); + + plugin1.SetRequirements({file1}); + plugin2.SetRequirements({file1, file2}); + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ(std::vector({file1, file2}), plugin1.GetRequirements()); +} + +TEST_F(PluginMetadataTest, mergeMetadataShouldMergeIncompatibilityData) { + PluginMetadata plugin1; + PluginMetadata plugin2; + File file1(blankEsm); + File file2(blankDifferentEsm); + + plugin1.SetIncompatibilities({file1}); + plugin2.SetIncompatibilities({file1, file2}); + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ(std::vector({file1, file2}), plugin1.GetIncompatibilities()); +} + +TEST_F(PluginMetadataTest, mergeMetadataShouldMergeMessages) { + PluginMetadata plugin1; + PluginMetadata plugin2; + Message message(MessageType::say, "content"); + + plugin1.SetMessages({message}); + plugin2.SetMessages({message}); + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ(std::vector({message, message}), plugin1.GetMessages()); +} + +TEST_F(PluginMetadataTest, mergeMetadataShouldMergeTags) { + PluginMetadata plugin1; + PluginMetadata plugin2; + Tag tag1("Relev"); + Tag tag2("Relev", false); + Tag tag3("Delev"); + + plugin1.SetTags({tag1}); + plugin2.SetTags({tag1, tag2, tag3}); + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ(std::vector({tag1, tag2, tag3}), plugin1.GetTags()); +} + +TEST_F(PluginMetadataTest, mergeMetadataShouldMergeDirtyInfoData) { + PluginMetadata plugin1; + PluginMetadata plugin2; + PluginCleaningData info1(0x5, "utility", info_, 1, 2, 3); + PluginCleaningData info2(0xA, "utility", info_, 1, 2, 3); + + plugin1.SetDirtyInfo({info1}); + plugin2.SetDirtyInfo({info1, info2}); + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ(std::vector({info1, info2}), + plugin1.GetDirtyInfo()); +} +TEST_F(PluginMetadataTest, mergeMetadataShouldMergeCleanInfoData) { + PluginMetadata plugin1; + PluginMetadata plugin2; + PluginCleaningData info1(0x5, "utility"); + PluginCleaningData info2(0xA, "utility"); + + plugin1.SetCleanInfo({info1}); + plugin2.SetCleanInfo({info1, info2}); + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ(std::vector({info1, info2}), + plugin1.GetCleanInfo()); +} + +TEST_F(PluginMetadataTest, mergeMetadataShouldMergeLocationData) { + PluginMetadata plugin1; + PluginMetadata plugin2; + Location location1("http://www.example.com/1"); + Location location2("http://www.example.com/2"); + + plugin1.SetLocations({location1}); + plugin2.SetLocations({location1, location2}); + plugin1.MergeMetadata(plugin2); + + EXPECT_EQ(std::vector({location1, location2}), + plugin1.GetLocations()); +} + +TEST_F(PluginMetadataTest, unsetGroupShouldLeaveNoGroupValueSet) { + PluginMetadata plugin; + EXPECT_FALSE(plugin.GetGroup().has_value()); + + plugin.SetGroup("test"); + EXPECT_EQ("test", plugin.GetGroup().value()); + + plugin.UnsetGroup(); + EXPECT_FALSE(plugin.GetGroup().has_value()); +} + +TEST_F(PluginMetadataTest, + hasNameOnlyShouldBeTrueForADefaultConstructedPluginMetadataObject) { + PluginMetadata plugin; + + EXPECT_TRUE(plugin.HasNameOnly()); +} + +TEST_F(PluginMetadataTest, + hasNameOnlyShouldBeTrueForAPluginMetadataObjectConstructedWithAName) { + PluginMetadata plugin(blankEsp); + + EXPECT_TRUE(plugin.HasNameOnly()); +} + +TEST_F(PluginMetadataTest, hasNameOnlyShouldBeFalseIfTheGroupIsExplicit) { + PluginMetadata plugin; + plugin.SetGroup("group"); + + EXPECT_FALSE(plugin.HasNameOnly()); +} + +TEST_F(PluginMetadataTest, hasNameOnlyShouldBeFalseIfLoadAfterMetadataExists) { + PluginMetadata plugin(blankEsp); + plugin.SetLoadAfterFiles({File(blankEsm)}); + + EXPECT_FALSE(plugin.HasNameOnly()); +} + +TEST_F(PluginMetadataTest, + hasNameOnlyShouldBeFalseIfRequirementMetadataExists) { + PluginMetadata plugin(blankEsp); + plugin.SetRequirements({File(blankEsm)}); + + EXPECT_FALSE(plugin.HasNameOnly()); +} + +TEST_F(PluginMetadataTest, + hasNameOnlyShouldBeFalseIfIncompatibilityMetadataExists) { + PluginMetadata plugin(blankEsp); + plugin.SetIncompatibilities({File(blankEsm)}); + + EXPECT_FALSE(plugin.HasNameOnly()); +} + +TEST_F(PluginMetadataTest, hasNameOnlyShouldBeFalseIfMessagesExist) { + PluginMetadata plugin(blankEsp); + plugin.SetMessages({Message(MessageType::say, "content")}); + + EXPECT_FALSE(plugin.HasNameOnly()); +} + +TEST_F(PluginMetadataTest, hasNameOnlyShouldBeFalseIfTagsExist) { + PluginMetadata plugin(blankEsp); + plugin.SetTags({Tag("Relev")}); + + EXPECT_FALSE(plugin.HasNameOnly()); +} + +TEST_F(PluginMetadataTest, hasNameOnlyShouldBeFalseIfDirtyInfoExists) { + PluginMetadata plugin(blankEsp); + plugin.SetDirtyInfo({PluginCleaningData(5, "utility", info_, 0, 1, 2)}); + + EXPECT_FALSE(plugin.HasNameOnly()); +} + +TEST_F(PluginMetadataTest, hasNameOnlyShouldBeFalseIfCleanInfoExists) { + PluginMetadata plugin(blankEsp); + plugin.SetCleanInfo({PluginCleaningData(5, "utility")}); + + EXPECT_FALSE(plugin.HasNameOnly()); +} + +TEST_F(PluginMetadataTest, hasNameOnlyShouldBeFalseIfLocationsExist) { + PluginMetadata plugin(blankEsp); + plugin.SetLocations({Location("http://www.example.com")}); + + EXPECT_FALSE(plugin.HasNameOnly()); +} + +TEST_F(PluginMetadataTest, isRegexPluginShouldBeFalseForAnEmptyPluginName) { + PluginMetadata plugin; + + EXPECT_FALSE(plugin.IsRegexPlugin()); +} + +TEST_F(PluginMetadataTest, isRegexPluginShouldBeFalseForAnExactPluginFilename) { + PluginMetadata plugin(blankEsm); + + EXPECT_FALSE(plugin.IsRegexPlugin()); +} + +TEST_F(PluginMetadataTest, + isRegexPluginShouldBeTrueIfThePluginNameContainsAColon) { + PluginMetadata plugin("Blank:.esm"); + + EXPECT_TRUE(plugin.IsRegexPlugin()); +} + +TEST_F(PluginMetadataTest, + isRegexPluginShouldBeTrueIfThePluginNameContainsABackslash) { + PluginMetadata plugin("Blank\\.esm"); + + EXPECT_TRUE(plugin.IsRegexPlugin()); +} + +TEST_F(PluginMetadataTest, + isRegexPluginShouldBeTrueIfThePluginNameContainsAnAsterisk) { + PluginMetadata plugin("Blank*.esm"); + + EXPECT_TRUE(plugin.IsRegexPlugin()); +} + +TEST_F(PluginMetadataTest, + isRegexPluginShouldBeTrueIfThePluginNameContainsAQuestionMark) { + PluginMetadata plugin("Blank?.esm"); + + EXPECT_TRUE(plugin.IsRegexPlugin()); +} + +TEST_F(PluginMetadataTest, + isRegexPluginShouldBeTrueIfThePluginNameContainsAVerticalBar) { + PluginMetadata plugin("Blank|.esm"); + + EXPECT_TRUE(plugin.IsRegexPlugin()); +} + +TEST_F(PluginMetadataTest, + asYamlShouldReturnAStringContainingTheMetadataEmittedAsYaml) { + PluginMetadata plugin(blankEsm); + plugin.SetLoadAfterFiles({File(blankEsm)}); + + EXPECT_EQ( + "name: 'Blank.esm'\n" + "after: ['Blank.esm']", + plugin.AsYaml()); +} +} +} + +#endif diff --git a/cxx/src/tests/api/internals/metadata/tag_test.h b/cxx/src/tests/api/internals/metadata/tag_test.h new file mode 100644 index 00000000..e7793a4d --- /dev/null +++ b/cxx/src/tests/api/internals/metadata/tag_test.h @@ -0,0 +1,289 @@ +/* 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 +. +*/ + +#ifndef LOOT_TESTS_API_INTERNALS_METADATA_TAG_TEST +#define LOOT_TESTS_API_INTERNALS_METADATA_TAG_TEST + +#include + +#include "loot/metadata/tag.h" + +namespace loot { +namespace test { +TEST(Tag, + defaultConstructorShouldSetEmptyNameAndConditionStringsForATagAddition) { + Tag tag; + + EXPECT_TRUE(tag.GetName().empty()); + EXPECT_TRUE(tag.IsAddition()); + EXPECT_TRUE(tag.GetCondition().empty()); +} + +TEST(Tag, dataConstructorShouldSetFieldsToGivenValues) { + Tag tag("name", false, "condition"); + + EXPECT_EQ("name", tag.GetName()); + EXPECT_FALSE(tag.IsAddition()); + EXPECT_EQ("condition", tag.GetCondition()); +} + +TEST(Tag, equalityShouldBeCaseSensitiveOnNameAndCondition) { + Tag tag1("name", true, "condition"); + Tag tag2("name", true, "condition"); + + EXPECT_TRUE(tag1 == tag2); + + tag1 = Tag("name"); + tag2 = Tag("Name"); + + EXPECT_FALSE(tag1 == tag2); + + tag1 = Tag("name", true, "condition"); + tag2 = Tag("name", true, "Condition"); + + EXPECT_FALSE(tag1 == tag2); + + tag1 = Tag("name1"); + tag2 = Tag("name2"); + + EXPECT_FALSE(tag1 == tag2); + + tag1 = Tag("name", true, "condition1"); + tag2 = Tag("name", true, "condition2"); + + EXPECT_FALSE(tag1 == tag2); +} + +TEST(Tag, equalityShouldRequireEqualAdditionStates) { + Tag tag1("name", true, "condition"); + Tag tag2("name", true, "condition"); + + EXPECT_TRUE(tag1 == tag2); + + tag1 = Tag("name", true); + tag2 = Tag("name", false); + + EXPECT_FALSE(tag1 == tag2); +} + +TEST(Tag, inequalityShouldBeTheInverseOfEquality) { + Tag tag1("name", true, "condition"); + Tag tag2("name", true, "condition"); + + EXPECT_FALSE(tag1 != tag2); + + tag1 = Tag("name"); + tag2 = Tag("Name"); + + EXPECT_TRUE(tag1 != tag2); + + tag1 = Tag("name", true, "condition"); + tag2 = Tag("name", true, "Condition"); + + EXPECT_TRUE(tag1 != tag2); + + tag1 = Tag("name1"); + tag2 = Tag("name2"); + + EXPECT_TRUE(tag1 != tag2); + + tag1 = Tag("name", true, "condition1"); + tag2 = Tag("name", true, "condition2"); + + EXPECT_TRUE(tag1 != tag2); + + tag1 = Tag("name", true, "condition"); + tag2 = Tag("name", true, "condition"); + + EXPECT_FALSE(tag1 != tag2); + + tag1 = Tag("name", true); + tag2 = Tag("name", false); + + EXPECT_TRUE(tag1 != tag2); +} + +TEST( + Tag, + lessThanOperatorShouldUseCaseSensitiveLexicographicalComparisonForNameAndCondition) { + Tag tag1("name", true, "condition"); + Tag tag2("name", true, "condition"); + + EXPECT_FALSE(tag1 < tag2); + EXPECT_FALSE(tag2 < tag1); + + tag1 = Tag("name"); + tag2 = Tag("Name"); + + EXPECT_FALSE(tag1 < tag2); + EXPECT_TRUE(tag2 < tag1); + + tag1 = Tag("name", true, "condition"); + tag2 = Tag("name", true, "Condition"); + + EXPECT_FALSE(tag1 < tag2); + EXPECT_TRUE(tag2 < tag1); + + tag1 = Tag("name1"); + tag2 = Tag("name2"); + + EXPECT_TRUE(tag1 < tag2); + EXPECT_FALSE(tag2 < tag1); + + tag1 = Tag("name", true, "condition1"); + tag2 = Tag("name", true, "condition2"); + + EXPECT_TRUE(tag1 < tag2); + EXPECT_FALSE(tag2 < tag1); +} + +TEST(Tag, lessThanOperatorShouldTreatTagAdditionsAsBeingLessThanRemovals) { + Tag tag1("name", true); + Tag tag2("name", false); + + EXPECT_TRUE(tag1 < tag2); + EXPECT_FALSE(tag2 < tag1); +} + +TEST(Tag, greaterThanOperatorShouldReturnTrueIfTheSecondTagIsLessThanTheFirst) { + Tag tag1("name", true, "condition"); + Tag tag2("name", true, "condition"); + + EXPECT_FALSE(tag1 > tag2); + EXPECT_FALSE(tag2 > tag1); + + tag1 = Tag("name"); + tag2 = Tag("Name"); + + EXPECT_TRUE(tag1 > tag2); + EXPECT_FALSE(tag2 > tag1); + + tag1 = Tag("name", true, "condition"); + tag2 = Tag("name", true, "Condition"); + + EXPECT_TRUE(tag1 > tag2); + EXPECT_FALSE(tag2 > tag1); + + tag1 = Tag("name1"); + tag2 = Tag("name2"); + + EXPECT_FALSE(tag1 > tag2); + EXPECT_TRUE(tag2 > tag1); + + tag1 = Tag("name", true, "condition1"); + tag2 = Tag("name", true, "condition2"); + + EXPECT_FALSE(tag1 > tag2); + EXPECT_TRUE(tag2 > tag1); + + tag1 = Tag("name", true); + tag2 = Tag("name", false); + + EXPECT_FALSE(tag1 > tag2); + EXPECT_TRUE(tag2 > tag1); +} + +TEST( + Tag, + lessThanOrEqualOperatorShouldReturnTrueIfTheFirstTagIsNotGreaterThanTheSecond) { + Tag tag1("name", true, "condition"); + Tag tag2("name", true, "condition"); + + EXPECT_TRUE(tag1 <= tag2); + EXPECT_TRUE(tag2 <= tag1); + + tag1 = Tag("name"); + tag2 = Tag("Name"); + + EXPECT_FALSE(tag1 <= tag2); + EXPECT_TRUE(tag2 <= tag1); + + tag1 = Tag("name", true, "condition"); + tag2 = Tag("name", true, "Condition"); + + EXPECT_FALSE(tag1 <= tag2); + EXPECT_TRUE(tag2 <= tag1); + + tag1 = Tag("name1"); + tag2 = Tag("name2"); + + EXPECT_TRUE(tag1 <= tag2); + EXPECT_FALSE(tag2 <= tag1); + + tag1 = Tag("name", true, "condition1"); + tag2 = Tag("name", true, "condition2"); + + EXPECT_TRUE(tag1 <= tag2); + EXPECT_FALSE(tag2 <= tag1); + + tag1 = Tag("name", true); + tag2 = Tag("name", false); + + EXPECT_TRUE(tag1 <= tag2); + EXPECT_FALSE(tag2 <= tag1); +} + +TEST( + Tag, + greaterThanOrEqualToOperatorShouldReturnTrueIfTheFirstTagIsNotLessThanTheSecond) { + Tag tag1("name", true, "condition"); + Tag tag2("name", true, "condition"); + + EXPECT_TRUE(tag1 >= tag2); + EXPECT_TRUE(tag2 >= tag1); + + tag1 = Tag("name"); + tag2 = Tag("Name"); + + EXPECT_TRUE(tag1 >= tag2); + EXPECT_FALSE(tag2 >= tag1); + + tag1 = Tag("name", true, "condition"); + tag2 = Tag("name", true, "Condition"); + + EXPECT_TRUE(tag1 >= tag2); + EXPECT_FALSE(tag2 >= tag1); + + tag1 = Tag("name1"); + tag2 = Tag("name2"); + + EXPECT_FALSE(tag1 >= tag2); + EXPECT_TRUE(tag2 >= tag1); + + tag1 = Tag("name", true, "condition1"); + tag2 = Tag("name", true, "condition2"); + + EXPECT_FALSE(tag1 >= tag2); + EXPECT_TRUE(tag2 >= tag1); + + tag1 = Tag("name", true); + tag2 = Tag("name", false); + + EXPECT_FALSE(tag1 >= tag2); + EXPECT_TRUE(tag2 >= tag1); +} +} +} + +#endif