From a100dc5debfa8263190631309c0f2eef67cb5292 Mon Sep 17 00:00:00 2001 From: Victor Camacho Date: Wed, 29 Jan 2020 17:27:48 -0500 Subject: [PATCH 1/2] Added comparison operators for extended_symbol type --- .../chain/include/eosio/chain/symbol.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libraries/chain/include/eosio/chain/symbol.hpp b/libraries/chain/include/eosio/chain/symbol.hpp index 1faa3038921..071505d83d3 100644 --- a/libraries/chain/include/eosio/chain/symbol.hpp +++ b/libraries/chain/include/eosio/chain/symbol.hpp @@ -165,6 +165,25 @@ namespace eosio { return lhs.value() > rhs.value(); } + inline bool operator== (const extended_symbol& lhs, const extended_symbol& rhs) + { + return std::tie(lhs.sym, lhs.contract) == std::tie(rhs.sym, rhs.contract); + } + + inline bool operator!= (const extended_symbol& lhs, const extended_symbol& rhs) + { + return std::tie(lhs.sym, lhs.contract) != std::tie(rhs.sym, rhs.contract); + } + + inline bool operator< (const extended_symbol& lhs, const extended_symbol& rhs) + { + return std::tie(lhs.sym, lhs.contract) < std::tie(rhs.sym, rhs.contract); + } + + inline bool operator> (const extended_symbol& lhs, const extended_symbol& rhs) + { + return std::tie(lhs.sym, lhs.contract) > std::tie(rhs.sym, rhs.contract); + } } // namespace chain } // namespace eosio From 2ce9d49ab08b55abbd6716b10678befb9f1f33c6 Mon Sep 17 00:00:00 2001 From: Victor Camacho Date: Thu, 30 Jan 2020 16:51:59 -0500 Subject: [PATCH 2/2] Added extended_symbol unit test cases for test comparison operators --- unittests/api_tests.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index 096180ab013..a9665440846 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -2236,6 +2236,41 @@ BOOST_FIXTURE_TEST_CASE(account_creation_time_tests, TESTER) { try { BOOST_REQUIRE_EQUAL( validate(), true ); } FC_LOG_AND_RETHROW() } +/************************************************************************************* + * extended_symbol_api_tests test cases + *************************************************************************************/ +BOOST_FIXTURE_TEST_CASE(extended_symbol_api_tests, TESTER) { try { + name n0{"1"}; + name n1{"5"}; + name n2{"a"}; + name n3{"z"}; + name n4{"111111111111j"}; + name n5{"555555555555j"}; + name n6{"zzzzzzzzzzzzj"}; + + symbol s0{4, ""}; + symbol s1{5, "Z"}; + symbol s2{10, "AAAAA"}; + symbol s3{10, "ZZZZZ"}; + + // Test comparison operators + + BOOST_REQUIRE( (extended_symbol{s0, n0} == extended_symbol{s0, n0}) ); + BOOST_REQUIRE( (extended_symbol{s1, n3} == extended_symbol{s1, n3}) ); + BOOST_REQUIRE( (extended_symbol{s2, n4} == extended_symbol{s2, n4}) ); + BOOST_REQUIRE( (extended_symbol{s3, n6} == extended_symbol{s3, n6}) ); + + BOOST_REQUIRE( (extended_symbol{s0, n0} != extended_symbol{s1, n0}) ); + BOOST_REQUIRE( (extended_symbol{s0, n0} != extended_symbol{s0, n1}) ); + BOOST_REQUIRE( (extended_symbol{s1, n1} != extended_symbol{s2, n2}) ); + + BOOST_REQUIRE( (extended_symbol{s0, n0} < extended_symbol{s1, n0}) ); + BOOST_REQUIRE( (extended_symbol{s0, n0} < extended_symbol{s0, n1}) ); + BOOST_REQUIRE( (extended_symbol{s0, n5} < extended_symbol{s0, n3}) ); + BOOST_REQUIRE( (extended_symbol{s2, n0} < extended_symbol{s3, n0}) ); + +} FC_LOG_AND_RETHROW() } + /************************************************************************************* * eosio_assert_code_tests test cases *************************************************************************************/