From 83ba085a6dcd7cef0450cd82d307d0927b0a0546 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 13 Apr 2020 18:56:44 +0100 Subject: [PATCH] Add missing comparison operators for plugin metadata classes This does not include the Group class, as that still needs its existing operator implementations updated. --- include/loot/metadata/file.h | 33 +++- include/loot/metadata/location.h | 30 +++ include/loot/metadata/message.h | 29 +++ include/loot/metadata/message_content.h | 30 +++ include/loot/metadata/plugin_cleaning_data.h | 49 ++++- include/loot/metadata/tag.h | 33 +++- src/api/metadata/file.cpp | 8 + src/api/metadata/location.cpp | 14 ++ src/api/metadata/message.cpp | 10 + src/api/metadata/message_content.cpp | 17 ++ src/api/metadata/plugin_cleaning_data.cpp | 16 ++ src/api/metadata/tag.cpp | 12 +- src/tests/api/internals/metadata/file_test.h | 136 +++++++++++++- .../api/internals/metadata/location_test.h | 132 ++++++++++++- .../internals/metadata/message_content_test.h | 137 +++++++++++++- .../api/internals/metadata/message_test.h | 175 ++++++++++++++++++ .../metadata/plugin_cleaning_data_test.h | 170 +++++++++++++++++ src/tests/api/internals/metadata/tag_test.h | 159 +++++++++++++++- 18 files changed, 1164 insertions(+), 26 deletions(-) diff --git a/include/loot/metadata/file.h b/include/loot/metadata/file.h index bf06e062..73a25205 100644 --- a/include/loot/metadata/file.h +++ b/include/loot/metadata/file.h @@ -52,8 +52,8 @@ public: * @return A File object. */ LOOT_API explicit File(const std::string& name, - const std::string& display = "", - const std::string& condition = ""); + const std::string& display = "", + const std::string& condition = ""); /** * A less-than operator implemented with no semantics so that File objects can @@ -85,6 +85,35 @@ private: std::string name_; std::string display_; }; + +/** + * Check if two File objects are not equal. + * @returns True if the File objects are not equal, false otherwise. + */ +LOOT_API bool operator!=(const File& lhs, const File& rhs); + +/** + * Check if the first File object is greater than the second File object. + * @returns True if the second File object is less than the first File object, + * false otherwise. + */ +LOOT_API bool operator>(const File& lhs, const File& rhs); + +/** + * Check if the first File object is less than or equal to the second File + * object. + * @returns True if the first File object is not greater than the second File + * object, false otherwise. + */ +LOOT_API bool operator<=(const File& lhs, const File& rhs); + +/** + * Check if the first File object is greater than or equal to the second File + * object. + * @returns True if the first File object is not less than the second File + * object, false otherwise. + */ +LOOT_API bool operator>=(const File& lhs, const File& rhs); } #endif diff --git a/include/loot/metadata/location.h b/include/loot/metadata/location.h index af6dcb1f..5824ada5 100644 --- a/include/loot/metadata/location.h +++ b/include/loot/metadata/location.h @@ -81,6 +81,36 @@ private: std::string url_; std::string name_; }; + +/** + * Check if two Location objects are not equal. + * @returns True if the Location objects are not equal, false otherwise. + */ +LOOT_API bool operator!=(const Location& lhs, const Location& rhs); + +/** + * Check if the first Location object is greater than the second Location + * object. + * @returns True if the second Location object is less than the first Location + * object, false otherwise. + */ +LOOT_API bool operator>(const Location& lhs, const Location& rhs); + +/** + * Check if the first Location object is less than or equal to the second + * Location object. + * @returns True if the first Location object is not greater than the second + * Location object, false otherwise. + */ +LOOT_API bool operator<=(const Location& lhs, const Location& rhs); + +/** + * Check if the first Location object is greater than or equal to the second + * Location object. + * @returns True if the first Location object is not less than the second + * Location object, false otherwise. + */ +LOOT_API bool operator>=(const Location& lhs, const Location& rhs); } #endif diff --git a/include/loot/metadata/message.h b/include/loot/metadata/message.h index 9d2ac574..d093c6cf 100644 --- a/include/loot/metadata/message.h +++ b/include/loot/metadata/message.h @@ -124,6 +124,35 @@ private: MessageType type_; std::vector content_; }; + +/** + * Check if two Message objects are not equal. + * @returns True if the Message objects are not equal, false otherwise. + */ +LOOT_API bool operator!=(const Message& lhs, const Message& rhs); + +/** + * Check if the first Message object is greater than the second Message object. + * @returns True if the second Message object is less than the first Message + * object, false otherwise. + */ +LOOT_API bool operator>(const Message& lhs, const Message& rhs); + +/** + * Check if the first Message object is less than or equal to the second + * Message object. + * @returns True if the first Message object is not greater than the second + * Message object, false otherwise. + */ +LOOT_API bool operator<=(const Message& lhs, const Message& rhs); + +/** + * Check if the first Message object is greater than or equal to the second + * Message object. + * @returns True if the first Message object is not less than the second + * Message object, false otherwise. + */ +LOOT_API bool operator>=(const Message& lhs, const Message& rhs); } #endif diff --git a/include/loot/metadata/message_content.h b/include/loot/metadata/message_content.h index 2d03b6be..c6cf8b0e 100644 --- a/include/loot/metadata/message_content.h +++ b/include/loot/metadata/message_content.h @@ -103,6 +103,36 @@ private: std::string text_; std::string language_; }; + +/** + * Check if two MessageContent objects are not equal. + * @returns True if the MessageContent objects are not equal, false otherwise. + */ +LOOT_API bool operator!=(const MessageContent& lhs, const MessageContent& rhs); + +/** + * Check if the first MessageContent object is greater than the second + * MessageContent object. + * @returns True if the second MessageContent object is less than the first + * MessageContent object, false otherwise. + */ +LOOT_API bool operator>(const MessageContent& lhs, const MessageContent& rhs); + +/** + * Check if the first MessageContent object is less than or equal to the second + * MessageContent object. + * @returns True if the first MessageContent object is not greater than the + * second MessageContent object, false otherwise. + */ +LOOT_API bool operator<=(const MessageContent& lhs, const MessageContent& rhs); + +/** + * Check if the first MessageContent object is greater than or equal to the + * second MessageContent object. + * @returns True if the first MessageContent object is not less than the second + * MessageContent object, false otherwise. + */ +LOOT_API bool operator>=(const MessageContent& lhs, const MessageContent& rhs); } #endif diff --git a/include/loot/metadata/plugin_cleaning_data.h b/include/loot/metadata/plugin_cleaning_data.h index 789c918c..634d79ac 100644 --- a/include/loot/metadata/plugin_cleaning_data.h +++ b/include/loot/metadata/plugin_cleaning_data.h @@ -56,7 +56,8 @@ public: * The utility that the plugin cleanliness was checked with. * @return A PluginCleaningData object. */ - LOOT_API explicit PluginCleaningData(uint32_t crc, const std::string& utility); + LOOT_API explicit PluginCleaningData(uint32_t crc, + const std::string& utility); /** * Construct a PluginCleaningData object with the given values. @@ -76,11 +77,11 @@ public: * @return A PluginCleaningData object. */ LOOT_API explicit PluginCleaningData(uint32_t crc, - const std::string& utility, - const std::vector& info, - unsigned int itm, - unsigned int ref, - unsigned int nav); + const std::string& utility, + const std::vector& info, + unsigned int itm, + unsigned int ref, + unsigned int nav); /** * A less-than operator implemented with no semantics so that * PluginCleaningData objects can be stored in sets. @@ -90,7 +91,7 @@ public: LOOT_API bool operator<(const PluginCleaningData& rhs) const; /** - * Check if two PluginCleaningData objects are equal by comparing their + * Check if two PluginCleaningData objects are equal by comparing their * fields. * @returns True if the objects' fields are equal, false otherwise. */ @@ -153,6 +154,40 @@ private: std::string utility_; std::vector info_; }; + +/** + * Check if two MessageContent objects are not equal. + * @returns True if the MessageContent objects are not equal, false otherwise. + */ +LOOT_API bool operator!=(const PluginCleaningData& lhs, + const PluginCleaningData& rhs); + +/** + * Check if the first PluginCleaningData object is greater than the second + * PluginCleaningData object. + * @returns True if the second PluginCleaningData object is less than the first + * PluginCleaningData object, false otherwise. + */ +LOOT_API bool operator>(const PluginCleaningData& lhs, + const PluginCleaningData& rhs); + +/** + * Check if the first PluginCleaningData object is less than or equal to the + * second PluginCleaningData object. + * @returns True if the first PluginCleaningData object is not greater than the + * second PluginCleaningData object, false otherwise. + */ +LOOT_API bool operator<=(const PluginCleaningData& lhs, + const PluginCleaningData& rhs); + +/** + * Check if the first PluginCleaningData object is greater than or equal to the + * second PluginCleaningData object. + * @returns True if the first PluginCleaningData object is not less than the + * second PluginCleaningData object, false otherwise. + */ +LOOT_API bool operator>=(const PluginCleaningData& lhs, + const PluginCleaningData& rhs); } #endif diff --git a/include/loot/metadata/tag.h b/include/loot/metadata/tag.h index d4b8c6a2..5ad2ecac 100644 --- a/include/loot/metadata/tag.h +++ b/include/loot/metadata/tag.h @@ -54,8 +54,8 @@ public: * @return A Tag object. */ LOOT_API explicit Tag(const std::string& tag, - const bool isAddition = true, - const std::string& condition = ""); + const bool isAddition = true, + const std::string& condition = ""); /** * A less-than operator implemented with no semantics so that Tag objects @@ -86,6 +86,35 @@ private: std::string name_; bool addTag_; }; + +/** + * Check if two Tag objects are not equal. + * @returns True if the Tag objects are not equal, false otherwise. + */ +LOOT_API bool operator!=(const Tag& lhs, const Tag& rhs); + +/** + * Check if the first Tag object is greater than the second Tag object. + * @returns True if the second Tag object is less than the first Tag object, + * false otherwise. + */ +LOOT_API bool operator>(const Tag& lhs, const Tag& rhs); + +/** + * Check if the first Tag object is less than or equal to the second Tag + * object. + * @returns True if the first Tag object is not greater than the second Tag + * object, false otherwise. + */ +LOOT_API bool operator<=(const Tag& lhs, const Tag& rhs); + +/** + * Check if the first Tag object is greater than or equal to the second Tag + * object. + * @returns True if the first Tag object is not less than the second Tag + * object, false otherwise. + */ +LOOT_API bool operator>=(const Tag& lhs, const Tag& rhs); } #endif diff --git a/src/api/metadata/file.cpp b/src/api/metadata/file.cpp index 79c159e9..0d535505 100644 --- a/src/api/metadata/file.cpp +++ b/src/api/metadata/file.cpp @@ -70,4 +70,12 @@ std::string File::GetDisplayName() const { else return display_; } + +bool operator!=(const File& lhs, const File& rhs) { return !(lhs == rhs); } + +bool operator>(const File& lhs, const File& rhs) { return rhs < lhs; } + +bool operator<=(const File& lhs, const File& rhs) { return !(lhs > rhs); } + +bool operator>=(const File& lhs, const File& rhs) { return !(lhs < rhs); } } diff --git a/src/api/metadata/location.cpp b/src/api/metadata/location.cpp index b1c15bb1..ec652220 100644 --- a/src/api/metadata/location.cpp +++ b/src/api/metadata/location.cpp @@ -50,4 +50,18 @@ bool Location::operator==(const Location& rhs) const { std::string Location::GetURL() const { return url_; } std::string Location::GetName() const { return name_; } + +bool operator!=(const Location& lhs, const Location& rhs) { + return !(lhs == rhs); +} + +bool operator>(const Location& lhs, const Location& rhs) { return rhs < lhs; } + +bool operator<=(const Location& lhs, const Location& rhs) { + return !(lhs > rhs); +} + +bool operator>=(const Location& lhs, const Location& rhs) { + return !(lhs < rhs); +} } diff --git a/src/api/metadata/message.cpp b/src/api/metadata/message.cpp index 3597b083..ad548965 100644 --- a/src/api/metadata/message.cpp +++ b/src/api/metadata/message.cpp @@ -100,4 +100,14 @@ SimpleMessage Message::ToSimpleMessage(const std::string& language) const { return simpleMessage; } + +bool operator!=(const Message& lhs, const Message& rhs) { + return !(lhs == rhs); +} + +bool operator>(const Message& lhs, const Message& rhs) { return rhs < lhs; } + +bool operator<=(const Message& lhs, const Message& rhs) { return !(lhs > rhs); } + +bool operator>=(const Message& lhs, const Message& rhs) { return !(lhs < rhs); } } diff --git a/src/api/metadata/message_content.cpp b/src/api/metadata/message_content.cpp index f640a51f..d804bf01 100644 --- a/src/api/metadata/message_content.cpp +++ b/src/api/metadata/message_content.cpp @@ -55,6 +55,7 @@ bool MessageContent::operator<(const MessageContent& rhs) const { bool MessageContent::operator==(const MessageContent& rhs) const { return text_ == rhs.text_ && language_ == rhs.language_; } + MessageContent MessageContent::Choose(const std::vector content, const std::string& language) { if (content.empty()) @@ -72,4 +73,20 @@ MessageContent MessageContent::Choose(const std::vector content, return english; } } + +bool operator!=(const MessageContent& lhs, const MessageContent& rhs) { + return !(lhs == rhs); +} + +bool operator>(const MessageContent& lhs, const MessageContent& rhs) { + return rhs < lhs; +} + +bool operator<=(const MessageContent& lhs, const MessageContent& rhs) { + return !(lhs > rhs); +} + +bool operator>=(const MessageContent& lhs, const MessageContent& rhs) { + return !(lhs < rhs); +} } diff --git a/src/api/metadata/plugin_cleaning_data.cpp b/src/api/metadata/plugin_cleaning_data.cpp index 52cd80b8..ed7b0eca 100644 --- a/src/api/metadata/plugin_cleaning_data.cpp +++ b/src/api/metadata/plugin_cleaning_data.cpp @@ -121,4 +121,20 @@ MessageContent PluginCleaningData::ChooseInfo( const std::string& language) const { return MessageContent::Choose(info_, language); } + +bool operator!=(const PluginCleaningData& lhs, const PluginCleaningData& rhs) { + return !(lhs == rhs); +} + +bool operator>(const PluginCleaningData& lhs, const PluginCleaningData& rhs) { + return rhs < lhs; +} + +bool operator<=(const PluginCleaningData& lhs, const PluginCleaningData& rhs) { + return !(lhs > rhs); +} + +bool operator>=(const PluginCleaningData& lhs, const PluginCleaningData& rhs) { + return !(lhs < rhs); +} } diff --git a/src/api/metadata/tag.cpp b/src/api/metadata/tag.cpp index be48540c..d708b196 100644 --- a/src/api/metadata/tag.cpp +++ b/src/api/metadata/tag.cpp @@ -40,7 +40,7 @@ bool Tag::operator<(const Tag& rhs) const { if (addTag_ != rhs.addTag_) { return addTag_ && !rhs.addTag_; } - + if (name_ < rhs.name_) { return true; } @@ -48,7 +48,7 @@ bool Tag::operator<(const Tag& rhs) const { if (rhs.name_ < name_) { return false; } - + return GetCondition() < rhs.GetCondition(); } @@ -60,4 +60,12 @@ bool Tag::operator==(const Tag& rhs) const { bool Tag::IsAddition() const { return addTag_; } std::string Tag::GetName() const { return name_; } + +bool operator!=(const Tag& lhs, const Tag& rhs) { return !(lhs == rhs); } + +bool operator>(const Tag& lhs, const Tag& rhs) { return rhs < lhs; } + +bool operator<=(const Tag& lhs, const Tag& rhs) { return !(lhs > rhs); } + +bool operator>=(const Tag& lhs, const Tag& rhs) { return !(lhs < rhs); } } diff --git a/src/tests/api/internals/metadata/file_test.h b/src/tests/api/internals/metadata/file_test.h index 65f55c16..b5f7b7aa 100644 --- a/src/tests/api/internals/metadata/file_test.h +++ b/src/tests/api/internals/metadata/file_test.h @@ -49,9 +49,7 @@ TEST(File, stringsConstructorShouldStoreGivenStrings) { EXPECT_EQ("condition", file.GetCondition()); } -TEST( - File, - equalityShouldBeCaseInsensitiveOnNameAndDisplay) { +TEST(File, equalityShouldBeCaseInsensitiveOnNameAndDisplay) { File file1("name", "display", "condition"); File file2("name", "display", "condition"); @@ -95,9 +93,35 @@ TEST(File, equalityShouldBeCaseSensitiveOnDisplayAndCondition) { EXPECT_FALSE(file1 == file2); } -TEST( - File, - lessThanOperatorShouldUseCaseInsensitiveLexicographicalComparisonForName) { +TEST(File, inequalityShouldBeTheInverseOfEquality) { + File file1("name", "display", "condition"); + File file2("name", "display", "condition"); + + 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", "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); +} + +TEST(File, + lessThanOperatorShouldUseCaseInsensitiveLexicographicalComparisonForName) { File file1("name", "display", "condition"); File file2("name", "display", "condition"); @@ -151,6 +175,106 @@ TEST( EXPECT_FALSE(file2 < file1); } +TEST(File, shouldAllowComparisonUsingGreaterThanOperator) { + 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(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); +} + +TEST( + File, + lessThanOrEqualToOperatorShouldReturnTrueIfFirstFileIsNotGreaterThanSecondFile) { + File file1("name", "display", "condition"); + File file2("name", "display", "condition"); + + 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); +} + +TEST( + File, + greaterThanOrEqualToOperatorShouldReturnTrueIfFirstFileIsNotLessThanSecondFile) { + File file1("name", "display", "condition"); + File file2("name", "display", "condition"); + + 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); +} + TEST(File, emittingAsYamlShouldSingleQuoteValues) { File file("name1", "display1", "condition1"); YAML::Emitter emitter; diff --git a/src/tests/api/internals/metadata/location_test.h b/src/tests/api/internals/metadata/location_test.h index b8da8a4d..6365b79f 100644 --- a/src/tests/api/internals/metadata/location_test.h +++ b/src/tests/api/internals/metadata/location_test.h @@ -74,8 +74,36 @@ TEST(Location, equalityShouldBeCaseSensitiveOnUrlAndName) { EXPECT_FALSE(location1 == location2); } -TEST(Location, - lessThanOperatorShouldUseCaseSensitiveLexicographicalComparisonForNameAndUrl) { +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"); @@ -107,6 +135,106 @@ TEST(Location, 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); +} + TEST(Location, emittingAsYamlShouldOutputAScalarIfTheNameStringIsEmpty) { Location location("http://www.example.com"); YAML::Emitter emitter; diff --git a/src/tests/api/internals/metadata/message_content_test.h b/src/tests/api/internals/metadata/message_content_test.h index bc4e5bf0..7bf46e2b 100644 --- a/src/tests/api/internals/metadata/message_content_test.h +++ b/src/tests/api/internals/metadata/message_content_test.h @@ -49,7 +49,8 @@ TEST(MessageContent, contentConstructorShouldStoreGivenStringAndLanguage) { EXPECT_EQ(french, content.GetLanguage()); } -TEST(MessageContent, equalityShouldRequireCaseSensitiveEqualityOnTextAndLanguage) { +TEST(MessageContent, + equalityShouldRequireCaseSensitiveEqualityOnTextAndLanguage) { MessageContent content1("content", "fr"); MessageContent content2("content", "fr"); @@ -76,8 +77,36 @@ TEST(MessageContent, equalityShouldRequireCaseSensitiveEqualityOnTextAndLanguage EXPECT_FALSE(content1 == content2); } -TEST(MessageContent, - lessThanOperatorShouldUseCaseSensitiveLexicographicalComparisonForTextAndLanguage) { +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"); @@ -109,6 +138,108 @@ TEST(MessageContent, 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(MessageContent, emittingAsYamlShouldOutputDataCorrectly) { MessageContent content("content", french); YAML::Emitter emitter; diff --git a/src/tests/api/internals/metadata/message_test.h b/src/tests/api/internals/metadata/message_test.h index 1a0783fb..782ffe76 100644 --- a/src/tests/api/internals/metadata/message_test.h +++ b/src/tests/api/internals/metadata/message_test.h @@ -123,6 +123,43 @@ TEST_P(MessageTest, equalityShouldRequireEqualContent) { EXPECT_FALSE(message1 == message2); } +TEST_P(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_P(MessageTest, lessThanOperatorShouldCompareMessageTypes) { Message message1(MessageType::say, "content"); Message message2(MessageType::say, "content"); @@ -173,6 +210,144 @@ TEST_P( EXPECT_FALSE(message2 < message1); } +TEST_P( + 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_P( + 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_P( + 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); +} + TEST_P(MessageTest, getContentShouldReturnADefaultContentObjectIfNoneExists) { Message message; EXPECT_EQ(MessageContent(), diff --git a/src/tests/api/internals/metadata/plugin_cleaning_data_test.h b/src/tests/api/internals/metadata/plugin_cleaning_data_test.h index 9596d0f8..9d21427c 100644 --- a/src/tests/api/internals/metadata/plugin_cleaning_data_test.h +++ b/src/tests/api/internals/metadata/plugin_cleaning_data_test.h @@ -105,6 +105,41 @@ TEST_P(PluginCleaningDataTest, equalityShouldCheckEqualityOfAllFields) { EXPECT_FALSE(info1 == info2); } +TEST_P(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_P(PluginCleaningDataTest, lessThanOperatorShouldCompareAllFields) { PluginCleaningData info1(0x12345678, "cleaner", info_, 2, 10, 30); PluginCleaningData info2(0x12345678, "cleaner", info_, 2, 10, 30); @@ -148,6 +183,141 @@ TEST_P(PluginCleaningDataTest, lessThanOperatorShouldCompareAllFields) { EXPECT_FALSE(info2 < info1); } +TEST_P( + 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_P( + 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_P( + 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); +} + TEST_P(PluginCleaningDataTest, chooseInfoShouldCreateADefaultContentObjectIfNoneExists) { PluginCleaningData dirtyInfo( diff --git a/src/tests/api/internals/metadata/tag_test.h b/src/tests/api/internals/metadata/tag_test.h index 6ecddf62..15d32275 100644 --- a/src/tests/api/internals/metadata/tag_test.h +++ b/src/tests/api/internals/metadata/tag_test.h @@ -89,8 +89,46 @@ TEST(Tag, equalityShouldRequireEqualAdditionStates) { EXPECT_FALSE(tag1 == tag2); } -TEST(Tag, - lessThanOperatorShouldUseCaseSensitiveLexicographicalComparisonForNameAndCondition) { +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"); @@ -130,6 +168,123 @@ TEST(Tag, lessThanOperatorShouldTreatTagAdditionsAsBeingLessThanRemovals) { 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); +} + TEST( Tag, emittingAsYamlShouldOutputOnlyTheNameStringIfTheTagIsAnAdditionWithNoCondition) {