interest: Interest::matchesData function
refs #1157
Change-Id: I5b74367cb1afed75728e2d5092ced5d269332f9d
diff --git a/tests/key-locator.cpp b/tests/key-locator.cpp
new file mode 100644
index 0000000..00f4ff9
--- /dev/null
+++ b/tests/key-locator.cpp
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * See COPYING for copyright and distribution information.
+ */
+
+#include "key-locator.hpp"
+
+#include <boost/test/unit_test.hpp>
+#include <boost/concept_check.hpp>
+
+namespace ndn {
+
+BOOST_AUTO_TEST_SUITE(TestKeyLocator)
+
+BOOST_AUTO_TEST_CASE(Equality)
+{
+ BOOST_CONCEPT_ASSERT((boost::EqualityComparable<KeyLocator>));
+
+ KeyLocator a;
+ KeyLocator 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);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn
diff --git a/tests/test-block.cpp b/tests/test-block.cpp
index 32cd8cd..1c7557d 100644
--- a/tests/test-block.cpp
+++ b/tests/test-block.cpp
@@ -3,10 +3,11 @@
* See COPYING for copyright and distribution information.
*/
-#include <boost/test/unit_test.hpp>
-
#include "encoding/encoding-buffer.hpp"
+#include <boost/test/unit_test.hpp>
+#include <boost/concept_check.hpp>
+
using namespace std;
namespace ndn {
@@ -563,6 +564,26 @@
BOOST_CHECK_THROW(testBlock = Block(stream), Tlv::Error);
}
+BOOST_AUTO_TEST_CASE(Equality)
+{
+ BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Block>));
+
+ Block a("\x08\x00", 2);
+ Block b("\x08\x00", 2);;
+ BOOST_CHECK_EQUAL(a == b, true);
+ BOOST_CHECK_EQUAL(a != b, false);
+
+ Block c("\x06\x00", 2);
+ Block d("\x08\x00", 2);;
+ BOOST_CHECK_EQUAL(c == d, false);
+ BOOST_CHECK_EQUAL(c != d, true);
+
+ Block e("\x06\x00", 2);
+ Block f("\x06\x01\xcc", 3);;
+ BOOST_CHECK_EQUAL(e == f, false);
+ BOOST_CHECK_EQUAL(e != f, true);
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace ndn
diff --git a/tests/test-interest.cpp b/tests/test-interest.cpp
index 2583f98..321685e 100644
--- a/tests/test-interest.cpp
+++ b/tests/test-interest.cpp
@@ -3,9 +3,12 @@
* See COPYING for copyright and distribution information.
*/
-#include <boost/test/unit_test.hpp>
-
#include "interest.hpp"
+#include "data.hpp"
+#include "security/signature-sha256-with-rsa.hpp"
+#include "security/signature-sha256.hpp"
+
+#include <boost/test/unit_test.hpp>
using namespace std;
namespace ndn {
@@ -230,6 +233,49 @@
BOOST_CHECK_EQUAL(&payload, &wireBlock);
}
+BOOST_AUTO_TEST_CASE(MatchesData)
+{
+ Interest interest;
+ interest.setName("ndn:/A")
+ .setMinSuffixComponents(2)
+ .setMaxSuffixComponents(2)
+ .setPublisherPublicKeyLocator(KeyLocator("ndn:/B"))
+ .setExclude(Exclude().excludeBefore(name::Component("C")));
+
+ Data data("ndn:/A/D");
+ SignatureSha256WithRsa signature;
+ signature.setKeyLocator(KeyLocator("ndn:/B"));
+ data.setSignature(signature);
+ BOOST_CHECK_EQUAL(interest.matchesData(data), true);
+
+ Data data1 = data;
+ data1.setName("ndn:/A");// violates MinSuffixComponents
+ BOOST_CHECK_EQUAL(interest.matchesData(data1), false);
+
+ Data data2 = data;
+ data2.setName("ndn:/A/E/F");// violates MaxSuffixComponents
+ BOOST_CHECK_EQUAL(interest.matchesData(data2), false);
+
+ Data data3 = data;
+ SignatureSha256WithRsa signature3;
+ signature3.setKeyLocator(KeyLocator("ndn:/G"));// violates PublisherPublicKeyLocator
+ data3.setSignature(signature3);
+ BOOST_CHECK_EQUAL(interest.matchesData(data3), false);
+
+ Data data4 = data;
+ SignatureSha256 signature4;// violates PublisherPublicKeyLocator
+ data4.setSignature(signature4);
+ BOOST_CHECK_EQUAL(interest.matchesData(data4), false);
+
+ Data data5 = data;
+ data5.setName("ndn:/A/C");// violates Exclude
+ BOOST_CHECK_EQUAL(interest.matchesData(data5), false);
+
+ Data data6 = data;
+ data6.setName("ndn:/H/I");// violates Name
+ BOOST_CHECK_EQUAL(interest.matchesData(data6), false);
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace ndn