Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, Regents of the University of California |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame] | 5 | * This file is part of NAC (Name-Based Access Control for NDN). |
| 6 | * See AUTHORS.md for complete list of NAC authors and contributors. |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame] | 8 | * NAC is free software: you can redistribute it and/or modify it under the terms |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame] | 12 | * NAC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame] | 17 | * NAC, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 18 | * |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 19 | * @author Zhiyi Zhang <zhiyi@cs.ucla.edu> |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "schedule.hpp" |
| 23 | #include "boost-test.hpp" |
| 24 | |
| 25 | namespace ndn { |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame] | 26 | namespace nac { |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 27 | namespace tests { |
| 28 | |
| 29 | using namespace boost::posix_time; |
| 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(TestSchedule) |
| 32 | |
Zhiyi Zhang | 2f9efa6 | 2015-11-23 19:02:28 +0800 | [diff] [blame] | 33 | BOOST_AUTO_TEST_CASE(CalIntervalWithBlackAndWhite) |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 34 | { |
| 35 | Schedule schedule; |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 36 | RepetitiveInterval interval1(from_iso_string("20150825T000000"), |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 37 | from_iso_string("20150827T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 38 | 5, |
| 39 | 10, |
| 40 | 2, |
| 41 | RepetitiveInterval::RepeatUnit::DAY); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 42 | RepetitiveInterval interval2(from_iso_string("20150825T000000"), |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 43 | from_iso_string("20150827T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 44 | 6, |
| 45 | 8, |
| 46 | 1, |
| 47 | RepetitiveInterval::RepeatUnit::DAY); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 48 | RepetitiveInterval interval3(from_iso_string("20150827T000000"), |
| 49 | from_iso_string("20150827T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 50 | 7, |
| 51 | 8); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 52 | RepetitiveInterval interval4(from_iso_string("20150825T000000"), |
| 53 | from_iso_string("20150825T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 54 | 4, |
| 55 | 7); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 56 | |
| 57 | schedule.addWhiteInterval(interval1); |
| 58 | schedule.addWhiteInterval(interval2); |
| 59 | schedule.addWhiteInterval(interval4); |
| 60 | schedule.addBlackInterval(interval3); |
| 61 | |
| 62 | Interval resultInterval; |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 63 | bool isPositive; |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 64 | |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 65 | // tp1 --> positive 8.25 4-10 |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 66 | TimeStamp tp1 = from_iso_string("20150825T063000"); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 67 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp1); |
| 68 | BOOST_CHECK_EQUAL(isPositive, true); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 69 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T040000"); |
| 70 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000"); |
| 71 | |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 72 | // tp2 --> positive 8.26 6-8 |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 73 | TimeStamp tp2 = from_iso_string("20150826T073000"); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 74 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp2); |
| 75 | BOOST_CHECK_EQUAL(isPositive, true); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 76 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150826T060000"); |
| 77 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150826T080000"); |
| 78 | |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 79 | // tp3 --> positive 8.27 5-7 |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 80 | TimeStamp tp3 = from_iso_string("20150827T053000"); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 81 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp3); |
| 82 | BOOST_CHECK_EQUAL(isPositive, true); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 83 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150827T050000"); |
| 84 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150827T070000"); |
| 85 | |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 86 | // tp4 --> positive 8.27 5-7 |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 87 | TimeStamp tp4 = from_iso_string("20150827T063000"); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 88 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp4); |
| 89 | BOOST_CHECK_EQUAL(isPositive, true); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 90 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150827T050000"); |
| 91 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150827T070000"); |
| 92 | |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 93 | // tp5 --> negative 8.27 7-8 |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 94 | TimeStamp tp5 = from_iso_string("20150827T073000"); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 95 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp5); |
| 96 | BOOST_CHECK_EQUAL(isPositive, false); |
| 97 | BOOST_CHECK_EQUAL(resultInterval.isEmpty(), false); |
| 98 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150827T070000"); |
| 99 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150827T080000"); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 100 | |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 101 | // tp6 --> negative 8.25 10-24 |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 102 | TimeStamp tp6 = from_iso_string("20150825T113000"); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 103 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp6); |
| 104 | BOOST_CHECK_EQUAL(isPositive, false); |
| 105 | BOOST_CHECK_EQUAL(resultInterval.isEmpty(), false); |
| 106 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T100000"); |
| 107 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150826T000000"); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Zhiyi Zhang | 2f9efa6 | 2015-11-23 19:02:28 +0800 | [diff] [blame] | 110 | BOOST_AUTO_TEST_CASE(CalIntervalWithoutBlack) |
| 111 | { |
| 112 | Schedule schedule; |
| 113 | RepetitiveInterval interval1(from_iso_string("20150825T000000"), |
| 114 | from_iso_string("20150827T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 115 | 5, |
| 116 | 10, |
| 117 | 2, |
| 118 | RepetitiveInterval::RepeatUnit::DAY); |
Zhiyi Zhang | 2f9efa6 | 2015-11-23 19:02:28 +0800 | [diff] [blame] | 119 | RepetitiveInterval interval2(from_iso_string("20150825T000000"), |
| 120 | from_iso_string("20150827T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 121 | 6, |
| 122 | 8, |
| 123 | 1, |
| 124 | RepetitiveInterval::RepeatUnit::DAY); |
Zhiyi Zhang | 2f9efa6 | 2015-11-23 19:02:28 +0800 | [diff] [blame] | 125 | RepetitiveInterval interval3(from_iso_string("20150825T000000"), |
| 126 | from_iso_string("20150825T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 127 | 4, |
| 128 | 7); |
Zhiyi Zhang | 2f9efa6 | 2015-11-23 19:02:28 +0800 | [diff] [blame] | 129 | |
| 130 | schedule.addWhiteInterval(interval1); |
| 131 | schedule.addWhiteInterval(interval2); |
| 132 | schedule.addWhiteInterval(interval3); |
| 133 | |
| 134 | Interval resultInterval; |
| 135 | bool isPositive; |
| 136 | |
| 137 | // tp1 --> positive 8.25 4-10 |
| 138 | TimeStamp tp1 = from_iso_string("20150825T063000"); |
| 139 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp1); |
| 140 | BOOST_CHECK_EQUAL(isPositive, true); |
| 141 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T040000"); |
| 142 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000"); |
| 143 | |
| 144 | // tp2 --> positive 8.26 6-8 |
| 145 | TimeStamp tp2 = from_iso_string("20150826T073000"); |
| 146 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp2); |
| 147 | BOOST_CHECK_EQUAL(isPositive, true); |
| 148 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150826T060000"); |
| 149 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150826T080000"); |
| 150 | |
| 151 | // tp3 --> positive 8.27 5-10 |
| 152 | TimeStamp tp3 = from_iso_string("20150827T053000"); |
| 153 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp3); |
| 154 | BOOST_CHECK_EQUAL(isPositive, true); |
| 155 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150827T050000"); |
| 156 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150827T100000"); |
| 157 | |
| 158 | // tp4 --> negative 8.25 10-24 |
| 159 | TimeStamp tp4 = from_iso_string("20150825T113000"); |
| 160 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp4); |
| 161 | BOOST_CHECK_EQUAL(isPositive, false); |
| 162 | BOOST_CHECK_EQUAL(resultInterval.isEmpty(), false); |
| 163 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T100000"); |
| 164 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150826T000000"); |
| 165 | |
| 166 | // tp5 --> negative 8.25 0-4 |
| 167 | TimeStamp tp5 = from_iso_string("20150825T013000"); |
| 168 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp5); |
| 169 | BOOST_CHECK_EQUAL(isPositive, false); |
| 170 | BOOST_CHECK_EQUAL(resultInterval.isEmpty(), false); |
| 171 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T000000"); |
| 172 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T040000"); |
| 173 | } |
| 174 | |
| 175 | BOOST_AUTO_TEST_CASE(CalIntervalWithoutWhite) |
| 176 | { |
| 177 | Schedule schedule; |
| 178 | RepetitiveInterval interval1(from_iso_string("20150825T000000"), |
| 179 | from_iso_string("20150827T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 180 | 5, |
| 181 | 10, |
| 182 | 2, |
| 183 | RepetitiveInterval::RepeatUnit::DAY); |
Zhiyi Zhang | 2f9efa6 | 2015-11-23 19:02:28 +0800 | [diff] [blame] | 184 | RepetitiveInterval interval2(from_iso_string("20150825T000000"), |
| 185 | from_iso_string("20150827T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 186 | 6, |
| 187 | 8, |
| 188 | 1, |
| 189 | RepetitiveInterval::RepeatUnit::DAY); |
Zhiyi Zhang | 2f9efa6 | 2015-11-23 19:02:28 +0800 | [diff] [blame] | 190 | |
| 191 | schedule.addBlackInterval(interval1); |
| 192 | schedule.addBlackInterval(interval2); |
| 193 | |
| 194 | Interval resultInterval; |
| 195 | bool isPositive; |
| 196 | |
| 197 | // tp1 --> negative 8.25 4-10 |
| 198 | TimeStamp tp1 = from_iso_string("20150825T063000"); |
| 199 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp1); |
| 200 | BOOST_CHECK_EQUAL(isPositive, false); |
| 201 | BOOST_CHECK_EQUAL(resultInterval.isEmpty(), false); |
| 202 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T050000"); |
| 203 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000"); |
| 204 | |
| 205 | // tp2 --> negative 8.25 0-4 |
| 206 | TimeStamp tp2 = from_iso_string("20150825T013000"); |
| 207 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp2); |
| 208 | BOOST_CHECK_EQUAL(isPositive, false); |
| 209 | BOOST_CHECK_EQUAL(resultInterval.isEmpty(), false); |
| 210 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T000000"); |
| 211 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150826T000000"); |
| 212 | } |
| 213 | |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 214 | const uint8_t SCHEDULE[] = { |
| 215 | 0x8f, 0xc4,// Schedule |
| 216 | 0x8d, 0x90,// WhiteIntervalList |
| 217 | ///// |
| 218 | 0x8c, 0x2e, // RepetitiveInterval |
| 219 | 0x86, 0x0f, |
| 220 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 221 | 0x87, 0x0f, |
Yingdi Yu | d263c8a | 2016-03-09 16:53:19 -0800 | [diff] [blame] | 222 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 223 | 0x88, 0x01, |
Yingdi Yu | d263c8a | 2016-03-09 16:53:19 -0800 | [diff] [blame] | 224 | 0x04, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 225 | 0x89, 0x01, |
Yingdi Yu | d263c8a | 2016-03-09 16:53:19 -0800 | [diff] [blame] | 226 | 0x07, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 227 | 0x8a, 0x01, |
Yingdi Yu | d263c8a | 2016-03-09 16:53:19 -0800 | [diff] [blame] | 228 | 0x00, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 229 | 0x8b, 0x01, |
Yingdi Yu | d263c8a | 2016-03-09 16:53:19 -0800 | [diff] [blame] | 230 | 0x00, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 231 | ///// |
| 232 | 0x8c, 0x2e, // RepetitiveInterval |
| 233 | 0x86, 0x0f, |
| 234 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 235 | 0x87, 0x0f, |
| 236 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x38, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 237 | 0x88, 0x01, |
Yingdi Yu | a717b88 | 2016-03-09 17:56:42 -0800 | [diff] [blame] | 238 | 0x05, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 239 | 0x89, 0x01, |
Yingdi Yu | a717b88 | 2016-03-09 17:56:42 -0800 | [diff] [blame] | 240 | 0x0a, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 241 | 0x8a, 0x01, |
Yingdi Yu | a717b88 | 2016-03-09 17:56:42 -0800 | [diff] [blame] | 242 | 0x02, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 243 | 0x8b, 0x01, |
| 244 | 0x01, |
| 245 | ///// |
| 246 | 0x8c, 0x2e, // RepetitiveInterval |
| 247 | 0x86, 0x0f, |
| 248 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 249 | 0x87, 0x0f, |
Yingdi Yu | d263c8a | 2016-03-09 16:53:19 -0800 | [diff] [blame] | 250 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x38, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 251 | 0x88, 0x01, |
Yingdi Yu | d263c8a | 2016-03-09 16:53:19 -0800 | [diff] [blame] | 252 | 0x06, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 253 | 0x89, 0x01, |
Yingdi Yu | d263c8a | 2016-03-09 16:53:19 -0800 | [diff] [blame] | 254 | 0x08, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 255 | 0x8a, 0x01, |
Yingdi Yu | d263c8a | 2016-03-09 16:53:19 -0800 | [diff] [blame] | 256 | 0x01, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 257 | 0x8b, 0x01, |
Yingdi Yu | d263c8a | 2016-03-09 16:53:19 -0800 | [diff] [blame] | 258 | 0x01, |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 259 | ///// |
| 260 | 0x8e, 0x30, // BlackIntervalList |
| 261 | ///// |
| 262 | 0x8c, 0x2e, // RepetitiveInterval |
| 263 | 0x86, 0x0f, |
| 264 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x37, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 265 | 0x87, 0x0f, |
| 266 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x37, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 267 | 0x88, 0x01, |
| 268 | 0x07, |
| 269 | 0x89, 0x01, |
| 270 | 0x08, |
| 271 | 0x8a, 0x01, |
| 272 | 0x00, |
| 273 | 0x8b, 0x01, |
| 274 | 0x00 |
| 275 | }; |
| 276 | |
| 277 | BOOST_AUTO_TEST_CASE(EncodeAndDecode) |
| 278 | { |
| 279 | Schedule schedule; |
| 280 | |
| 281 | RepetitiveInterval interval1(from_iso_string("20150825T000000"), |
| 282 | from_iso_string("20150828T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 283 | 5, |
| 284 | 10, |
| 285 | 2, |
| 286 | RepetitiveInterval::RepeatUnit::DAY); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 287 | RepetitiveInterval interval2(from_iso_string("20150825T000000"), |
| 288 | from_iso_string("20150828T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 289 | 6, |
| 290 | 8, |
| 291 | 1, |
| 292 | RepetitiveInterval::RepeatUnit::DAY); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 293 | RepetitiveInterval interval3(from_iso_string("20150827T000000"), |
| 294 | from_iso_string("20150827T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 295 | 7, |
| 296 | 8); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 297 | RepetitiveInterval interval4(from_iso_string("20150825T000000"), |
| 298 | from_iso_string("20150825T000000"), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 299 | 4, |
| 300 | 7); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 301 | |
| 302 | schedule.addWhiteInterval(interval1); |
| 303 | schedule.addWhiteInterval(interval2); |
| 304 | schedule.addWhiteInterval(interval4); |
| 305 | schedule.addBlackInterval(interval3); |
| 306 | |
| 307 | Block block = schedule.wireEncode(); |
| 308 | Block block2(SCHEDULE, sizeof(SCHEDULE)); |
| 309 | BOOST_CHECK(block == block2); |
| 310 | |
| 311 | Schedule schedule2(block); |
| 312 | Interval resultInterval; |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 313 | bool isPositive; |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 314 | |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 315 | // tp1 --> positive 8.25 4-10 |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 316 | TimeStamp tp1 = from_iso_string("20150825T063000"); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 317 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp1); |
| 318 | BOOST_CHECK_EQUAL(isPositive, true); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 319 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T040000"); |
| 320 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000"); |
| 321 | |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 322 | // tp2 --> positive 8.26 6-8 |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 323 | TimeStamp tp2 = from_iso_string("20150826T073000"); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 324 | std::tie(isPositive, resultInterval) = schedule.getCoveringInterval(tp2); |
| 325 | BOOST_CHECK_EQUAL(isPositive, true); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 326 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150826T060000"); |
| 327 | BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150826T080000"); |
| 328 | } |
| 329 | |
| 330 | BOOST_AUTO_TEST_SUITE_END() |
| 331 | |
| 332 | } // namespace tests |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame] | 333 | } // namespace nac |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 334 | } // namespace ndn |