mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Improve Tag tests
This commit is contained in:
+1
-1
@@ -252,7 +252,7 @@ set (LOOT_TESTS_HEADERS "${CMAKE_SOURCE_DIR}/src/tests/base_game_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata/message_content_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata/plugin_dirty_info_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata/plugin_metadata_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata/test_tag.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/metadata/tag_test.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/plugin/test_plugin.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/test_metadata_list.h"
|
||||
"${CMAKE_SOURCE_DIR}/src/tests/backend/test_masterlist.h"
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2014-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_TEST_BACKEND_METADATA_TAG
|
||||
#define LOOT_TEST_BACKEND_METADATA_TAG
|
||||
|
||||
#include "backend/metadata/tag.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace loot {
|
||||
namespace test {
|
||||
TEST(Tag, defaultConstructorShouldSetEmptyNameAndConditionStringsForATagAddition) {
|
||||
Tag tag;
|
||||
|
||||
EXPECT_TRUE(tag.Name().empty());
|
||||
EXPECT_TRUE(tag.IsAddition());
|
||||
EXPECT_TRUE(tag.Condition().empty());
|
||||
}
|
||||
|
||||
TEST(Tag, dataConstructorShouldSetFieldsToGivenValues) {
|
||||
Tag tag("name", false, "condition");
|
||||
|
||||
EXPECT_EQ("name", tag.Name());
|
||||
EXPECT_FALSE(tag.IsAddition());
|
||||
EXPECT_EQ("condition", tag.Condition());
|
||||
}
|
||||
|
||||
TEST(Tag, tagsWithCaseInsensitiveEqualNamesAndEqualAdditionStatesShouldBeEqual) {
|
||||
Tag tag1("Name", true, "condition1");
|
||||
Tag tag2("name", true, "condition2");
|
||||
|
||||
EXPECT_TRUE(tag1 == tag2);
|
||||
}
|
||||
|
||||
TEST(Tags, tagsWithUnequalNamesShouldNotBeEqual) {
|
||||
Tag tag1("name1");
|
||||
Tag tag2("name2");
|
||||
|
||||
EXPECT_FALSE(tag1 == tag2);
|
||||
}
|
||||
|
||||
TEST(Tag, tagsWithUnequalAdditionStatesShouldNotBeEqual) {
|
||||
Tag tag1("Name", true);
|
||||
Tag tag2("name", false);
|
||||
|
||||
EXPECT_FALSE(tag1 == tag2);
|
||||
}
|
||||
|
||||
TEST(Tag, lessThanOperatorShouldCaseInsensitivelyLexicographicallyCompareNameStrings) {
|
||||
Tag tag1("Name");
|
||||
Tag tag2("name");
|
||||
|
||||
EXPECT_FALSE(tag1 < tag2);
|
||||
EXPECT_FALSE(tag2 < tag1);
|
||||
|
||||
tag1 = Tag("name1");
|
||||
tag2 = Tag("name2");
|
||||
|
||||
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, emittingAsYamlShouldOutputOnlyTheNameStringIfTheTagIsAnAdditionWithNoCondition) {
|
||||
Tag tag("name1");
|
||||
YAML::Emitter emitter;
|
||||
emitter << tag;
|
||||
|
||||
EXPECT_EQ(tag.Name(), emitter.c_str());
|
||||
}
|
||||
|
||||
TEST(Tag, emittingAsYamlShouldOutputOnlyTheNameStringPrefixedWithAHyphenIfTheTagIsARemovalWithNoCondition) {
|
||||
Tag tag("name1", false);
|
||||
YAML::Emitter emitter;
|
||||
emitter << tag;
|
||||
|
||||
EXPECT_EQ("-" + tag.Name(), emitter.c_str());
|
||||
}
|
||||
|
||||
TEST(Tag, emittingAsYamlShouldOutputAMapIfTheTagHasACondition) {
|
||||
Tag tag("name1", false, "condition1");
|
||||
YAML::Emitter emitter;
|
||||
emitter << tag;
|
||||
|
||||
EXPECT_STREQ("name: -name1\ncondition: 'condition1'", emitter.c_str());
|
||||
}
|
||||
|
||||
TEST(Tag, encodingAsYamlShouldOmitTheConditionFieldIfTheConditionStringIsEmpty) {
|
||||
Tag tag;
|
||||
YAML::Node node;
|
||||
node = tag;
|
||||
|
||||
EXPECT_FALSE(node["condition"]);
|
||||
}
|
||||
|
||||
TEST(Tag, encodingAsYamlShouldOutputTheNameFieldCorrectly) {
|
||||
Tag tag("name1");
|
||||
YAML::Node node;
|
||||
node = tag;
|
||||
|
||||
EXPECT_EQ(tag.Name(), node["name"].as<std::string>());
|
||||
}
|
||||
|
||||
TEST(Tag, encodingAsYamlShouldOutputTheNameFieldWithAHyphenPrefixIfTheTagIsARemoval) {
|
||||
Tag tag("name1", false);
|
||||
YAML::Node node;
|
||||
node = tag;
|
||||
|
||||
EXPECT_EQ("-" + tag.Name(), node["name"].as<std::string>());
|
||||
}
|
||||
|
||||
TEST(Tag, encodingAsYamlShouldOutputTheConditionFieldIfTheConditionStringIsNotEmpty) {
|
||||
Tag tag("name1", true, "condition1");
|
||||
YAML::Node node;
|
||||
node = tag;
|
||||
|
||||
EXPECT_EQ(tag.Name(), node["name"].as<std::string>());
|
||||
EXPECT_EQ(tag.Condition(), node["condition"].as<std::string>());
|
||||
}
|
||||
|
||||
TEST(Tag, decodingFromYamlScalarShouldSetNameCorrectly) {
|
||||
YAML::Node node = YAML::Load("name1");
|
||||
Tag tag = node.as<Tag>();
|
||||
|
||||
EXPECT_EQ("name1", tag.Name());
|
||||
EXPECT_TRUE(tag.IsAddition());
|
||||
EXPECT_EQ("", tag.Condition());
|
||||
}
|
||||
|
||||
TEST(Tag, decodingFromYamlScalarShouldSetAdditionStateCorrectly) {
|
||||
YAML::Node node = YAML::Load("-name1");
|
||||
Tag tag = node.as<Tag>();
|
||||
|
||||
EXPECT_EQ("name1", tag.Name());
|
||||
EXPECT_FALSE(tag.IsAddition());
|
||||
EXPECT_EQ("", tag.Condition());
|
||||
}
|
||||
|
||||
TEST(Tag, decodingFromYamlMapShouldSetDataCorrectly) {
|
||||
YAML::Node node = YAML::Load("{name: name1, condition: 'file(\"Foo.esp\")'}");
|
||||
Tag tag = node.as<Tag>();
|
||||
|
||||
EXPECT_EQ("name1", tag.Name());
|
||||
EXPECT_TRUE(tag.IsAddition());
|
||||
EXPECT_EQ("file(\"Foo.esp\")", tag.Condition());
|
||||
}
|
||||
|
||||
TEST(Tag, decodingFromYamlShouldThrowIfAnInvalidConditionIsGiven) {
|
||||
YAML::Node node = YAML::Load("{name: name1, condition: invalid}");
|
||||
|
||||
EXPECT_THROW(node.as<Tag>(), YAML::RepresentationException);
|
||||
}
|
||||
|
||||
TEST(Tag, decodingFromYamlListShouldThrow) {
|
||||
YAML::Node node = YAML::Load("[0, 1, 2]");
|
||||
|
||||
EXPECT_THROW(node.as<Tag>(), YAML::RepresentationException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,182 +0,0 @@
|
||||
/* LOOT
|
||||
|
||||
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
|
||||
Fallout: New Vegas.
|
||||
|
||||
Copyright (C) 2014-2016 WrinklyNinja
|
||||
|
||||
This file is part of LOOT.
|
||||
|
||||
LOOT is free software: you can redistribute
|
||||
it and/or modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
LOOT is distributed in the hope that it will
|
||||
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LOOT. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOOT_TEST_BACKEND_METADATA_TAG
|
||||
#define LOOT_TEST_BACKEND_METADATA_TAG
|
||||
|
||||
#include "backend/metadata/tag.h"
|
||||
#include "tests/fixtures.h"
|
||||
|
||||
namespace loot {
|
||||
namespace test {
|
||||
TEST(Tag, ConstructorsAndDataAccess) {
|
||||
Tag tag;
|
||||
EXPECT_EQ("", tag.Name());
|
||||
EXPECT_TRUE(tag.IsAddition());
|
||||
EXPECT_EQ("", tag.Condition());
|
||||
|
||||
tag = Tag("name");
|
||||
EXPECT_EQ("name", tag.Name());
|
||||
EXPECT_TRUE(tag.IsAddition());
|
||||
EXPECT_EQ("", tag.Condition());
|
||||
|
||||
tag = Tag("name", false);
|
||||
EXPECT_EQ("name", tag.Name());
|
||||
EXPECT_FALSE(tag.IsAddition());
|
||||
EXPECT_EQ("", tag.Condition());
|
||||
|
||||
// Not a valid condition, but not evaluating it in this test.
|
||||
tag = Tag("name", false, "condition");
|
||||
EXPECT_EQ("name", tag.Name());
|
||||
EXPECT_FALSE(tag.IsAddition());
|
||||
EXPECT_EQ("condition", tag.Condition());
|
||||
}
|
||||
|
||||
TEST(Tag, EqualityOperator) {
|
||||
Tag tag1, tag2;
|
||||
EXPECT_TRUE(tag1 == tag2);
|
||||
|
||||
// Not valid conditions, but not evaluating them in this test.
|
||||
tag1 = Tag("name", true, "condition1");
|
||||
tag2 = Tag("name", true, "condition2");
|
||||
EXPECT_TRUE(tag1 == tag2);
|
||||
|
||||
tag1 = Tag("name");
|
||||
tag2 = Tag("Name");
|
||||
EXPECT_TRUE(tag1 == tag2);
|
||||
|
||||
tag1 = Tag("name", true);
|
||||
tag2 = Tag("name", false);
|
||||
EXPECT_FALSE(tag1 == tag2);
|
||||
|
||||
tag1 = Tag("name1");
|
||||
tag2 = Tag("name2");
|
||||
EXPECT_FALSE(tag1 == tag2);
|
||||
}
|
||||
|
||||
TEST(Tag, LessThanOperator) {
|
||||
Tag tag1, tag2;
|
||||
EXPECT_FALSE(tag1 < tag2);
|
||||
EXPECT_FALSE(tag2 < tag1);
|
||||
|
||||
tag1 = Tag("name", true, "condition1");
|
||||
tag2 = Tag("name", true, "condition2");
|
||||
EXPECT_FALSE(tag1 < tag2);
|
||||
EXPECT_FALSE(tag2 < tag1);
|
||||
|
||||
tag1 = Tag("name");
|
||||
tag2 = Tag("Name");
|
||||
EXPECT_FALSE(tag1 < tag2);
|
||||
EXPECT_FALSE(tag2 < tag1);
|
||||
|
||||
tag1 = Tag("name1");
|
||||
tag2 = Tag("name2");
|
||||
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, YamlEmitter) {
|
||||
Tag tag("name1");
|
||||
YAML::Emitter e1;
|
||||
e1 << tag;
|
||||
EXPECT_STREQ("name1", e1.c_str());
|
||||
|
||||
tag = Tag("name1", false);
|
||||
YAML::Emitter e2;
|
||||
e2 << tag;
|
||||
EXPECT_STREQ("-name1", e2.c_str());
|
||||
|
||||
tag = Tag("name1", true, "condition1");
|
||||
YAML::Emitter e3;
|
||||
e3 << tag;
|
||||
EXPECT_STREQ("name: name1\ncondition: 'condition1'", e3.c_str());
|
||||
|
||||
tag = Tag("name1", false, "condition1");
|
||||
YAML::Emitter e4;
|
||||
e4 << tag;
|
||||
EXPECT_STREQ("name: -name1\ncondition: 'condition1'", e4.c_str());
|
||||
}
|
||||
|
||||
TEST(Tag, YamlEncode) {
|
||||
YAML::Node node;
|
||||
|
||||
Tag tag("name1");
|
||||
node = tag;
|
||||
EXPECT_EQ("name1", node["name"].as<std::string>());
|
||||
EXPECT_FALSE(node["condition"]);
|
||||
|
||||
tag = Tag("name1", false);
|
||||
node = tag;
|
||||
EXPECT_EQ("-name1", node["name"].as<std::string>());
|
||||
EXPECT_FALSE(node["condition"]);
|
||||
|
||||
tag = Tag("name1", false, "condition1");
|
||||
node = tag;
|
||||
EXPECT_EQ("-name1", node["name"].as<std::string>());
|
||||
EXPECT_EQ("condition1", node["condition"].as<std::string>());
|
||||
}
|
||||
|
||||
TEST(Tag, YamlDecode) {
|
||||
YAML::Node node;
|
||||
Tag tag;
|
||||
|
||||
node = YAML::Load("name1");
|
||||
tag = node.as<Tag>();
|
||||
EXPECT_EQ("name1", tag.Name());
|
||||
EXPECT_TRUE(tag.IsAddition());
|
||||
EXPECT_EQ("", tag.Condition());
|
||||
|
||||
node = YAML::Load("-name1");
|
||||
tag = node.as<Tag>();
|
||||
EXPECT_EQ("name1", tag.Name());
|
||||
EXPECT_FALSE(tag.IsAddition());
|
||||
EXPECT_EQ("", tag.Condition());
|
||||
|
||||
node = YAML::Load("{name: -name1}");
|
||||
tag = node.as<Tag>();
|
||||
EXPECT_EQ("name1", tag.Name());
|
||||
EXPECT_FALSE(tag.IsAddition());
|
||||
EXPECT_EQ("", tag.Condition());
|
||||
|
||||
node = YAML::Load("{name: name1, condition: 'file(\"Foo.esp\")'}");
|
||||
tag = node.as<Tag>();
|
||||
EXPECT_EQ("name1", tag.Name());
|
||||
EXPECT_TRUE(tag.IsAddition());
|
||||
EXPECT_EQ("file(\"Foo.esp\")", tag.Condition());
|
||||
|
||||
node = YAML::Load("{name: name1, condition: invalid}");
|
||||
EXPECT_THROW(node.as<Tag>(), YAML::RepresentationException);
|
||||
|
||||
node = YAML::Load("[0, 1, 2]");
|
||||
EXPECT_THROW(node.as<Tag>(), YAML::RepresentationException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -58,7 +58,7 @@
|
||||
#include "backend/metadata/message_content_test.h"
|
||||
#include "backend/metadata/plugin_dirty_info_test.h"
|
||||
#include "backend/metadata/plugin_metadata_test.h"
|
||||
#include "backend/metadata/test_tag.h"
|
||||
#include "backend/metadata/tag_test.h"
|
||||
#include "backend/plugin/test_plugin.h"
|
||||
#include "backend/test_metadata_list.h"
|
||||
#include "backend/test_masterlist.h"
|
||||
|
||||
Reference in New Issue
Block a user