Adding schedule related classes: Schedule, RepetitiveInterval and Interval
Change-Id: Ia3fa750270f49c1b9e3bc4c6f67281c527910c55
Refs: #3118
diff --git a/tests/unit-tests/interval.t.cpp b/tests/unit-tests/interval.t.cpp
new file mode 100644
index 0000000..e9cf6d9
--- /dev/null
+++ b/tests/unit-tests/interval.t.cpp
@@ -0,0 +1,155 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
+ *
+ * ndn-group-encrypt is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-group-encrypt 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Zhiyi Zhang <dreamerbarrychang@gmail.com>
+ */
+
+#include "interval.hpp"
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace gep {
+namespace tests {
+
+using namespace boost::posix_time;
+
+BOOST_AUTO_TEST_SUITE(TestInterval)
+
+BOOST_AUTO_TEST_CASE(Construction)
+{
+ // construct with the right parameters
+ Interval interval1(from_iso_string("20150825T120000"),
+ from_iso_string("20150825T160000"));
+ BOOST_CHECK_EQUAL(to_iso_string(interval1.getStartTime()), "20150825T120000");
+ BOOST_CHECK_EQUAL(to_iso_string(interval1.getEndTime()), "20150825T160000");
+ BOOST_CHECK_EQUAL(interval1.isValid(), true);
+
+ // construct with the invalid interval
+ Interval interval2;
+ BOOST_CHECK_EQUAL(interval2.isValid(), false);
+
+ // construct with the empty interval
+ Interval interval3(true);
+ BOOST_CHECK_EQUAL(interval3.isValid(), true);
+ BOOST_CHECK_EQUAL(interval3.isEmpty(), true);
+}
+
+BOOST_AUTO_TEST_CASE(CoverTimePoint)
+{
+ Interval interval(from_iso_string("20150825T120000"),
+ from_iso_string("20150825T160000"));
+
+ TimeStamp tp1 = from_iso_string("20150825T120000");
+ TimeStamp tp2 = from_iso_string("20150825T130000");
+ TimeStamp tp3 = from_iso_string("20150825T170000");
+ TimeStamp tp4 = from_iso_string("20150825T110000");
+
+ BOOST_CHECK_EQUAL(interval.covers(tp1), true);
+ BOOST_CHECK_EQUAL(interval.covers(tp2), true);
+ BOOST_CHECK_EQUAL(interval.covers(tp3), false);
+ BOOST_CHECK_EQUAL(interval.covers(tp4), false);
+}
+
+BOOST_AUTO_TEST_CASE(IntersectionAndUnion)
+{
+ Interval interval1(from_iso_string("20150825T030000"),
+ from_iso_string("20150825T050000"));
+ // no intersection
+ Interval interval2(from_iso_string("20150825T050000"),
+ from_iso_string("20150825T070000"));
+ // no intersection
+ Interval interval3(from_iso_string("20150825T060000"),
+ from_iso_string("20150825T070000"));
+ // there's an intersection
+ Interval interval4(from_iso_string("20150825T010000"),
+ from_iso_string("20150825T040000"));
+ // right in the interval1, there's an intersection
+ Interval interval5(from_iso_string("20150825T030000"),
+ from_iso_string("20150825T040000"));
+ // wrap the interval1, there's an intersection
+ Interval interval6(from_iso_string("20150825T010000"),
+ from_iso_string("20150825T050000"));
+ // empty interval
+ Interval interval7(true);
+
+ Interval tempInterval = interval1;
+ tempInterval && interval2;
+ BOOST_CHECK_EQUAL(tempInterval.isEmpty(), true);
+
+ tempInterval = interval1;
+ BOOST_CHECK_THROW(tempInterval || interval2, Interval::Error);
+
+ tempInterval = interval1;
+ tempInterval && interval3;
+ BOOST_CHECK_EQUAL(tempInterval.isEmpty(), true);
+
+ tempInterval = interval1;
+ BOOST_CHECK_THROW(tempInterval || interval3, Interval::Error);
+
+ tempInterval = interval1;
+ tempInterval && interval4;
+ BOOST_CHECK_EQUAL(tempInterval.isEmpty(), false);
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getStartTime()), "20150825T030000");
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getEndTime()), "20150825T040000");
+
+ tempInterval = interval1;
+ tempInterval || interval4;
+ BOOST_CHECK_EQUAL(tempInterval.isEmpty(), false);
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getStartTime()), "20150825T010000");
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getEndTime()), "20150825T050000");
+
+ tempInterval = interval1;
+ tempInterval && interval5;
+ BOOST_CHECK_EQUAL(tempInterval.isEmpty(), false);
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getStartTime()), "20150825T030000");
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getEndTime()), "20150825T040000");
+
+ tempInterval = interval1;
+ tempInterval || interval5;
+ BOOST_CHECK_EQUAL(tempInterval.isEmpty(), false);
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getStartTime()), "20150825T030000");
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getEndTime()), "20150825T050000");
+
+ tempInterval = interval1;
+ tempInterval && interval6;
+ BOOST_CHECK_EQUAL(tempInterval.isEmpty(), false);
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getStartTime()), "20150825T030000");
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getEndTime()), "20150825T050000");
+
+ tempInterval = interval1;
+ tempInterval || interval6;
+ BOOST_CHECK_EQUAL(tempInterval.isEmpty(), false);
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getStartTime()), "20150825T010000");
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getEndTime()), "20150825T050000");
+
+ tempInterval = interval1;
+ tempInterval && interval7;
+ BOOST_CHECK_EQUAL(tempInterval.isEmpty(), true);
+
+ tempInterval = interval1;
+ tempInterval || interval7;
+ BOOST_CHECK_EQUAL(tempInterval.isEmpty(), false);
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getStartTime()), "20150825T030000");
+ BOOST_CHECK_EQUAL(to_iso_string(tempInterval.getEndTime()), "20150825T050000");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace gep
+} // namespace ndn
diff --git a/tests/unit-tests/repetitive-interval.t.cpp b/tests/unit-tests/repetitive-interval.t.cpp
new file mode 100644
index 0000000..65ac8ae
--- /dev/null
+++ b/tests/unit-tests/repetitive-interval.t.cpp
@@ -0,0 +1,207 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
+ *
+ * ndn-group-encrypt is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-group-encrypt 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Zhiyi Zhang <dreamerbarrychang@gmail.com>
+ */
+
+#include "repetitive-interval.hpp"
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace gep {
+namespace tests {
+
+using namespace boost::posix_time;
+
+BOOST_AUTO_TEST_SUITE(TestRepetitiveInterval)
+
+BOOST_AUTO_TEST_CASE(Construction)
+{
+ RepetitiveInterval repetitiveInterval1(from_iso_string("20150825T000000"),
+ from_iso_string("20150825T000000"),
+ 5, 10);
+
+ BOOST_CHECK_EQUAL(to_iso_string(repetitiveInterval1.getStartDate()), "20150825T000000");
+ BOOST_CHECK_EQUAL(to_iso_string(repetitiveInterval1.getEndDate()), "20150825T000000");
+ BOOST_CHECK_EQUAL(repetitiveInterval1.getIntervalStartHour(), 5);
+ BOOST_CHECK_EQUAL(repetitiveInterval1.getIntervalEndHour(), 10);
+
+ RepetitiveInterval repetitiveInterval2(from_iso_string("20150825T000000"),
+ from_iso_string("20150827T000000"),
+ 5, 10, 1, RepetitiveInterval::RepeatUnit::DAY);
+
+ BOOST_CHECK_EQUAL(repetitiveInterval2.getNRepeats(), 1);
+ BOOST_CHECK(repetitiveInterval2.getRepeatUnit() == RepetitiveInterval::RepeatUnit::DAY);
+
+ RepetitiveInterval repetitiveInterval3(from_iso_string("20150825T000000"),
+ from_iso_string("20151227T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::MONTH);
+
+ BOOST_CHECK_EQUAL(repetitiveInterval3.getNRepeats(), 2);
+ BOOST_CHECK(repetitiveInterval3.getRepeatUnit() == RepetitiveInterval::RepeatUnit::MONTH);
+
+ RepetitiveInterval repetitiveInterval4(from_iso_string("20150825T000000"),
+ from_iso_string("20301227T000000"),
+ 5, 10, 5, RepetitiveInterval::RepeatUnit::YEAR);
+
+ BOOST_CHECK_EQUAL(repetitiveInterval4.getNRepeats(), 5);
+ BOOST_CHECK(repetitiveInterval4.getRepeatUnit() == RepetitiveInterval::RepeatUnit::YEAR);
+
+ RepetitiveInterval repetitiveInterval5;
+
+ BOOST_CHECK_EQUAL(repetitiveInterval5.getNRepeats(), 0);
+ BOOST_CHECK(repetitiveInterval5.getRepeatUnit() == RepetitiveInterval::RepeatUnit::NONE);
+}
+
+BOOST_AUTO_TEST_CASE(CheckCoverTimePoint)
+{
+ ///////////////////////////////////////////// with the repeat unit DAY
+
+ RepetitiveInterval repetitiveInterval1(from_iso_string("20150825T000000"),
+ from_iso_string("20150925T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY);
+ Interval resultInterval;
+ bool isPositive = false;
+
+ TimeStamp tp1 = from_iso_string("20150825T050000");
+
+ std::tie(isPositive,resultInterval) = repetitiveInterval1.getInterval(tp1);
+ BOOST_CHECK_EQUAL(isPositive, true);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T050000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000");
+
+ TimeStamp tp2 = from_iso_string("20150902T060000");
+
+ std::tie(isPositive,resultInterval) = repetitiveInterval1.getInterval(tp2);
+ BOOST_CHECK_EQUAL(isPositive, true);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150902T050000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150902T100000");
+
+ TimeStamp tp3 = from_iso_string("20150929T040000");
+
+ BOOST_CHECK(std::get<0>(repetitiveInterval1.getInterval(tp3)) == false);
+
+ ///////////////////////////////////////////// with the repeat unit MONTH
+
+ RepetitiveInterval repetitiveInterval2(from_iso_string("20150825T000000"),
+ from_iso_string("20160825T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::MONTH);
+
+ TimeStamp tp4 = from_iso_string("20150825T050000");
+
+ std::tie(isPositive,resultInterval) = repetitiveInterval2.getInterval(tp4);
+ BOOST_CHECK_EQUAL(isPositive, true);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T050000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000");
+
+ TimeStamp tp5 = from_iso_string("20151025T060000");
+
+ std::tie(isPositive,resultInterval) = repetitiveInterval2.getInterval(tp5);
+ BOOST_CHECK_EQUAL(isPositive, true);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20151025T050000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20151025T100000");
+
+ TimeStamp tp6 = from_iso_string("20151226T050000");
+
+ BOOST_CHECK(std::get<0>(repetitiveInterval2.getInterval(tp6)) == false);
+
+ TimeStamp tp7 = from_iso_string("20151225T040000");
+
+ BOOST_CHECK(std::get<0>(repetitiveInterval2.getInterval(tp7)) == false);
+
+ ///////////////////////////////////////////// with the repeat unit YEAR
+
+ RepetitiveInterval repetitiveInterval3(from_iso_string("20150825T000000"),
+ from_iso_string("20300825T000000"),
+ 5, 10, 3, RepetitiveInterval::RepeatUnit::YEAR);
+
+ TimeStamp tp8 = from_iso_string("20150825T050000");
+
+ std::tie(isPositive,resultInterval) = repetitiveInterval3.getInterval(tp8);
+ BOOST_CHECK_EQUAL(isPositive, true);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T050000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000");
+
+ TimeStamp tp9 = from_iso_string("20180825T060000");
+
+ std::tie(isPositive,resultInterval) = repetitiveInterval3.getInterval(tp9);
+ BOOST_CHECK_EQUAL(isPositive, true);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20180825T050000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20180825T100000");
+
+ TimeStamp tp10 = from_iso_string("20180826T050000");
+ BOOST_CHECK(std::get<0>(repetitiveInterval3.getInterval(tp10)) == false);
+
+ TimeStamp tp11 = from_iso_string("20210825T040000");
+ BOOST_CHECK(std::get<0>(repetitiveInterval3.getInterval(tp11)) == false);
+
+ TimeStamp tp12 = from_iso_string("20300825T040000");
+ BOOST_CHECK(std::get<0>(repetitiveInterval3.getInterval(tp12)) == false);
+}
+
+const uint8_t REPETITIVE_INTERVAL[] = {
+ 0x8c, 0x2e, // RepetitiveInterval
+ 0x86, 0x0f,
+ 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x87, 0x0f,
+ 0x32, 0x30, 0x31, 0x35, 0x30, 0x39, 0x32, 0x31, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x88, 0x01,
+ 0x05,
+ 0x89, 0x01,
+ 0x0a,
+ 0x8a, 0x01,
+ 0x04,
+ 0x8b, 0x01,
+ 0x01
+};
+
+BOOST_AUTO_TEST_CASE(EncodeAndDecode)
+{
+ RepetitiveInterval repetitiveInterval1(from_iso_string("20150825T000000"),
+ from_iso_string("20150921T000000"),
+ 5, 10, 4, RepetitiveInterval::RepeatUnit::DAY);
+
+ Block block1 = repetitiveInterval1.wireEncode();
+ Block block2(REPETITIVE_INTERVAL, sizeof(REPETITIVE_INTERVAL));
+
+ BOOST_CHECK(block1 == block2);
+
+ RepetitiveInterval RepetitiveInterval2(block1);
+
+ BOOST_CHECK_EQUAL(to_iso_string(RepetitiveInterval2.getStartDate()), "20150825T000000");
+ BOOST_CHECK_EQUAL(to_iso_string(RepetitiveInterval2.getEndDate()), "20150921T000000");
+ BOOST_CHECK_EQUAL(RepetitiveInterval2.getIntervalStartHour(), 5);
+ BOOST_CHECK_EQUAL(RepetitiveInterval2.getIntervalEndHour(), 10);
+ BOOST_CHECK_EQUAL(RepetitiveInterval2.getNRepeats(), 4);
+ BOOST_CHECK(RepetitiveInterval2.getRepeatUnit() == RepetitiveInterval::RepeatUnit::DAY);
+
+ RepetitiveInterval repetitiveInterval3(block2);
+
+ BOOST_CHECK_EQUAL(to_iso_string(repetitiveInterval3.getStartDate()), "20150825T000000");
+ BOOST_CHECK_EQUAL(to_iso_string(repetitiveInterval3.getEndDate()), "20150921T000000");
+ BOOST_CHECK_EQUAL(repetitiveInterval3.getIntervalStartHour(), 5);
+ BOOST_CHECK_EQUAL(repetitiveInterval3.getIntervalEndHour(), 10);
+ BOOST_CHECK_EQUAL(repetitiveInterval3.getNRepeats(), 4);
+ BOOST_CHECK(repetitiveInterval3.getRepeatUnit() == RepetitiveInterval::RepeatUnit::DAY);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace gep
+} // namespace ndn
diff --git a/tests/unit-tests/schedule.t.cpp b/tests/unit-tests/schedule.t.cpp
new file mode 100644
index 0000000..80560c5
--- /dev/null
+++ b/tests/unit-tests/schedule.t.cpp
@@ -0,0 +1,211 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2015, Regents of the University of California
+ *
+ * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
+ *
+ * ndn-group-encrypt is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-group-encrypt 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Zhiyi Zhang <dreamerbarrychang@gmail.com>
+ */
+
+#include "schedule.hpp"
+#include "boost-test.hpp"
+
+namespace ndn {
+namespace gep {
+namespace tests {
+
+using namespace boost::posix_time;
+
+BOOST_AUTO_TEST_SUITE(TestSchedule)
+
+BOOST_AUTO_TEST_CASE(CalculateCoveringInterval)
+{
+ Schedule schedule;
+
+ RepetitiveInterval interval1(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY);
+ RepetitiveInterval interval2(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 6, 8, 1, RepetitiveInterval::RepeatUnit::DAY);
+ RepetitiveInterval interval3(from_iso_string("20150827T000000"),
+ from_iso_string("20150827T000000"),
+ 7, 8);
+ RepetitiveInterval interval4(from_iso_string("20150825T000000"),
+ from_iso_string("20150825T000000"),
+ 4, 7);
+
+ schedule.addWhiteInterval(interval1);
+ schedule.addWhiteInterval(interval2);
+ schedule.addWhiteInterval(interval4);
+ schedule.addBlackInterval(interval3);
+
+ Interval resultInterval;
+
+ // tp1 --> 8.25 4-10
+ TimeStamp tp1 = from_iso_string("20150825T063000");
+ resultInterval = schedule.getCoveringInterval(tp1);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T040000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000");
+
+ // tp2 --> 8.26 6-8
+ TimeStamp tp2 = from_iso_string("20150826T073000");
+ resultInterval = schedule.getCoveringInterval(tp2);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150826T060000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150826T080000");
+
+ // tp3 --> 8.27 5-7
+ TimeStamp tp3 = from_iso_string("20150827T053000");
+ resultInterval = schedule.getCoveringInterval(tp3);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150827T050000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150827T070000");
+
+ // tp4 --> 8.27 5-7
+ TimeStamp tp4 = from_iso_string("20150827T063000");
+ resultInterval = schedule.getCoveringInterval(tp4);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150827T050000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150827T070000");
+
+ // tp5 --> No
+ TimeStamp tp5 = from_iso_string("20150827T073000");
+ BOOST_CHECK_EQUAL(schedule.getCoveringInterval(tp5).isEmpty(), true);
+
+ // tp6 --> No
+ TimeStamp tp6 = from_iso_string("20150825T113000");
+ BOOST_CHECK_EQUAL(schedule.getCoveringInterval(tp6).isEmpty(), true);
+}
+
+const uint8_t SCHEDULE[] = {
+ 0x8f, 0xc4,// Schedule
+ 0x8d, 0x90,// WhiteIntervalList
+ /////
+ 0x8c, 0x2e, // RepetitiveInterval
+ 0x86, 0x0f,
+ 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x87, 0x0f,
+ 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x38, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x88, 0x01,
+ 0x05,
+ 0x89, 0x01,
+ 0x0a,
+ 0x8a, 0x01,
+ 0x02,
+ 0x8b, 0x01,
+ 0x01,
+ /////
+ 0x8c, 0x2e, // RepetitiveInterval
+ 0x86, 0x0f,
+ 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x87, 0x0f,
+ 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x38, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x88, 0x01,
+ 0x06,
+ 0x89, 0x01,
+ 0x08,
+ 0x8a, 0x01,
+ 0x01,
+ 0x8b, 0x01,
+ 0x01,
+ /////
+ 0x8c, 0x2e, // RepetitiveInterval
+ 0x86, 0x0f,
+ 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x87, 0x0f,
+ 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x88, 0x01,
+ 0x04,
+ 0x89, 0x01,
+ 0x07,
+ 0x8a, 0x01,
+ 0x00,
+ 0x8b, 0x01,
+ 0x00,
+ /////
+ 0x8e, 0x30, // BlackIntervalList
+ /////
+ 0x8c, 0x2e, // RepetitiveInterval
+ 0x86, 0x0f,
+ 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x37, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x87, 0x0f,
+ 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x37, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x88, 0x01,
+ 0x07,
+ 0x89, 0x01,
+ 0x08,
+ 0x8a, 0x01,
+ 0x00,
+ 0x8b, 0x01,
+ 0x00
+};
+
+BOOST_AUTO_TEST_CASE(EncodeAndDecode)
+{
+ Schedule schedule;
+
+ RepetitiveInterval interval1(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY);
+ RepetitiveInterval interval2(from_iso_string("20150825T000000"),
+ from_iso_string("20150828T000000"),
+ 6, 8, 1, RepetitiveInterval::RepeatUnit::DAY);
+ RepetitiveInterval interval3(from_iso_string("20150827T000000"),
+ from_iso_string("20150827T000000"),
+ 7, 8);
+ RepetitiveInterval interval4(from_iso_string("20150825T000000"),
+ from_iso_string("20150825T000000"),
+ 4, 7);
+
+ schedule.addWhiteInterval(interval1);
+ schedule.addWhiteInterval(interval2);
+ schedule.addWhiteInterval(interval4);
+ schedule.addBlackInterval(interval3);
+
+ Block block = schedule.wireEncode();
+ Block block2(SCHEDULE, sizeof(SCHEDULE));
+ BOOST_CHECK(block == block2);
+
+ Schedule schedule2(block);
+ Interval resultInterval;
+
+ // tp1 --> 8.25 4-10
+ TimeStamp tp1 = from_iso_string("20150825T063000");
+ resultInterval = schedule2.getCoveringInterval(tp1);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T040000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000");
+
+ // tp2 --> 8.26 6-8
+ TimeStamp tp2 = from_iso_string("20150826T073000");
+ resultInterval = schedule2.getCoveringInterval(tp2);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150826T060000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150826T080000");
+
+ Schedule schedule3(block2);
+
+ // tp1 --> 8.25 4-10
+ resultInterval = schedule3.getCoveringInterval(tp1);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T040000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000");
+
+ // tp2 --> 8.26 6-8
+ resultInterval = schedule3.getCoveringInterval(tp2);
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150826T060000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150826T080000");
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace tests
+} // namespace gep
+} // namespace ndn