management: add Flags and Mask fields to faces/create and faces/update
refs #3731
Change-Id: I35fb84a875767649da0cb354be5e5c07de179198
diff --git a/tests/unit-tests/management/nfd-control-parameters.t.cpp b/tests/unit-tests/management/nfd-control-parameters.t.cpp
index 5a3a864..e12d675 100644
--- a/tests/unit-tests/management/nfd-control-parameters.t.cpp
+++ b/tests/unit-tests/management/nfd-control-parameters.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -34,18 +34,21 @@
ControlParameters parameters;
parameters.setUri("tcp4://192.0.2.1:6363");
parameters.setFacePersistency(ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
+ parameters.setFlags(1);
+ parameters.setMask(1);
Block wire = parameters.wireEncode();
ControlParameters decoded(wire);
BOOST_CHECK_EQUAL(decoded.getUri(), "tcp4://192.0.2.1:6363");
BOOST_CHECK_EQUAL(decoded.getFacePersistency(), ndn::nfd::FacePersistency::FACE_PERSISTENCY_PERSISTENT);
+ BOOST_CHECK_EQUAL(decoded.getFlags(), 1);
+ BOOST_CHECK_EQUAL(decoded.getMask(), 1);
BOOST_CHECK_EQUAL(decoded.hasName(), false);
BOOST_CHECK_EQUAL(decoded.hasFaceId(), false);
BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false);
BOOST_CHECK_EQUAL(decoded.hasOrigin(), false);
BOOST_CHECK_EQUAL(decoded.hasCost(), false);
- BOOST_CHECK_EQUAL(decoded.hasFlags(), false);
BOOST_CHECK_EQUAL(decoded.hasStrategy(), false);
BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false);
}
@@ -89,6 +92,7 @@
BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false);
BOOST_CHECK_EQUAL(decoded.hasOrigin(), false);
BOOST_CHECK_EQUAL(decoded.hasFlags(), false);
+ BOOST_CHECK_EQUAL(decoded.hasMask(), false);
BOOST_CHECK_EQUAL(decoded.hasStrategy(), false);
BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false);
BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false);
@@ -112,6 +116,7 @@
BOOST_CHECK_EQUAL(decoded.hasOrigin(), false);
BOOST_CHECK_EQUAL(decoded.hasCost(), false);
BOOST_CHECK_EQUAL(decoded.hasFlags(), false);
+ BOOST_CHECK_EQUAL(decoded.hasMask(), false);
BOOST_CHECK_EQUAL(decoded.hasExpirationPeriod(), false);
BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false);
}
@@ -138,10 +143,128 @@
BOOST_CHECK_EQUAL(decoded.hasUri(), false);
BOOST_CHECK_EQUAL(decoded.hasLocalControlFeature(), false);
+ BOOST_CHECK_EQUAL(decoded.hasMask(), false);
BOOST_CHECK_EQUAL(decoded.hasStrategy(), false);
BOOST_CHECK_EQUAL(decoded.hasFacePersistency(), false);
}
+BOOST_AUTO_TEST_CASE(FlagsAndMask)
+{
+ ControlParameters p;
+
+ BOOST_CHECK(!p.hasFlags());
+ BOOST_CHECK(!p.hasMask());
+ BOOST_CHECK(!p.hasFlagBit(0));
+ BOOST_CHECK(!p.getFlagBit(0));
+
+ // Set bit 2 to true (change Mask)
+ p.setFlagBit(2, true);
+ // 2^2 = 4
+ BOOST_CHECK_EQUAL(p.getFlags(), 4);
+ BOOST_CHECK_EQUAL(p.getMask(), 4);
+ BOOST_CHECK(p.hasFlagBit(2));
+ BOOST_CHECK(p.getFlagBit(2));
+ BOOST_CHECK(!p.hasFlagBit(1));
+ BOOST_CHECK(!p.getFlagBit(1));
+
+ // Set bit 3 to true (no change to Mask)
+ p.setFlagBit(3, true, false);
+ // 2^3 + 2^2 = 12
+ BOOST_CHECK_EQUAL(p.getFlags(), 12);
+ // 2^2 = 4
+ BOOST_CHECK_EQUAL(p.getMask(), 4);
+ BOOST_CHECK(!p.hasFlagBit(3));
+ BOOST_CHECK(p.getFlagBit(3));
+ BOOST_CHECK(p.hasFlagBit(2));
+ BOOST_CHECK(p.getFlagBit(2));
+
+ // Set bit 1 to false (change Mask)
+ p.setFlagBit(1, false);
+ // 2^3 + 2^2 = 12
+ BOOST_CHECK_EQUAL(p.getFlags(), 12);
+ // 2^2 + 2^1 = 6
+ BOOST_CHECK_EQUAL(p.getMask(), 6);
+ BOOST_CHECK(!p.hasFlagBit(3));
+ BOOST_CHECK(p.getFlagBit(3));
+ BOOST_CHECK(p.hasFlagBit(2));
+ BOOST_CHECK(p.getFlagBit(2));
+ BOOST_CHECK(p.hasFlagBit(1));
+ BOOST_CHECK(!p.getFlagBit(1));
+
+ // Set bit 2 to false (change Mask)
+ p.setFlagBit(2, false);
+ // 2^3 = 8
+ BOOST_CHECK_EQUAL(p.getFlags(), 8);
+ // 2^2 + 2^1 = 6
+ BOOST_CHECK_EQUAL(p.getMask(), 6);
+ BOOST_CHECK(!p.hasFlagBit(3));
+ BOOST_CHECK(p.getFlagBit(3));
+ BOOST_CHECK(p.hasFlagBit(2));
+ BOOST_CHECK(!p.getFlagBit(2));
+ BOOST_CHECK(p.hasFlagBit(1));
+ BOOST_CHECK(!p.getFlagBit(1));
+
+ // Set bit 0 to true (change Mask)
+ p.setFlagBit(0, true);
+ // 2^3 + 2^0 = 9
+ BOOST_CHECK_EQUAL(p.getFlags(), 9);
+ // 2^2 + 2^1 + 2^0 = 7
+ BOOST_CHECK_EQUAL(p.getMask(), 7);
+ BOOST_CHECK(p.hasFlagBit(0));
+ BOOST_CHECK(p.getFlagBit(0));
+
+ // Unset bit 0
+ p.unsetFlagBit(0);
+ BOOST_REQUIRE(p.hasFlags());
+ BOOST_REQUIRE(p.hasMask());
+ // 2^3 + 2^0 = 9
+ BOOST_CHECK_EQUAL(p.getFlags(), 9);
+ // 2^2 + 2^1 = 6
+ BOOST_CHECK_EQUAL(p.getMask(), 6);
+ BOOST_CHECK(p.hasFlagBit(1));
+ BOOST_CHECK(!p.hasFlagBit(0));
+ BOOST_CHECK(p.getFlagBit(0));
+
+ // Unset bit 3 (already unset in Mask, so no change)
+ p.unsetFlagBit(3);
+ BOOST_REQUIRE(p.hasFlags());
+ BOOST_REQUIRE(p.hasMask());
+ // 2^3 + 2^0 = 9
+ BOOST_CHECK_EQUAL(p.getFlags(), 9);
+ // 2^2 + 2^1 = 6
+ BOOST_CHECK_EQUAL(p.getMask(), 6);
+ BOOST_CHECK(!p.hasFlagBit(3));
+ BOOST_CHECK(p.getFlagBit(3));
+
+ // Unset bit 2
+ p.unsetFlagBit(2);
+ BOOST_REQUIRE(p.hasFlags());
+ BOOST_REQUIRE(p.hasMask());
+ // 2^3 + 2^0 = 9
+ BOOST_CHECK_EQUAL(p.getFlags(), 9);
+ // 2^1 = 2
+ BOOST_CHECK_EQUAL(p.getMask(), 2);
+ BOOST_CHECK(!p.hasFlagBit(2));
+ BOOST_CHECK(!p.getFlagBit(2));
+
+ // Unset bit 1
+ // Flags and Mask fields will be deleted as Mask is now 0
+ p.unsetFlagBit(1);
+ BOOST_CHECK(!p.hasFlags());
+ BOOST_CHECK(!p.hasMask());
+ BOOST_CHECK(!p.hasFlagBit(3));
+ BOOST_CHECK(!p.getFlagBit(3));
+ BOOST_CHECK(!p.hasFlagBit(2));
+ BOOST_CHECK(!p.getFlagBit(2));
+ BOOST_CHECK(!p.hasFlagBit(1));
+ BOOST_CHECK(!p.getFlagBit(1));
+ BOOST_CHECK(!p.hasFlagBit(0));
+ BOOST_CHECK(!p.getFlagBit(0));
+
+ BOOST_CHECK_THROW(p.setFlagBit(64, true), std::out_of_range);
+ BOOST_CHECK_THROW(p.unsetFlagBit(64), std::out_of_range);
+}
+
BOOST_AUTO_TEST_SUITE_END()
} // namespace tests