data+interest+selectors+meta-info+signature: Implementing EqualityComparable concept
Change-Id: I54f04820861bdc7b4e001949f1ba8d62f9a66786
diff --git a/tests/test-data.cpp b/tests/test-data.cpp
index 30d39df..1a3b97e 100644
--- a/tests/test-data.cpp
+++ b/tests/test-data.cpp
@@ -14,6 +14,10 @@
BOOST_AUTO_TEST_SUITE(TestData)
+BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Data>));
+BOOST_CONCEPT_ASSERT((boost::EqualityComparable<MetaInfo>));
+BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Signature>));
+
const uint8_t Content1[] = {0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x21};
const uint8_t Data1[] = {
@@ -86,6 +90,116 @@
const uint8_t MetaInfo3[] = {0x14, 0x17, 0x18, 0x01, 0x01, 0x19, 0x02, 0x27, 0x10, 0x1a, 0x0e, 0x08, 0x0c, 0x68, 0x65,
0x6c, 0x6c, 0x6f, 0x2c, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21};
+BOOST_AUTO_TEST_CASE(DataEqualityChecks)
+{
+ using namespace time;
+
+ Data a;
+ Data b;
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ a.setName("ndn:/A");
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setName("ndn:/B");
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setName("ndn:/A");
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ a.setFreshnessPeriod(seconds(10));
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setFreshnessPeriod(seconds(10));
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ static const uint8_t someData[] = "someData";
+ a.setContent(someData, sizeof(someData));
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setContent(someData, sizeof(someData));
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ a.setSignature(SignatureSha256WithRsa());
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setSignature(SignatureSha256WithRsa());
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+}
+
+BOOST_AUTO_TEST_CASE(MetaInfoEqualityChecks)
+{
+ using namespace time;
+
+ MetaInfo a;
+ MetaInfo b;
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ a.setFreshnessPeriod(seconds(10));
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setFreshnessPeriod(milliseconds(90000));
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setFreshnessPeriod(milliseconds(10000));
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ a.setType(10);
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setType(10);
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+}
+
+BOOST_AUTO_TEST_CASE(SignatureEqualityChecks)
+{
+ 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 = dataBlock(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 = SignatureSha256();
+ b = SignatureSha256WithRsa();
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b = SignatureSha256();
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+}
+
class TestDataFixture
{
public:
@@ -102,8 +216,7 @@
CryptoPP::RSA::PublicKey publicKey_;
};
-
-BOOST_FIXTURE_TEST_CASE (Decode, TestDataFixture)
+BOOST_FIXTURE_TEST_CASE(Decode, TestDataFixture)
{
Block dataBlock(Data1, sizeof(Data1));
@@ -132,7 +245,7 @@
BOOST_REQUIRE_EQUAL(signatureVerified, true);
}
-BOOST_FIXTURE_TEST_CASE (Encode, TestDataFixture)
+BOOST_FIXTURE_TEST_CASE(Encode, TestDataFixture)
{
// manual data packet creation for now
@@ -176,9 +289,9 @@
signer.Sign(rng_, hash, buf);
Tlv::writeVarNumber(os, buf.size());
- os.write(reinterpret_cast<const char *> (buf.BytePtr()), buf.size());
+ os.write(reinterpret_cast<const char *>(buf.BytePtr()), buf.size());
- ndn::Block signatureValue (Block(os.buf()));
+ ndn::Block signatureValue(Block(os.buf()));
Signature signature(signatureInfo, signatureValue);
@@ -191,7 +304,7 @@
dataBlock.begin(), dataBlock.end());
}
-BOOST_AUTO_TEST_CASE (EncodeMetaInfo)
+BOOST_AUTO_TEST_CASE(EncodeMetaInfo)
{
MetaInfo meta;
meta.setType(MetaInfo::TYPE_DEFAULT);
@@ -212,7 +325,7 @@
meta.wireEncode().begin(), meta.wireEncode().end());
}
-BOOST_AUTO_TEST_CASE (DecodeMetaInfo)
+BOOST_AUTO_TEST_CASE(DecodeMetaInfo)
{
MetaInfo meta(Block(MetaInfo1, sizeof(MetaInfo1)));
BOOST_CHECK_EQUAL(meta.getType(), static_cast<uint32_t>(MetaInfo::TYPE_DEFAULT));
diff --git a/tests/test-interest.cpp b/tests/test-interest.cpp
index 3da58ec..da6c2e3 100644
--- a/tests/test-interest.cpp
+++ b/tests/test-interest.cpp
@@ -15,6 +15,9 @@
BOOST_AUTO_TEST_SUITE(TestInterest)
+BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Interest>));
+BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Selectors>));
+
const uint8_t Interest1[] = {
0x05, 0x59, // NDN Interest
0x07, 0x14, // Name
@@ -65,6 +68,149 @@
0x01
};
+BOOST_AUTO_TEST_CASE(InterestEqualityChecks)
+{
+ // Interest ::= INTEREST-TYPE TLV-LENGTH
+ // Name
+ // Selectors?
+ // Nonce
+ // Scope?
+ // InterestLifetime?
+
+ Interest a;
+ Interest b;
+
+ // if nonce is not set, it will be set to a random value
+ a.setNonce(1);
+ b.setNonce(1);
+
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ // check comparison on Name
+ a.setName("ndn:/A");
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setName("ndn:/B");
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setName("ndn:/A");
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ // check comparison on 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);
+
+ // check comparison on 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);
+
+ // check comparison on Nonce
+ a.setScope(1);
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setScope(1);
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ // check comparison on InterestLifetime
+ a.setInterestLifetime(time::seconds(10));
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setInterestLifetime(time::seconds(10));
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+}
+
+BOOST_AUTO_TEST_CASE(SelectorsEqualityChecks)
+{
+ // Selectors ::= SELECTORS-TYPE TLV-LENGTH
+ // MinSuffixComponents?
+ // MaxSuffixComponents?
+ // PublisherPublicKeyLocator?
+ // Exclude?
+ // ChildSelector?
+ // MustBeFresh?
+
+ Selectors a;
+ Selectors b;
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ // MinSuffixComponents
+ a.setMinSuffixComponents(1);
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setMinSuffixComponents(2);
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setMinSuffixComponents(1);
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ // MaxSuffixComponents
+ a.setMaxSuffixComponents(10);
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setMaxSuffixComponents(10);
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ // PublisherPublicKeyLocator
+ a.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setPublisherPublicKeyLocator(KeyLocator("/key/Locator/name"));
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ // Exclude
+ a.setExclude(Exclude().excludeOne(name::Component("exclude")));
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setExclude(Exclude().excludeOne(name::Component("exclude")));
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ // ChildSelector
+ 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);
+
+ // MustBeFresh
+ a.setMustBeFresh(true);
+ BOOST_CHECK_EQUAL(a == b, false);
+ BOOST_CHECK_EQUAL(a != b, true);
+
+ b.setMustBeFresh(true);
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+}
+
BOOST_AUTO_TEST_CASE(Decode)
{
Block interestBlock(Interest1, sizeof(Interest1));