interest: declare default CanBePrefix setting
refs #4581
Change-Id: I82de3b13c3010242fa7999a2564d4a5442dfd14b
diff --git a/tests/integrated/default-can-be-prefix-0.cpp b/tests/integrated/default-can-be-prefix-0.cpp
new file mode 100644
index 0000000..8be2c4f
--- /dev/null
+++ b/tests/integrated/default-can-be-prefix-0.cpp
@@ -0,0 +1,46 @@
+/* -*- 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.
+ */
+
+#define BOOST_TEST_MAIN 1
+#define BOOST_TEST_DYN_LINK 1
+#define BOOST_TEST_MODULE ndn-cxx Integrated Tests (DefaultCanBePrefix=0)
+
+#include "interest.hpp"
+
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(TestInterest)
+
+BOOST_AUTO_TEST_CASE(DefaultCanBePrefix0)
+{
+ Interest::setDefaultCanBePrefix(false);
+ Interest interest1;
+ Interest interest2(interest1.wireEncode());
+ BOOST_CHECK_EQUAL(interest2.getCanBePrefix(), false);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestInterest
+
+} // namespace tests
+} // namespace ndn
diff --git a/tests/integrated/default-can-be-prefix-1.cpp b/tests/integrated/default-can-be-prefix-1.cpp
new file mode 100644
index 0000000..e2071e1
--- /dev/null
+++ b/tests/integrated/default-can-be-prefix-1.cpp
@@ -0,0 +1,46 @@
+/* -*- 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.
+ */
+
+#define BOOST_TEST_MAIN 1
+#define BOOST_TEST_DYN_LINK 1
+#define BOOST_TEST_MODULE ndn-cxx Integrated Tests (DefaultCanBePrefix=1)
+
+#include "interest.hpp"
+
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(TestInterest)
+
+BOOST_AUTO_TEST_CASE(DefaultCanBePrefix1)
+{
+ Interest::setDefaultCanBePrefix(true);
+ Interest interest1;
+ Interest interest2(interest1.wireEncode());
+ BOOST_CHECK_EQUAL(interest2.getCanBePrefix(), true);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestInterest
+
+} // namespace tests
+} // namespace ndn
diff --git a/tests/integrated/default-can-be-prefix-unset.cpp b/tests/integrated/default-can-be-prefix-unset.cpp
new file mode 100644
index 0000000..88375da
--- /dev/null
+++ b/tests/integrated/default-can-be-prefix-unset.cpp
@@ -0,0 +1,47 @@
+/* -*- 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.
+ */
+
+#define BOOST_TEST_MAIN 1
+#define BOOST_TEST_DYN_LINK 1
+#define BOOST_TEST_MODULE ndn-cxx Integrated Tests (DefaultCanBePrefix=unset)
+
+#include "interest.hpp"
+
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace tests {
+
+BOOST_AUTO_TEST_SUITE(TestInterest)
+
+BOOST_AUTO_TEST_CASE(DefaultCanBePrefixUnset)
+{
+ Interest interest1;
+ BOOST_CHECK_THROW(interest1.wireEncode(), std::logic_error);
+ Interest::s_errorIfCanBePrefixUnset = false;
+ Interest interest2(interest1.wireEncode());
+ BOOST_CHECK_EQUAL(interest2.getCanBePrefix(), true);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestInterest
+
+} // namespace tests
+} // namespace ndn
diff --git a/tests/integrated/default-can-be-prefix.README.md b/tests/integrated/default-can-be-prefix.README.md
new file mode 100644
index 0000000..23b01ae
--- /dev/null
+++ b/tests/integrated/default-can-be-prefix.README.md
@@ -0,0 +1,10 @@
+# DefaultCanBePrefix test
+
+`default-can-be-prefix-*.cpp` verifies the effect of `Interest::setDefaultCanBePrefix`.
+They are written as integration tests because ndn-cxx unit tests are prohibited from calling `Interest::setDefaultCanBePrefix`.
+
+Manual verification steps:
+
+1. `default-can-be-prefix-unset` program should print a "CanBePrefix unset" warning to stderr.
+2. `default-can-be-prefix-0` and `default-can-be-prefix-1` test cases should not print that warning.
+
diff --git a/tests/integrated/face.cpp b/tests/integrated/face.cpp
index 2884ec6..adbe314 100644
--- a/tests/integrated/face.cpp
+++ b/tests/integrated/face.cpp
@@ -128,7 +128,7 @@
BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExpressInterestData, TransportType, Transports, FaceFixture<TransportType>)
{
int nData = 0;
- this->face.expressInterest(Interest("/"),
+ this->face.expressInterest(*makeInterest("/", true),
[&] (const Interest&, const Data&) { ++nData; },
[] (const Interest&, const lp::Nack&) { BOOST_ERROR("unexpected Nack"); },
[] (const Interest&) { BOOST_ERROR("unexpected timeout"); });
@@ -140,7 +140,7 @@
BOOST_FIXTURE_TEST_CASE_TEMPLATE(ExpressInterestNack, TransportType, Transports, FaceFixture<TransportType>)
{
int nNacks = 0;
- this->face.expressInterest(Interest("/localhost/non-existent-should-nack"),
+ this->face.expressInterest(*makeInterest("/localhost/non-existent-should-nack"),
[] (const Interest&, const Data&) { BOOST_ERROR("unexpected Data"); },
[&] (const Interest&, const lp::Nack&) { ++nNacks; },
[] (const Interest&) { BOOST_ERROR("unexpected timeout"); });
@@ -156,7 +156,7 @@
std::this_thread::sleep_for(std::chrono::milliseconds(200)); // wait for FIB update to take effect
int nTimeouts = 0;
- this->face.expressInterest(Interest("/localhost/non-existent-should-timeout", 1_s),
+ this->face.expressInterest(*makeInterest("/localhost/non-existent-should-timeout", false, 1_s),
[] (const Interest&, const Data&) { BOOST_ERROR("unexpected Data"); },
[] (const Interest&, const lp::Nack&) { BOOST_ERROR("unexpected Nack"); },
[&] (const Interest&) { ++nTimeouts; });
@@ -168,7 +168,7 @@
BOOST_FIXTURE_TEST_CASE_TEMPLATE(OversizedInterest, TransportType, Transports, FaceFixture<TransportType>)
{
BOOST_CHECK_THROW(do {
- this->face.expressInterest(Interest(makeVeryLongName()), nullptr, nullptr, nullptr);
+ this->face.expressInterest(*makeInterest(makeVeryLongName()), nullptr, nullptr, nullptr);
this->face.processEvents();
} while (false), Face::OversizedPacketError);
}
@@ -229,7 +229,7 @@
});
char interestOutcome;
- this->sendInterest(1_s, Interest("/Hello/World/regular", 50_ms), interestOutcome);
+ this->sendInterest(1_s, *makeInterest("/Hello/World/regular", false, 50_ms), interestOutcome);
this->face.processEvents();
BOOST_CHECK_EQUAL(interestOutcome, 'T');
@@ -254,10 +254,10 @@
BOOST_CHECK(!output.empty());
});
- this->sendInterest(200_ms, Interest("/Hello/World/a", 50_ms));
- this->sendInterest(300_ms, Interest("/Hello/World/a/b", 50_ms));
- this->sendInterest(400_ms, Interest("/Hello/World/a/b/c", 50_ms));
- this->sendInterest(500_ms, Interest("/Hello/World/a/b/d", 50_ms));
+ this->sendInterest(200_ms, *makeInterest("/Hello/World/a", false, 50_ms));
+ this->sendInterest(300_ms, *makeInterest("/Hello/World/a/b", false, 50_ms));
+ this->sendInterest(400_ms, *makeInterest("/Hello/World/a/b/c", false, 50_ms));
+ this->sendInterest(500_ms, *makeInterest("/Hello/World/a/b/d", false, 50_ms));
this->face.processEvents();
BOOST_CHECK_EQUAL(nRegSuccess, 1);
@@ -280,10 +280,10 @@
BOOST_CHECK(output.empty());
});
- this->sendInterest(200_ms, Interest("/Hello/World/a", 50_ms));
- this->sendInterest(300_ms, Interest("/Hello/World/a/b", 50_ms));
- this->sendInterest(400_ms, Interest("/Hello/World/a/b/c", 50_ms));
- this->sendInterest(500_ms, Interest("/Hello/World/a/b/d", 50_ms));
+ this->sendInterest(200_ms, *makeInterest("/Hello/World/a", false, 50_ms));
+ this->sendInterest(300_ms, *makeInterest("/Hello/World/a/b", false, 50_ms));
+ this->sendInterest(400_ms, *makeInterest("/Hello/World/a/b/c", false, 50_ms));
+ this->sendInterest(500_ms, *makeInterest("/Hello/World/a/b/d", false, 50_ms));
this->face.processEvents();
}
@@ -305,8 +305,8 @@
[] (const Name&, const std::string& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
char outcome1, outcome2;
- this->sendInterest(700_ms, Interest("/Hello/World/data", 50_ms), outcome1);
- this->sendInterest(800_ms, Interest("/Hello/World/nack", 50_ms), outcome2);
+ this->sendInterest(700_ms, *makeInterest("/Hello/World/data", false, 50_ms), outcome1);
+ this->sendInterest(800_ms, *makeInterest("/Hello/World/nack", false, 50_ms), outcome2);
this->face.processEvents();
BOOST_CHECK_EQUAL(outcome1, 'D');
@@ -324,7 +324,7 @@
nullptr,
[] (const Name&, const std::string& msg) { BOOST_ERROR("unexpected register prefix failure: " << msg); });
- this->sendInterest(1_s, Interest("/Hello/World/oversized", 50_ms));
+ this->sendInterest(1_s, *makeInterest("/Hello/World/oversized", true, 50_ms));
BOOST_CHECK_THROW(this->face.processEvents(), Face::OversizedPacketError);
}
@@ -335,12 +335,12 @@
BOOST_AUTO_TEST_CASE(ShutdownWhileSendInProgress) // Bug #3136
{
- this->face.expressInterest(Interest("/Hello/World"), nullptr, nullptr, nullptr);
+ this->face.expressInterest(*makeInterest("/Hello/World"), nullptr, nullptr, nullptr);
this->face.processEvents(1_s);
- this->face.expressInterest(Interest("/Bye/World/1"), nullptr, nullptr, nullptr);
- this->face.expressInterest(Interest("/Bye/World/2"), nullptr, nullptr, nullptr);
- this->face.expressInterest(Interest("/Bye/World/3"), nullptr, nullptr, nullptr);
+ this->face.expressInterest(*makeInterest("/Bye/World/1"), nullptr, nullptr, nullptr);
+ this->face.expressInterest(*makeInterest("/Bye/World/2"), nullptr, nullptr, nullptr);
+ this->face.expressInterest(*makeInterest("/Bye/World/3"), nullptr, nullptr, nullptr);
this->face.shutdown();
this->face.processEvents(1_s); // should not segfault