Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014-2015, Regents of the University of California |
| 4 | * |
| 5 | * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN). |
| 6 | * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors. |
| 7 | * |
| 8 | * ndn-group-encrypt is free software: you can redistribute it and/or modify it under the terms |
| 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 | * |
| 12 | * ndn-group-encrypt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 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 |
| 17 | * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * @author Zhiyi Zhang <dreamerbarrychang@gmail.com> |
| 20 | */ |
| 21 | |
| 22 | #include "group-manager-db.hpp" |
| 23 | #include "boost-test.hpp" |
| 24 | |
| 25 | #include <boost/filesystem.hpp> |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace gep { |
| 29 | namespace tests { |
| 30 | |
| 31 | const uint8_t DATA[] = { |
| 32 | 0x06, 0xfd, 0x02, 0xd7, 0x07, 0x38, 0x08, 0x03, 0x6e, 0x64, 0x6e, 0x08, 0x03, 0x4b, 0x45, |
| 33 | 0x59, 0x08, 0x05, 0x73, 0x69, 0x74, 0x65, 0x31, 0x08, 0x11, 0x6b, 0x73, 0x6b, 0x2d, 0x31, |
| 34 | 0x34, 0x31, 0x36, 0x34, 0x32, 0x35, 0x33, 0x37, 0x37, 0x30, 0x39, 0x34, 0x08, 0x07, 0x49, |
| 35 | 0x44, 0x2d, 0x43, 0x45, 0x52, 0x54, 0x08, 0x09, 0xfd, 0x00, 0x00, 0x01, 0x49, 0xc9, 0x8b, |
| 36 | 0x2e, 0x73, 0x14, 0x03, 0x18, 0x01, 0x02, 0x15, 0xfd, 0x01, 0x61, 0x30, 0x82, 0x01, 0x5d, |
| 37 | 0x30, 0x22, 0x18, 0x0f, 0x32, 0x30, 0x31, 0x34, 0x31, 0x31, 0x31, 0x39, 0x31, 0x39, 0x33, |
| 38 | 0x33, 0x30, 0x32, 0x5a, 0x18, 0x0f, 0x32, 0x30, 0x31, 0x35, 0x31, 0x31, 0x31, 0x39, 0x31, |
| 39 | 0x39, 0x33, 0x33, 0x30, 0x32, 0x5a, 0x30, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x29, |
| 40 | 0x13, 0x0a, 0x2f, 0x6e, 0x64, 0x6e, 0x2f, 0x73, 0x69, 0x74, 0x65, 0x31, 0x30, 0x82, 0x01, |
| 41 | 0x20, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, |
| 42 | 0x00, 0x03, 0x82, 0x01, 0x0d, 0x00, 0x30, 0x82, 0x01, 0x08, 0x02, 0x82, 0x01, 0x01, 0x00, |
| 43 | 0xb6, 0x54, 0x7e, 0xe8, 0xf2, 0x91, 0x7d, 0xc1, 0x6d, 0xcb, 0x25, 0x44, 0x97, 0x90, 0xdc, |
| 44 | 0x78, 0x15, 0x0e, 0xef, 0xb5, 0xe7, 0xfd, 0x09, 0x2c, 0xf8, 0xd5, 0x9c, 0x2f, 0xe5, 0xa6, |
| 45 | 0xae, 0x9d, 0x7e, 0x95, 0x2d, 0xfc, 0xc7, 0xc3, 0x43, 0x46, 0xb0, 0x6f, 0x53, 0xcd, 0xcd, |
| 46 | 0x6a, 0x29, 0x1d, 0x95, 0xa1, 0x62, 0xcd, 0xa9, 0xf2, 0xf8, 0xe2, 0xfa, 0x8b, 0x5d, 0xfe, |
| 47 | 0xa1, 0x2b, 0x15, 0x3f, 0x7f, 0x71, 0xe6, 0x3e, 0xb9, 0xb1, 0x29, 0xd1, 0x22, 0x6f, 0x56, |
| 48 | 0xdf, 0xb6, 0x85, 0xaf, 0xd4, 0xb3, 0x67, 0x8b, 0x94, 0xb8, 0x83, 0xcb, 0x72, 0x86, 0xc4, |
| 49 | 0xf2, 0x86, 0xb2, 0x7c, 0x94, 0xbc, 0x38, 0x7b, 0x8c, 0x92, 0x86, 0x36, 0x83, 0x0e, 0x11, |
| 50 | 0x8c, 0x95, 0x49, 0xff, 0xcc, 0x16, 0x62, 0xdb, 0x55, 0x40, 0x7f, 0xc8, 0x8d, 0xe4, 0x3f, |
| 51 | 0x87, 0x02, 0x87, 0xaf, 0xf6, 0x2f, 0x8a, 0x7d, 0x74, 0x10, 0xd3, 0xbb, 0xa3, 0xfe, 0x5a, |
| 52 | 0x7b, 0x8f, 0x56, 0x09, 0x8b, 0x49, 0x46, 0x9f, 0x7d, 0x55, 0xa3, 0x4a, 0xe8, 0x22, 0x7b, |
| 53 | 0x80, 0x8a, 0x6f, 0xde, 0x9f, 0xfb, 0x2f, 0xeb, 0xf7, 0x29, 0x8a, 0x38, 0x67, 0x41, 0xae, |
| 54 | 0x21, 0x7a, 0xe3, 0x7b, 0x96, 0x1a, 0x90, 0x35, 0x7d, 0x04, 0xaa, 0x4d, 0x9f, 0xe6, 0xd6, |
| 55 | 0x00, 0x17, 0x4e, 0x02, 0x34, 0x6c, 0x56, 0x3a, 0x81, 0x3c, 0xb4, 0x7f, 0x98, 0x48, 0x22, |
| 56 | 0xa0, 0x9f, 0x53, 0x35, 0xf9, 0x4e, 0xae, 0x8f, 0xc3, 0xfa, 0x0b, 0x93, 0xd4, 0x55, 0x78, |
| 57 | 0x05, 0xb0, 0x40, 0x44, 0x48, 0x74, 0xb7, 0x9b, 0x2d, 0x65, 0xf0, 0x3d, 0x2e, 0x87, 0x2b, |
| 58 | 0x48, 0x29, 0x12, 0x85, 0xf0, 0xaf, 0xc4, 0xdc, 0x73, 0xce, 0x18, 0x8b, 0xd9, 0x4c, 0x60, |
| 59 | 0x15, 0x51, 0xae, 0x47, 0x1e, 0x2b, 0x54, 0xde, 0xf6, 0xba, 0x77, 0x30, 0x5d, 0x68, 0x9a, |
| 60 | 0xfb, 0x02, 0x01, 0x11, 0x16, 0x2d, 0x1b, 0x01, 0x01, 0x1c, 0x28, 0x07, 0x26, 0x08, 0x03, |
| 61 | 0x6e, 0x64, 0x6e, 0x08, 0x03, 0x4b, 0x45, 0x59, 0x08, 0x11, 0x6b, 0x73, 0x6b, 0x2d, 0x31, |
| 62 | 0x34, 0x31, 0x36, 0x34, 0x32, 0x35, 0x32, 0x39, 0x35, 0x35, 0x34, 0x36, 0x08, 0x07, 0x49, |
| 63 | 0x44, 0x2d, 0x43, 0x45, 0x52, 0x54, 0x17, 0xfd, 0x01, 0x00, 0x26, 0x40, 0xbc, 0xf0, 0x28, |
| 64 | 0x12, 0x69, 0x94, 0x11, 0x13, 0xff, 0x47, 0x2c, 0x6b, 0x12, 0xdd, 0xfa, 0x60, 0x92, 0xe9, |
| 65 | 0x59, 0x10, 0x98, 0xd8, 0x11, 0x2a, 0xf0, 0x25, 0xb0, 0x03, 0xb2, 0xda, 0xd3, 0xb6, 0xa9, |
| 66 | 0xfb, 0x8b, 0xc3, 0x6f, 0xfb, 0xb4, 0x93, 0x9b, 0x24, 0x9f, 0x7e, 0x63, 0x8a, 0x37, 0xea, |
| 67 | 0x88, 0x74, 0xac, 0x0c, 0x04, 0x5b, 0xa2, 0x39, 0x0c, 0xa1, 0x9e, 0x0e, 0xa2, 0xd6, 0x74, |
| 68 | 0xca, 0xc4, 0x92, 0x64, 0x9f, 0xc2, 0x68, 0x56, 0xef, 0xc5, 0x11, 0xe8, 0x7a, 0xf3, 0x21, |
| 69 | 0xde, 0x88, 0x40, 0x70, 0x2b, 0x44, 0xe0, 0xcb, 0x3b, 0x33, 0xc6, 0x53, 0x65, 0x70, 0x56, |
| 70 | 0x08, 0xe2, 0x22, 0x70, 0x9e, 0xe0, 0x38, 0x18, 0xa8, 0x7c, 0x7d, 0x09, 0x15, 0xac, 0xf1, |
| 71 | 0x44, 0x63, 0x5d, 0xd5, 0x59, 0xf4, 0xeb, 0x60, 0x6c, 0x6e, 0x77, 0x36, 0x20, 0x2a, 0xe2, |
| 72 | 0xd1, 0x2d, 0xa1, 0x7d, 0xd4, 0x6d, 0x29, 0x2d, 0x88, 0xde, 0x9e, 0xf8, 0x64, 0x41, 0x6a, |
| 73 | 0xeb, 0x9f, 0x3b, 0x52, 0x06, 0xb1, 0x94, 0x09, 0x3b, 0xc9, 0xba, 0xa0, 0x05, 0x31, 0x2d, |
| 74 | 0x49, 0x17, 0x5b, 0xc1, 0x62, 0xf5, 0x19, 0xce, 0x27, 0x7b, 0xe8, 0x4b, 0xeb, 0x80, 0x36, |
| 75 | 0xf3, 0xd7, 0xe9, 0x59, 0x22, 0x50, 0x5a, 0x14, 0xb0, 0x1a, 0xa5, 0x6b, 0x33, 0xb2, 0x83, |
| 76 | 0x72, 0x11, 0xf4, 0xd5, 0xd2, 0x32, 0x93, 0x94, 0xb6, 0x8d, 0xed, 0xcd, 0xce, 0x54, 0x79, |
| 77 | 0xe8, 0xc3, 0x3c, 0xa8, 0xc6, 0x71, 0xa7, 0x61, 0xba, 0x70, 0x44, 0x94, 0xc9, 0xfc, 0xd0, |
| 78 | 0x20, 0x00, 0x87, 0xdc, 0xf3, 0x3c, 0x47, 0x1b, 0x4f, 0x91, 0x4c, 0xc7, 0x49, 0xb7, 0xe4, |
| 79 | 0xe3, 0x84, 0xb7, 0x82, 0x52, 0xec, 0x91, 0xa9, 0x28, 0x38, 0x2d, 0x48, 0x89, 0xc7, 0xcf, |
| 80 | 0xfa, 0x63, 0x0b, 0xf0, 0x62, 0x51, 0xac, 0xe9, 0xdb, 0xfd, 0x1c |
| 81 | }; |
| 82 | |
| 83 | const uint8_t SCHEDULE[] = { |
| 84 | 0x8f, 0xc4,// Schedule |
| 85 | 0x8d, 0x90,// WhiteIntervalList |
| 86 | 0x8c, 0x2e, // RepetitiveInterval |
| 87 | 0x86, 0x0f, |
| 88 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 89 | 0x87, 0x0f, |
| 90 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x38, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 91 | 0x88, 0x01, |
| 92 | 0x05, |
| 93 | 0x89, 0x01, |
| 94 | 0x0a, |
| 95 | 0x8a, 0x01, |
| 96 | 0x02, |
| 97 | 0x8b, 0x01, |
| 98 | 0x01, |
| 99 | 0x8c, 0x2e, // RepetitiveInterval |
| 100 | 0x86, 0x0f, |
| 101 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 102 | 0x87, 0x0f, |
| 103 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x38, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 104 | 0x88, 0x01, |
| 105 | 0x06, |
| 106 | 0x89, 0x01, |
| 107 | 0x08, |
| 108 | 0x8a, 0x01, |
| 109 | 0x01, |
| 110 | 0x8b, 0x01, |
| 111 | 0x01, |
| 112 | 0x8c, 0x2e, // RepetitiveInterval |
| 113 | 0x86, 0x0f, |
| 114 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 115 | 0x87, 0x0f, |
| 116 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 117 | 0x88, 0x01, |
| 118 | 0x04, |
| 119 | 0x89, 0x01, |
| 120 | 0x07, |
| 121 | 0x8a, 0x01, |
| 122 | 0x00, |
| 123 | 0x8b, 0x01, |
| 124 | 0x00, |
| 125 | 0x8e, 0x30, // BlackIntervalList |
| 126 | 0x8c, 0x2e, // RepetitiveInterval |
| 127 | 0x86, 0x0f, |
| 128 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x37, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 129 | 0x87, 0x0f, |
| 130 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x37, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 131 | 0x88, 0x01, |
| 132 | 0x07, |
| 133 | 0x89, 0x01, |
| 134 | 0x08, |
| 135 | 0x8a, 0x01, |
| 136 | 0x00, |
| 137 | 0x8b, 0x01, |
| 138 | 0x00 |
| 139 | }; |
| 140 | |
| 141 | const uint8_t REPETITIVE_INTERVAL[] = { |
| 142 | 0x8c, 0x2e, // RepetitiveInterval |
| 143 | 0x86, 0x0f, |
| 144 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 145 | 0x87, 0x0f, |
| 146 | 0x32, 0x30, 0x31, 0x35, 0x30, 0x39, 0x32, 0x31, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, |
| 147 | 0x88, 0x01, |
| 148 | 0x02, |
| 149 | 0x89, 0x01, |
| 150 | 0x0a, |
| 151 | 0x8a, 0x01, |
| 152 | 0x05, |
| 153 | 0x8b, 0x01, |
| 154 | 0x01 |
| 155 | }; |
| 156 | |
| 157 | class GroupManagerDBFixture |
| 158 | { |
| 159 | public: |
| 160 | GroupManagerDBFixture() |
| 161 | : tmpPath(boost::filesystem::path(TMP_TESTS_PATH)) |
| 162 | { |
| 163 | boost::filesystem::create_directories(tmpPath); |
| 164 | } |
| 165 | |
| 166 | ~GroupManagerDBFixture() |
| 167 | { |
| 168 | boost::filesystem::remove_all(tmpPath); |
| 169 | } |
| 170 | |
| 171 | public: |
| 172 | boost::filesystem::path tmpPath; |
| 173 | }; |
| 174 | |
| 175 | BOOST_FIXTURE_TEST_SUITE(TestGroupManagerDB, GroupManagerDBFixture) |
| 176 | |
| 177 | BOOST_AUTO_TEST_CASE(DatabaseFunctions) |
| 178 | { |
| 179 | // construction |
| 180 | std::string dbDir = tmpPath.c_str(); |
| 181 | dbDir += "/test.db"; |
| 182 | GroupManagerDB db(dbDir); |
| 183 | |
| 184 | Block dataBlock(DATA, sizeof(DATA)); |
| 185 | Block scheduleBlock(SCHEDULE, sizeof(SCHEDULE)); |
| 186 | |
| 187 | // create schedule |
| 188 | Schedule schedule(scheduleBlock); |
| 189 | |
| 190 | // create member |
| 191 | Data data1(dataBlock); |
| 192 | data1.setName(Name("/ndn/BoyA/KEY/ksk-123/ID-CERT/123")); |
| 193 | Data data2(dataBlock); |
| 194 | data2.setName(Name("/ndn/BoyB/KEY/ksk-123/ID-CERT/123")); |
| 195 | Data data3(dataBlock); |
| 196 | data3.setName(Name("/ndn/GirlC/KEY/ksk-123/ID-CERT/123")); |
| 197 | Data data4(dataBlock); |
| 198 | data4.setName(Name("/ndn/GirlD/KEY/ksk-123/ID-CERT/123")); |
| 199 | Data data5(dataBlock); |
| 200 | data5.setName(Name("/ndn/Hello/KEY/ksk-123/ID-CERT/123")); |
| 201 | |
| 202 | // add schedules into the database |
| 203 | BOOST_CHECK_NO_THROW(db.addSchedule("work-time", schedule)); |
| 204 | BOOST_CHECK_NO_THROW(db.addSchedule("rest-time", schedule)); |
| 205 | BOOST_CHECK_NO_THROW(db.addSchedule("play-time", schedule)); |
| 206 | BOOST_CHECK_NO_THROW(db.addSchedule("boelter-time", schedule)); |
| 207 | |
| 208 | // throw exception when adding a schedule called an existing name |
| 209 | BOOST_CHECK_THROW(db.addSchedule("boelter-time", schedule), GroupManagerDB::Error); |
| 210 | |
| 211 | // add members into the database |
| 212 | BOOST_CHECK_NO_THROW(db.addMember("work-time", data1)); |
| 213 | BOOST_CHECK_NO_THROW(db.addMember("rest-time", data2)); |
| 214 | BOOST_CHECK_NO_THROW(db.addMember("play-time", data3)); |
| 215 | BOOST_CHECK_NO_THROW(db.addMember("play-time", data4)); |
| 216 | |
| 217 | // throw exception when adding a member having a not existing schedule name |
| 218 | BOOST_CHECK_THROW(db.addMember("false-time", data5), GroupManagerDB::Error); |
| 219 | |
| 220 | BOOST_CHECK_NO_THROW(db.addMember("boelter-time", data5)); |
| 221 | |
| 222 | // throw exception when adding a member having an existing identity |
| 223 | BOOST_CHECK_THROW(db.addMember("work-time", data5), GroupManagerDB::Error); |
| 224 | |
| 225 | // has function |
| 226 | BOOST_CHECK_EQUAL(db.hasSchedule("work-time"), true); |
| 227 | BOOST_CHECK_EQUAL(db.hasSchedule("rest-time"), true); |
| 228 | BOOST_CHECK_EQUAL(db.hasSchedule("play-time"), true); |
| 229 | BOOST_CHECK_EQUAL(db.hasSchedule("sleep-time"), false); |
| 230 | BOOST_CHECK_EQUAL(db.hasSchedule(""), false); |
| 231 | |
| 232 | BOOST_CHECK_EQUAL(db.hasMember(Name("/ndn/BoyA")), true); |
| 233 | BOOST_CHECK_EQUAL(db.hasMember(Name("/ndn/BoyB")), true); |
| 234 | BOOST_CHECK_EQUAL(db.hasMember(Name("/ndn/BoyC")), false); |
| 235 | |
| 236 | // get schedule |
| 237 | Schedule scheduleResult = db.getSchedule("work-time"); |
| 238 | BOOST_CHECK(scheduleResult.wireEncode() == scheduleBlock); |
| 239 | |
| 240 | scheduleResult = db.getSchedule("play-time"); |
| 241 | BOOST_CHECK(scheduleResult.wireEncode() == scheduleBlock); |
| 242 | |
| 243 | // throw exception when there is no such schedule in database |
| 244 | BOOST_CHECK_THROW(db.getSchedule("work-time-11"), GroupManagerDB::Error); |
| 245 | |
| 246 | // get certificate of a member |
| 247 | Data dataResult = db.getMemberCert(Name("/ndn/BoyA")); |
| 248 | BOOST_CHECK(dataResult.wireEncode() == data1.wireEncode()); |
| 249 | |
| 250 | dataResult = db.getMemberCert(Name("/ndn/GirlC")); |
| 251 | BOOST_CHECK(dataResult.wireEncode() == data3.wireEncode()); |
| 252 | |
| 253 | // throw error when there is no such member in database |
| 254 | BOOST_CHECK_THROW(db.getMemberCert(Name("/ndn/GirlA")), GroupManagerDB::Error); |
| 255 | |
| 256 | // list all schedule names |
| 257 | std::list<std::string> names = db.listAllScheduleNames(); |
| 258 | BOOST_CHECK(std::find(names.begin(), names.end(), "work-time") != names.end()); |
| 259 | BOOST_CHECK(std::find(names.begin(), names.end(), "play-time") != names.end()); |
| 260 | BOOST_CHECK(std::find(names.begin(), names.end(), "rest-time") != names.end()); |
| 261 | BOOST_CHECK(std::find(names.begin(), names.end(), "sleep-time") == names.end()); |
| 262 | |
| 263 | // list members of a schedule |
| 264 | std::map<Name, Data> memberMap = db.getScheduleMembers("play-time"); |
| 265 | BOOST_CHECK(memberMap.size() != 0); |
| 266 | |
| 267 | // when there's no such schedule, the return list's size is 0 |
| 268 | BOOST_CHECK_EQUAL(db.getScheduleMembers("sleep-time").size(), 0); |
| 269 | |
| 270 | // list all members |
| 271 | std::list<Name> members = db.listAllMembers(); |
| 272 | BOOST_CHECK(std::find(members.begin(), members.end(), Name("/ndn/GirlC")) != members.end()); |
| 273 | BOOST_CHECK(std::find(members.begin(), members.end(), Name("/ndn/GirlD")) != members.end()); |
| 274 | BOOST_CHECK(std::find(members.begin(), members.end(), Name("/ndn/BoyA")) != members.end()); |
| 275 | BOOST_CHECK(std::find(members.begin(), members.end(), Name("/ndn/BoyB")) != members.end()); |
| 276 | |
| 277 | // rename schedule |
| 278 | BOOST_CHECK_EQUAL(db.hasSchedule("boelter-time"), true); |
| 279 | db.renameSchedule("boelter-time", "rieber-time"); |
| 280 | BOOST_CHECK_EQUAL(db.hasSchedule("boelter-time"), false); |
| 281 | BOOST_CHECK_EQUAL(db.hasSchedule("rieber-time"), true); |
| 282 | BOOST_CHECK_EQUAL(db.getMemberSchedule("/ndn/Hello"), "rieber-time"); |
| 283 | |
| 284 | // update schedule |
| 285 | Schedule newSchedule(scheduleBlock); |
| 286 | Block repIntervalBlock(REPETITIVE_INTERVAL, sizeof(REPETITIVE_INTERVAL)); |
| 287 | newSchedule.addWhiteInterval(RepetitiveInterval(repIntervalBlock)); |
| 288 | db.updateSchedule("rieber-time", newSchedule); |
| 289 | scheduleResult = db.getSchedule("rieber-time"); |
| 290 | BOOST_CHECK(scheduleResult.wireEncode() != scheduleBlock); |
| 291 | BOOST_CHECK(scheduleResult.wireEncode() == newSchedule.wireEncode()); |
| 292 | |
| 293 | // add a new schedule when update a not existing schedule |
| 294 | BOOST_CHECK_EQUAL(db.hasSchedule("ralphs-time"), false); |
| 295 | db.updateSchedule("ralphs-time", newSchedule); |
| 296 | BOOST_CHECK_EQUAL(db.hasSchedule("ralphs-time"), true); |
| 297 | |
| 298 | // update schedule of member |
| 299 | db.updateMemberSchedule(Name("/ndn/Hello"), "play-time"); |
| 300 | BOOST_CHECK_EQUAL(db.getMemberSchedule(Name("/ndn/Hello")), "play-time"); |
| 301 | |
| 302 | // delete member |
| 303 | BOOST_CHECK_EQUAL(db.hasMember(Name("/ndn/Hello")), true); |
| 304 | db.deleteMember(Name("/ndn/Hello")); |
| 305 | BOOST_CHECK_EQUAL(db.hasMember(Name("/ndn/Hello")), false); |
| 306 | |
| 307 | // delete a not existing member |
| 308 | BOOST_CHECK_NO_THROW(db.deleteMember(Name("/ndn/notExisting"))); |
| 309 | |
| 310 | // delete the schedule and all the members using this schedule should be deleted |
| 311 | db.deleteSchedule("play-time"); |
| 312 | BOOST_CHECK_EQUAL(db.hasSchedule("play-time"), false); |
| 313 | BOOST_CHECK_EQUAL(db.hasMember(Name("/ndn/GirlC")), false); |
| 314 | BOOST_CHECK_EQUAL(db.hasMember(Name("/ndn/GirlD")), false); |
| 315 | |
| 316 | // delete a not existing schedule |
| 317 | BOOST_CHECK_NO_THROW(db.deleteSchedule("not-existing-time")); |
| 318 | } |
| 319 | |
| 320 | BOOST_AUTO_TEST_SUITE_END() |
| 321 | |
| 322 | } // namespace tests |
| 323 | } // namespace gep |
| 324 | } // namespace ndn |