tests: use BOOST_TEST_CONTEXT and BOOST_DATA_TEST_CASE where possible

Fix the last two "CanBePrefix unset" warnings in unit tests

Change-Id: Ifd2420ae98e7c4741a1c20e7fa0d52f74d7178c8
diff --git a/tests/unit/security/certificate-fetcher-offline.t.cpp b/tests/unit/security/certificate-fetcher-offline.t.cpp
index ac1e9ee..f674993 100644
--- a/tests/unit/security/certificate-fetcher-offline.t.cpp
+++ b/tests/unit/security/certificate-fetcher-offline.t.cpp
@@ -21,7 +21,6 @@
 
 #include "ndn-cxx/security/certificate-fetcher-offline.hpp"
 #include "ndn-cxx/security/validation-policy-simple-hierarchy.hpp"
-#include "ndn-cxx/util/scope.hpp"
 
 #include "tests/boost-test.hpp"
 #include "tests/unit/security/validator-fixture.hpp"
@@ -31,8 +30,6 @@
 inline namespace v2 {
 namespace tests {
 
-using namespace ndn::tests;
-
 BOOST_AUTO_TEST_SUITE(Security)
 
 class CertificateFetcherOfflineWrapper : public CertificateFetcherOffline
@@ -48,23 +45,18 @@
 
 BOOST_FIXTURE_TEST_SUITE(TestCertificateFetcherOffline, CertificateFetcherOfflineFixture)
 
-using Packets = boost::mpl::vector<Interest, Data>;
+using Packets = boost::mpl::vector<InterestV03Pkt, DataPkt>;
 
 BOOST_AUTO_TEST_CASE_TEMPLATE(Validate, Packet, Packets)
 {
-  // Can't set CanBePrefix on Interests in this test case because of template
-  // TODO: Remove in #4582
-  auto guard = make_scope_exit([] { Interest::s_errorIfCanBePrefixUnset = true; });
-  Interest::s_errorIfCanBePrefixUnset = false;
+  const Name name = "/Security/ValidatorFixture/Sub1/Packet";
 
-  Packet unsignedPacket("/Security/ValidatorFixture/Sub1/Packet");
-
-  Packet packet = unsignedPacket;
+  auto packet = Packet::makePacket(name);
   m_keyChain.sign(packet, signingByIdentity(subIdentity));
   VALIDATE_FAILURE(packet, "Should fail, as no cert should be requested");
   BOOST_CHECK_EQUAL(this->face.sentInterests.size(), 0);
 
-  packet = unsignedPacket;
+  packet = Packet::makePacket(name);
   m_keyChain.sign(packet, signingByIdentity(identity));
   VALIDATE_SUCCESS(packet, "Should succeed, as signed by trust anchor");
   BOOST_CHECK_EQUAL(this->face.sentInterests.size(), 0);
diff --git a/tests/unit/security/validation-policy-simple-hierarchy.t.cpp b/tests/unit/security/validation-policy-simple-hierarchy.t.cpp
index a6b6fdc..c0729f4 100644
--- a/tests/unit/security/validation-policy-simple-hierarchy.t.cpp
+++ b/tests/unit/security/validation-policy-simple-hierarchy.t.cpp
@@ -20,7 +20,6 @@
  */
 
 #include "ndn-cxx/security/validation-policy-simple-hierarchy.hpp"
-#include "ndn-cxx/util/scope.hpp"
 
 #include "tests/boost-test.hpp"
 #include "tests/unit/security/validator-fixture.hpp"
@@ -32,43 +31,36 @@
 inline namespace v2 {
 namespace tests {
 
-using namespace ndn::tests;
-
 BOOST_AUTO_TEST_SUITE(Security)
 BOOST_FIXTURE_TEST_SUITE(TestValidationPolicySimpleHierarchy,
                          HierarchicalValidatorFixture<ValidationPolicySimpleHierarchy>)
 
-using Packets = boost::mpl::vector<Interest, Data>;
+using Packets = boost::mpl::vector<InterestV03Pkt, DataPkt>;
 
 BOOST_AUTO_TEST_CASE_TEMPLATE(Validate, Packet, Packets)
 {
-  // Can't set CanBePrefix on Interests in this test case because of template
-  // TODO: Remove in #4582
-  auto guard = make_scope_exit([] { Interest::s_errorIfCanBePrefixUnset = true; });
-  Interest::s_errorIfCanBePrefixUnset = false;
+  const Name name = "/Security/ValidatorFixture/Sub1/Sub2/Packet";
 
-  Packet unsignedPacket("/Security/ValidatorFixture/Sub1/Sub2/Packet");
-
-  Packet packet = unsignedPacket;
+  auto packet = Packet::makePacket(name);
   VALIDATE_FAILURE(packet, "Unsigned");
 
-  packet = unsignedPacket;
+  packet = Packet::makePacket(name);
   m_keyChain.sign(packet, signingWithSha256());
   VALIDATE_FAILURE(packet, "Policy doesn't accept Sha256Digest signature");
 
-  packet = unsignedPacket;
+  packet = Packet::makePacket(name);
   m_keyChain.sign(packet, signingByIdentity(identity));
   VALIDATE_SUCCESS(packet, "Should get accepted, as signed by the anchor");
 
-  packet = unsignedPacket;
+  packet = Packet::makePacket(name);
   m_keyChain.sign(packet, signingByIdentity(subIdentity));
   VALIDATE_SUCCESS(packet, "Should get accepted, as signed by the policy-compliant cert");
 
-  packet = unsignedPacket;
+  packet = Packet::makePacket(name);
   m_keyChain.sign(packet, signingByIdentity(otherIdentity));
   VALIDATE_FAILURE(packet, "Should fail, as signed by the policy-violating cert");
 
-  packet = unsignedPacket;
+  packet = Packet::makePacket(name);
   m_keyChain.sign(packet, signingByIdentity(subSelfSignedIdentity));
   VALIDATE_FAILURE(packet, "Should fail, because subSelfSignedIdentity is not a trust anchor");
 
diff --git a/tests/unit/security/validator-fixture.hpp b/tests/unit/security/validator-fixture.hpp
index 8da34f0..343e363 100644
--- a/tests/unit/security/validator-fixture.hpp
+++ b/tests/unit/security/validator-fixture.hpp
@@ -185,6 +185,12 @@
     return name;
   }
 
+  static Data
+  makePacket(const Name& name)
+  {
+    return Data(name);
+  }
+
   static shared_ptr<ValidationState>
   makeState()
   {
@@ -203,6 +209,12 @@
   static Name
   makeName(Name name, KeyChain& keyChain);
 
+  static Interest
+  makePacket(const Name& name)
+  {
+    return Interest(name).setCanBePrefix(false);
+  }
+
   static shared_ptr<ValidationState>
   makeState()
   {
@@ -223,6 +235,12 @@
   static Name
   makeName(Name name, KeyChain& keyChain);
 
+  static Interest
+  makePacket(const Name& name)
+  {
+    return Interest(name).setCanBePrefix(false);
+  }
+
   static shared_ptr<ValidationState>
   makeState()
   {