Remove ill-defined equality operators (part 1)
This removes overloaded operator== and operator!= from those classes
for which it is unclear what semantics such operators should have,
and whose current definitions are unsound or confusing for the user.
Refs: #4569
Change-Id: Ic385ac1e376a9916e762b1a0f790e4caae7c955b
diff --git a/tests/unit/data.t.cpp b/tests/unit/data.t.cpp
index 9457089..56ca775 100644
--- a/tests/unit/data.t.cpp
+++ b/tests/unit/data.t.cpp
@@ -79,8 +79,6 @@
0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1
};
-// ---- constructor, encode, decode ----
-
BOOST_AUTO_TEST_CASE(DefaultConstructor)
{
Data d;
@@ -251,7 +249,9 @@
{
d.wireDecode("0607 0700 16031B0100"_block);
BOOST_CHECK_EQUAL(d.getName(), "/"); // empty Name is allowed in Data
- BOOST_CHECK_EQUAL(d.getMetaInfo(), MetaInfo());
+ BOOST_CHECK_EQUAL(d.getContentType(), tlv::ContentType_Blob);
+ BOOST_CHECK_EQUAL(d.getFreshnessPeriod(), 0_ms);
+ BOOST_CHECK_EQUAL(d.getFinalBlock().has_value(), false);
BOOST_CHECK_EQUAL(d.getContent().value_size(), 0);
BOOST_CHECK_EQUAL(d.getSignature().getType(), tlv::DigestSha256);
BOOST_CHECK_EQUAL(d.getSignature().getValue().value_size(), 0);
@@ -262,7 +262,9 @@
d.wireDecode("062C 0703080144 16031B0100 "
"1720612A79399E60304A9F701C1ECAC7956BF2F1B046E6C6F0D6C29B3FE3A29BAD76"_block);
BOOST_CHECK_EQUAL(d.getName(), "/D");
- BOOST_CHECK_EQUAL(d.getMetaInfo(), MetaInfo());
+ BOOST_CHECK_EQUAL(d.getContentType(), tlv::ContentType_Blob);
+ BOOST_CHECK_EQUAL(d.getFreshnessPeriod(), 0_ms);
+ BOOST_CHECK_EQUAL(d.getFinalBlock().has_value(), false);
BOOST_CHECK_EQUAL(d.getContent().value_size(), 0);
BOOST_CHECK_EQUAL(d.getSignature().getType(), tlv::DigestSha256);
BOOST_CHECK_EQUAL(d.getSignature().getValue().value_size(), 32);
@@ -282,7 +284,9 @@
d.wireDecode("063A 0703080144 FC00 1400 FC00 1500 FC00 16031B0100 FC00 "
"1720612A79399E60304A9F701C1ECAC7956BF2F1B046E6C6F0D6C29B3FE3A29BAD76 FC00"_block);
BOOST_CHECK_EQUAL(d.getName(), "/D");
- BOOST_CHECK_EQUAL(d.getMetaInfo(), MetaInfo());
+ BOOST_CHECK_EQUAL(d.getContentType(), tlv::ContentType_Blob);
+ BOOST_CHECK_EQUAL(d.getFreshnessPeriod(), 0_ms);
+ BOOST_CHECK_EQUAL(d.getFinalBlock().has_value(), false);
BOOST_CHECK_EQUAL(d.getContent().value_size(), 0);
BOOST_CHECK_EQUAL(d.getSignature().getType(), tlv::DigestSha256);
BOOST_CHECK_EQUAL(d.getSignature().getValue().value_size(), 32);
@@ -379,8 +383,6 @@
"sha256digest=28bad4b5275bd392dbb670c75cf0b66f13f7942b21e80f55c0e86b374753a548");
}
-// ---- operators ----
-
BOOST_AUTO_TEST_CASE(Equality)
{
Data a;
diff --git a/tests/unit/interest.t.cpp b/tests/unit/interest.t.cpp
index e7354e9..75aba88 100644
--- a/tests/unit/interest.t.cpp
+++ b/tests/unit/interest.t.cpp
@@ -101,8 +101,6 @@
BOOST_CHECK(i2.getHopLimit() == nullopt);
BOOST_CHECK_EQUAL(i2.hasApplicationParameters(), false);
BOOST_CHECK_EQUAL(i2.isParametersDigestValid(), true);
-
- BOOST_CHECK_EQUAL(i1, i2);
}
BOOST_AUTO_TEST_CASE(Full)
@@ -144,8 +142,6 @@
BOOST_CHECK(i2.getHopLimit() == nullopt);
BOOST_CHECK_EQUAL(i2.hasApplicationParameters(), false);
BOOST_CHECK_EQUAL(i2.isParametersDigestValid(), true);
-
- BOOST_CHECK_EQUAL(i1, i2);
}
BOOST_AUTO_TEST_CASE(ParametersSha256DigestComponent)
@@ -884,86 +880,6 @@
BOOST_CHECK_EQUAL(i.isParametersDigestValid(), true);
}
-BOOST_AUTO_TEST_CASE(Equality)
-{
- Interest a;
- Interest b;
-
- // if nonce is not set, it would be set to a random value
- a.setNonce(1);
- b.setNonce(1);
-
- BOOST_CHECK_EQUAL(a == b, true);
- BOOST_CHECK_EQUAL(a != b, false);
-
- // compare Name
- a.setName("/A");
- BOOST_CHECK_EQUAL(a == b, false);
- BOOST_CHECK_EQUAL(a != b, true);
-
- b.setName("/B");
- BOOST_CHECK_EQUAL(a == b, false);
- BOOST_CHECK_EQUAL(a != b, true);
-
- b.setName("/A");
- BOOST_CHECK_EQUAL(a == b, true);
- BOOST_CHECK_EQUAL(a != b, false);
-
- // compare Selectors
- a.setChildSelector(1);
- BOOST_CHECK_EQUAL(a == b, false);
- BOOST_CHECK_EQUAL(a != b, true);
-
- b.setChildSelector(1);
- BOOST_CHECK_EQUAL(a == b, true);
- BOOST_CHECK_EQUAL(a != b, false);
-
- // compare ForwardingHint
- a.setForwardingHint({{1, "/H"}});
- BOOST_CHECK_EQUAL(a == b, false);
- BOOST_CHECK_EQUAL(a != b, true);
-
- b.setForwardingHint({{1, "/H"}});
- BOOST_CHECK_EQUAL(a == b, true);
- BOOST_CHECK_EQUAL(a != b, false);
-
- // compare Nonce
- a.setNonce(100);
- BOOST_CHECK_EQUAL(a == b, false);
- BOOST_CHECK_EQUAL(a != b, true);
-
- b.setNonce(100);
- BOOST_CHECK_EQUAL(a == b, true);
- BOOST_CHECK_EQUAL(a != b, false);
-
- // compare InterestLifetime
- a.setInterestLifetime(10_s);
- BOOST_CHECK_EQUAL(a == b, false);
- BOOST_CHECK_EQUAL(a != b, true);
-
- b.setInterestLifetime(10_s);
- BOOST_CHECK_EQUAL(a == b, true);
- BOOST_CHECK_EQUAL(a != b, false);
-
- // compare HopLimit
- a.setHopLimit(255);
- BOOST_CHECK_EQUAL(a == b, false);
- BOOST_CHECK_EQUAL(a != b, true);
-
- b.setHopLimit(255);
- BOOST_CHECK_EQUAL(a == b, true);
- BOOST_CHECK_EQUAL(a != b, false);
-
- // compare ApplicationParameters
- a.setApplicationParameters("2404C0C1C2C3"_block);
- BOOST_CHECK_EQUAL(a == b, false);
- BOOST_CHECK_EQUAL(a != b, true);
-
- b.setApplicationParameters("2404C0C1C2C3"_block);
- BOOST_CHECK_EQUAL(a == b, true);
- BOOST_CHECK_EQUAL(a != b, false);
-}
-
BOOST_AUTO_TEST_SUITE_END() // TestInterest
} // namespace tests
diff --git a/tests/unit/meta-info.t.cpp b/tests/unit/meta-info.t.cpp
index e6ad757..e5229bf 100644
--- a/tests/unit/meta-info.t.cpp
+++ b/tests/unit/meta-info.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -29,51 +29,49 @@
BOOST_AUTO_TEST_SUITE(TestMetaInfo)
-BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES(EncodeDecodeEquality, 1)
-BOOST_AUTO_TEST_CASE(EncodeDecodeEquality)
+BOOST_AUTO_TEST_CASE(EncodeDecode)
{
// default values
MetaInfo a("1406 type=180100 freshness=190100"_block);
BOOST_CHECK_EQUAL(a.getType(), tlv::ContentType_Blob);
BOOST_CHECK_EQUAL(a.getFreshnessPeriod(), 0_ms);
- BOOST_CHECK(!a.getFinalBlock());
- BOOST_CHECK_EQUAL(a, a);
+ BOOST_CHECK(a.getFinalBlock() == nullopt);
MetaInfo b;
- BOOST_CHECK_NE(a, b);
+ BOOST_CHECK_NE(a.wireEncode(), b.wireEncode());
b.setType(a.getType());
b.setFreshnessPeriod(a.getFreshnessPeriod());
b.setFinalBlock(a.getFinalBlock());
+ BOOST_CHECK_NE(a.wireEncode(), b.wireEncode());
BOOST_CHECK_EQUAL(b.wireEncode(), "1400"_block);
- BOOST_CHECK_EQUAL(a, b); // expected failure #4569
// non-default values
- Block wire2 = "140C type=180101 freshness=190266B2 finalblock=1A03080141"_block;
+ Block wire2("140C type=180101 freshness=190266B2 finalblock=1A03080141"_block);
a.wireDecode(wire2);
BOOST_CHECK_EQUAL(a.getType(), tlv::ContentType_Link);
BOOST_CHECK_EQUAL(a.getFreshnessPeriod(), 26290_ms);
+ BOOST_REQUIRE(a.getFinalBlock().has_value());
BOOST_CHECK_EQUAL(*a.getFinalBlock(), name::Component("A"));
- BOOST_CHECK_NE(a, b);
+ BOOST_CHECK_NE(a.wireEncode(), b.wireEncode());
b.setType(a.getType());
b.setFreshnessPeriod(a.getFreshnessPeriod());
b.setFinalBlock(a.getFinalBlock());
BOOST_CHECK_EQUAL(b.wireEncode(), wire2);
- BOOST_CHECK_EQUAL(a, b);
- // FinalBlockId is typed name component
+ // FinalBlockId is a typed name component
Block wire3 = "1405 finalblock=1A03DD0141"_block;
a.wireDecode(wire3);
BOOST_CHECK_EQUAL(a.getType(), tlv::ContentType_Blob);
BOOST_CHECK_EQUAL(a.getFreshnessPeriod(), 0_ms);
+ BOOST_REQUIRE(a.getFinalBlock().has_value());
BOOST_CHECK_EQUAL(*a.getFinalBlock(), name::Component::fromEscapedString("221=A"));
- BOOST_CHECK_NE(a, b);
+ BOOST_CHECK_NE(a.wireEncode(), b.wireEncode());
b.setType(a.getType());
b.setFreshnessPeriod(a.getFreshnessPeriod());
b.setFinalBlock(a.getFinalBlock());
BOOST_CHECK_EQUAL(b.wireEncode(), wire3);
- BOOST_CHECK_EQUAL(a, b);
}
BOOST_AUTO_TEST_CASE(AppMetaInfo)
diff --git a/tests/unit/mgmt/nfd/cs-info.t.cpp b/tests/unit/mgmt/nfd/cs-info.t.cpp
index 9c1999c..3bc5f7b 100644
--- a/tests/unit/mgmt/nfd/cs-info.t.cpp
+++ b/tests/unit/mgmt/nfd/cs-info.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2019 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -107,15 +107,15 @@
{
CsInfo csi;
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(csi),
- "CS: 0 entries, 0 max, admit disabled, serve disabled, 0 hits, 0 misses");
+ "CsInfo: 0 entries, 0 max, admit disabled, serve disabled, 0 hits, 0 misses");
csi = makeCsInfo();
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(csi),
- "CS: 5509 entries, 20177 max, admit disabled, serve enabled, 12951 hits, 28179 misses");
+ "CsInfo: 5509 entries, 20177 max, admit disabled, serve enabled, 12951 hits, 28179 misses");
csi.setEnableAdmit(true).setNHits(1).setNMisses(1);
BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(csi),
- "CS: 5509 entries, 20177 max, admit enabled, serve enabled, 1 hit, 1 miss");
+ "CsInfo: 5509 entries, 20177 max, admit enabled, serve enabled, 1 hit, 1 miss");
}
BOOST_AUTO_TEST_SUITE_END() // TestCsInfo
diff --git a/tests/unit/signature.t.cpp b/tests/unit/signature.t.cpp
deleted file mode 100644
index 0650b03..0000000
--- a/tests/unit/signature.t.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2013-2018 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library 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 Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#include "ndn-cxx/signature.hpp"
-#include "ndn-cxx/security/digest-sha256.hpp"
-#include "ndn-cxx/security/signature-sha256-with-rsa.hpp"
-
-#include "tests/boost-test.hpp"
-
-namespace ndn {
-namespace tests {
-
-BOOST_AUTO_TEST_SUITE(TestSignature)
-
-BOOST_AUTO_TEST_CASE(Equality)
-{
- Signature a;
- Signature b;
-
- BOOST_CHECK_EQUAL(a == b, true);
- BOOST_CHECK_EQUAL(a != b, false);
-
- a = SignatureSha256WithRsa();
- BOOST_CHECK_EQUAL(a == b, false);
- BOOST_CHECK_EQUAL(a != b, true);
-
- b = SignatureSha256WithRsa();
- static const uint8_t someData[256] = {};
- Block signatureValue = makeBinaryBlock(tlv::SignatureValue, someData, sizeof(someData));
- b.setValue(signatureValue);
- BOOST_CHECK_EQUAL(a == b, false);
- BOOST_CHECK_EQUAL(a != b, true);
-
- a.setValue(signatureValue);
- BOOST_CHECK_EQUAL(a == b, true);
- BOOST_CHECK_EQUAL(a != b, false);
-
- a = DigestSha256();
- b = SignatureSha256WithRsa();
- BOOST_CHECK_EQUAL(a == b, false);
- BOOST_CHECK_EQUAL(a != b, true);
-
- b = DigestSha256();
- BOOST_CHECK_EQUAL(a == b, true);
- BOOST_CHECK_EQUAL(a != b, false);
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestSignature
-
-} // namespace tests
-} // namespace ndn