From 5b3cf7621ce9269048022ea311887aa752591713 Mon Sep 17 00:00:00 2001 From: Davide Pesavento Date: Fri, 3 Apr 2020 16:20:04 -0400 Subject: [PATCH] tests: use BOOST_REQUIRE and Name::at() to prevent out-of-bound accesses Various other cleanups Change-Id: Ie099e618b12b7b6cf36c32be96d753221f14a8b6 --- PSync/detail/iblt.hpp | 8 ++--- PSync/producer-base.hpp | 3 -- tests/test-bloom-filter.cpp | 14 ++++---- tests/test-consumer.cpp | 28 +++++++-------- tests/test-full-producer.cpp | 12 +++---- tests/test-full-sync.cpp | 40 ++++++++-------------- tests/test-iblt.cpp | 44 ++++++++++++------------ tests/test-partial-producer.cpp | 17 ++++----- tests/test-partial-sync.cpp | 59 +++++++++++++++++--------------- tests/test-producer-base.cpp | 9 +++-- tests/test-segment-publisher.cpp | 6 ++-- tests/test-state.cpp | 6 ++-- tests/test-util.cpp | 10 ++---- 13 files changed, 114 insertions(+), 142 deletions(-) diff --git a/PSync/detail/iblt.hpp b/PSync/detail/iblt.hpp index d3d023f..f3278b3 100644 --- a/PSync/detail/iblt.hpp +++ b/PSync/detail/iblt.hpp @@ -119,9 +119,7 @@ public: * Entries listed in positive are in ownIBLT but not in rcvdIBLT * Entries listed in negative are in rcvdIBLT but not in ownIBLT * - * @param positive - * @param negative - * @return true if decoding is complete successfully + * @return whether decoding completed successfully */ bool listEntries(std::set& positive, std::set& negative) const; @@ -136,15 +134,13 @@ public: } /** - * @brief Appends self to name + * @brief Appends self to @p name * * Encodes our hash table from uint32_t vector to uint8_t vector * We create a uin8_t vector 12 times the size of uint32_t vector * We put the first count in first 4 cells, keySum in next 4, and keyCheck in next 4. * Repeat for all the other cells of the hash table. * Then we append this uint8_t vector to the name. - * - * @param name */ void appendToName(ndn::Name& name) const; diff --git a/PSync/producer-base.hpp b/PSync/producer-base.hpp index 29a1c04..16e28d6 100644 --- a/PSync/producer-base.hpp +++ b/PSync/producer-base.hpp @@ -151,9 +151,6 @@ PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED: /** * @brief Logs a message if setting an interest filter fails - * - * @param prefix - * @param msg */ void onRegisterFailed(const ndn::Name& prefix, const std::string& msg) const; diff --git a/tests/test-bloom-filter.cpp b/tests/test-bloom-filter.cpp index 77a56a0..1788cd1 100644 --- a/tests/test-bloom-filter.cpp +++ b/tests/test-bloom-filter.cpp @@ -19,7 +19,8 @@ #include "PSync/detail/bloom-filter.hpp" -#include +#include "tests/boost-test.hpp" + #include namespace psync { @@ -42,18 +43,17 @@ BOOST_AUTO_TEST_CASE(NameAppendAndExtract) Name bfName("/test"); BloomFilter bf(100, 0.001); bf.insert("/memphis"); - bf.appendToName(bfName); - BloomFilter bfFromName(100, 0.001, bfName.get(-1)); + BloomFilter bfFromName(100, 0.001, bfName.at(-1)); - BOOST_CHECK_EQUAL(bfName.get(1).toNumber(), 100); - BOOST_CHECK_EQUAL(bfName.get(2).toNumber(), 1); + BOOST_CHECK_EQUAL(bfName.at(1).toNumber(), 100); + BOOST_CHECK_EQUAL(bfName.at(2).toNumber(), 1); BOOST_CHECK_EQUAL(bf, bfFromName); - BOOST_CHECK_THROW(BloomFilter inCompatibleBf(200, 0.001, bfName.get(-1)), std::runtime_error); + BOOST_CHECK_THROW(BloomFilter(200, 0.001, bfName.at(-1)), std::runtime_error); } BOOST_AUTO_TEST_SUITE_END() -} // namespace psync \ No newline at end of file +} // namespace psync diff --git a/tests/test-consumer.cpp b/tests/test-consumer.cpp index 9b08d53..e5560cd 100644 --- a/tests/test-consumer.cpp +++ b/tests/test-consumer.cpp @@ -18,36 +18,34 @@ **/ #include "PSync/consumer.hpp" -#include "unit-test-time-fixture.hpp" -#include +#include "tests/boost-test.hpp" +#include "tests/unit-test-time-fixture.hpp" + #include #include namespace psync { using namespace ndn; -using namespace std; BOOST_AUTO_TEST_SUITE(TestConsumer) BOOST_AUTO_TEST_CASE(Constructor) { util::DummyClientFace face({true, true}); - BOOST_REQUIRE_NO_THROW(Consumer(Name("/psync"), - face, - [] (const vector&) {}, - [] (const vector&) {}, - 40, - 0.001)); + BOOST_REQUIRE_NO_THROW(Consumer(Name("/psync"), face, + [] (const std::vector&) {}, + [] (const std::vector&) {}, + 40, 0.001)); } BOOST_AUTO_TEST_CASE(AddSubscription) { util::DummyClientFace face({true, true}); Consumer consumer(Name("/psync"), face, - [] (const vector&) {}, - [] (const vector&) {}, + [] (const auto&) {}, + [] (const auto&) {}, 40, 0.001); Name subscription("test"); @@ -57,12 +55,12 @@ BOOST_AUTO_TEST_CASE(AddSubscription) BOOST_CHECK(!consumer.addSubscription(subscription)); } -BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, ndn::tests::UnitTestTimeFixture) +BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::UnitTestTimeFixture) { util::DummyClientFace face(io, {true, true}); Consumer consumer(Name("/psync"), face, - [] (const vector&) {}, - [] (const vector&) {}, + [] (const auto&) {}, + [] (const auto&) {}, 40, 0.001, ndn::time::milliseconds(4000), ndn::time::milliseconds(4000)); @@ -82,4 +80,4 @@ BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, ndn::tests::UnitTestTime BOOST_AUTO_TEST_SUITE_END() -} // namespace psync \ No newline at end of file +} // namespace psync diff --git a/tests/test-full-producer.cpp b/tests/test-full-producer.cpp index fc56a0c..33b5014 100644 --- a/tests/test-full-producer.cpp +++ b/tests/test-full-producer.cpp @@ -18,17 +18,17 @@ **/ #include "PSync/full-producer.hpp" -#include "unit-test-time-fixture.hpp" -#include +#include "tests/boost-test.hpp" +#include "tests/unit-test-time-fixture.hpp" + #include -#include #include +#include namespace psync { using namespace ndn; -using namespace std; BOOST_AUTO_TEST_SUITE(TestFullProducer) @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(OnInterest) BOOST_REQUIRE_NO_THROW(node.onSyncInterest(syncPrefix, Interest(syncInterestName))); } -BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, ndn::tests::UnitTestTimeFixture) +BOOST_FIXTURE_TEST_CASE(ConstantTimeoutForFirstSegment, tests::UnitTestTimeFixture) { Name syncPrefix("/psync"), userNode("/testUser"); util::DummyClientFace face(io, {true, true}); @@ -87,4 +87,4 @@ BOOST_AUTO_TEST_CASE(OnSyncDataDecodeFailure) BOOST_AUTO_TEST_SUITE_END() -} // namespace psync \ No newline at end of file +} // namespace psync diff --git a/tests/test-full-sync.cpp b/tests/test-full-sync.cpp index 1f5c6bb..38e7bf2 100644 --- a/tests/test-full-sync.cpp +++ b/tests/test-full-sync.cpp @@ -17,38 +17,35 @@ * PSync, e.g., in COPYING.md file. If not, see . **/ -#include "unit-test-time-fixture.hpp" #include "PSync/full-producer.hpp" #include "PSync/consumer.hpp" #include "PSync/detail/state.hpp" -#include +#include "tests/boost-test.hpp" +#include "tests/unit-test-time-fixture.hpp" + #include #include namespace psync { using namespace ndn; -using namespace std; class FullSyncFixture : public tests::UnitTestTimeFixture { -public: - FullSyncFixture() - : syncPrefix("psync") - { - } - +protected: void addNode(int id) { + BOOST_ASSERT(id >= 0 && id <= 3); faces[id] = std::make_shared(io, util::DummyClientFace::Options{true, true}); userPrefixes[id] = Name("userPrefix" + to_string(id)); nodes[id] = make_shared(40, *faces[id], syncPrefix, userPrefixes[id], - [] (const std::vector& updates) {}); + [] (const auto&) {}); } - Name syncPrefix; +protected: + const Name syncPrefix = "/psync"; shared_ptr faces[4]; Name userPrefixes[4]; shared_ptr nodes[4]; @@ -134,7 +131,6 @@ BOOST_AUTO_TEST_CASE(MultipleNodes) for (int i = 0; i < 4; i++) { addNode(i); } - for (int i = 0; i < 3; i++) { faces[i]->linkTo(*faces[i + 1]); } @@ -158,16 +154,14 @@ BOOST_AUTO_TEST_CASE(MultipleNodes) } } -BOOST_AUTO_TEST_CASE(MultipleNodesSimulataneousPublish) +BOOST_AUTO_TEST_CASE(MultipleNodesSimultaneousPublish) { for (int i = 0; i < 4; i++) { addNode(i); } - for (int i = 0; i < 3; i++) { faces[i]->linkTo(*faces[i + 1]); } - for (int i = 0; i < 4; i++) { nodes[i]->publishName(userPrefixes[i]); } @@ -196,7 +190,6 @@ BOOST_AUTO_TEST_CASE(NetworkPartition) for (int i = 0; i < 4; i++) { addNode(i); } - for (int i = 0; i < 3; i++) { faces[i]->linkTo(*faces[i + 1]); } @@ -210,7 +203,6 @@ BOOST_AUTO_TEST_CASE(NetworkPartition) for (int i = 0; i < 3; i++) { faces[i]->unlink(); } - faces[0]->linkTo(*faces[1]); faces[2]->linkTo(*faces[3]); @@ -238,7 +230,6 @@ BOOST_AUTO_TEST_CASE(NetworkPartition) for (int i = 0; i < 3; i++) { faces[i]->unlink(); } - for (int i = 0; i < 3; i++) { faces[i]->linkTo(*faces[i + 1]); } @@ -369,7 +360,6 @@ BOOST_AUTO_TEST_CASE(DiffIBFDecodeFailureMultipleNodes) for (int i = 0; i < 4; i++) { addNode(i); } - for (int i = 0; i < 3; i++) { faces[i]->linkTo(*faces[i + 1]); } @@ -400,19 +390,17 @@ BOOST_AUTO_TEST_CASE(DelayedSecondSegment) int i = 0; State state; - - std::shared_ptr compressed; + std::shared_ptr compressed; do { Name prefixToPublish("userNode0-" + to_string(i++)); nodes[0]->addUserNode(prefixToPublish); nodes[0]->publishName(prefixToPublish); - state.addContent(ndn::Name(prefixToPublish).appendNumber(nodes[0]->m_prefixes[prefixToPublish])); + state.addContent(Name(prefixToPublish).appendNumber(nodes[0]->m_prefixes[prefixToPublish])); auto block = state.wireEncode(); compressed = compress(nodes[0]->m_contentCompression, block.wire(), block.size()); - - } while (compressed->size() < (ndn::MAX_NDN_PACKET_SIZE >> 1)); + } while (compressed->size() < (MAX_NDN_PACKET_SIZE >> 1)); advanceClocks(ndn::time::milliseconds(10), 100); @@ -430,6 +418,7 @@ BOOST_AUTO_TEST_CASE(DelayedSecondSegment) BOOST_CHECK_EQUAL(nodes[0]->m_segmentPublisher.m_ims.size(), 0); // Get data name from face and increase segment number to form next interest + BOOST_REQUIRE(!faces[0]->sentData.empty()); Name dataName = faces[0]->sentData.front().getName(); Name interestName = dataName.getSubName(0, dataName.size() - 2); interestName.appendSegment(1); @@ -441,7 +430,8 @@ BOOST_AUTO_TEST_CASE(DelayedSecondSegment) // Should have repopulated SegmentPublisher BOOST_CHECK_EQUAL(nodes[0]->m_segmentPublisher.m_ims.size(), 2); // Should have received the second data segment this time - BOOST_CHECK_EQUAL(faces[0]->sentData.front().getName()[-1].toSegment(), 1); + BOOST_REQUIRE(!faces[0]->sentData.empty()); + BOOST_CHECK_EQUAL(faces[0]->sentData.front().getName().at(-1).toSegment(), 1); } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test-iblt.cpp b/tests/test-iblt.cpp index a2bb449..c689596 100644 --- a/tests/test-iblt.cpp +++ b/tests/test-iblt.cpp @@ -20,8 +20,8 @@ #include "PSync/detail/iblt.hpp" #include "PSync/detail/util.hpp" -#include -#include +#include "tests/boost-test.hpp" + #include namespace psync { @@ -71,40 +71,38 @@ static const uint8_t IBF[] = { BOOST_AUTO_TEST_CASE(NameAppendAndExtract) { - int size = 10; + const int size = 10; IBLT iblt(size, CompressionScheme::DEFAULT); - std::string prefix = Name("/test/memphis").appendNumber(1).toUri(); - uint32_t newHash = murmurHash3(11, prefix); - iblt.insert(newHash); + auto prefix = Name("/test/memphis").appendNumber(1).toUri(); + auto hash = murmurHash3(11, prefix); + iblt.insert(hash); - Name ibltName("sync"); + Name ibltName("/sync"); iblt.appendToName(ibltName); IBLT rcvd(size, CompressionScheme::DEFAULT); - rcvd.initialize(ibltName.get(-1)); - + rcvd.initialize(ibltName.at(-1)); BOOST_CHECK_EQUAL(iblt, rcvd); IBLT rcvdDiffSize(20, CompressionScheme::DEFAULT); - BOOST_CHECK_THROW(rcvdDiffSize.initialize(ibltName.get(-1)), IBLT::Error); + BOOST_CHECK_THROW(rcvdDiffSize.initialize(ibltName.at(-1)), IBLT::Error); - Name malformedName("test"); + IBLT iblt2(size, CompressionScheme::NONE); + iblt2.insert(hash); + Name ibltName2("/sync"); + iblt2.appendToName(ibltName2); + BOOST_CHECK_EQUAL_COLLECTIONS(IBF, IBF + sizeof(IBF), + ibltName2.at(-1).wireEncode().begin(), + ibltName2.at(-1).wireEncode().end()); + + Name malformedName("/test"); auto compressed = compress(CompressionScheme::DEFAULT, malformedName.wireEncode().value(), malformedName.wireEncode().value_size()); - IBLT rcvdDiffSize1(size, CompressionScheme::DEFAULT); malformedName.append(compressed->data(), compressed->size()); - BOOST_CHECK_THROW(rcvdDiffSize1.initialize(malformedName.get(-1)), IBLT::Error); - - IBLT iblt2(size, CompressionScheme::NONE); - iblt2.insert(newHash); - Name ibltName2("sync"); - iblt2.appendToName(ibltName2); - - BOOST_CHECK_EQUAL_COLLECTIONS(IBF, IBF + sizeof(IBF), - ibltName2.get(-1).wireEncode().begin(), - ibltName2.get(-1).wireEncode().end()); + IBLT rcvd2(size, CompressionScheme::DEFAULT); + BOOST_CHECK_THROW(rcvd2.initialize(malformedName.at(-1)), IBLT::Error); } BOOST_AUTO_TEST_CASE(CopyInsertErase) @@ -233,4 +231,4 @@ BOOST_AUTO_TEST_CASE(DifferenceBwOversizedIBFs) BOOST_AUTO_TEST_SUITE_END() -} // namespace psync \ No newline at end of file +} // namespace psync diff --git a/tests/test-partial-producer.cpp b/tests/test-partial-producer.cpp index c55fd22..ffddac8 100644 --- a/tests/test-partial-producer.cpp +++ b/tests/test-partial-producer.cpp @@ -19,15 +19,15 @@ #include "PSync/partial-producer.hpp" -#include +#include "tests/boost-test.hpp" + #include -#include #include +#include namespace psync { using namespace ndn; -using namespace std; BOOST_AUTO_TEST_SUITE(TestPartialProducer) @@ -46,12 +46,9 @@ BOOST_AUTO_TEST_CASE(RegisterPrefix) face.processEvents(time::milliseconds(-1)); BOOST_REQUIRE_EQUAL(face.sentInterests.size(), 1); - - face.sentInterests.back(); - Interest interest = *face.sentInterests.begin(); - BOOST_CHECK_EQUAL(interest.getName().get(3), name::Component("register")); - name::Component test = interest.getName().get(4); - nfd::ControlParameters params(test.blockFromValue()); + auto interest = face.sentInterests.front(); + BOOST_CHECK_EQUAL(interest.getName().at(3), name::Component("register")); + nfd::ControlParameters params(interest.getName().at(4).blockFromValue()); BOOST_CHECK_EQUAL(params.getName(), syncPrefix); } @@ -144,4 +141,4 @@ BOOST_AUTO_TEST_CASE(OnSyncInterest) BOOST_AUTO_TEST_SUITE_END() -} // namespace psync \ No newline at end of file +} // namespace psync diff --git a/tests/test-partial-sync.cpp b/tests/test-partial-sync.cpp index fae7958..31058ff 100644 --- a/tests/test-partial-sync.cpp +++ b/tests/test-partial-sync.cpp @@ -19,26 +19,26 @@ #include "PSync/partial-producer.hpp" #include "PSync/consumer.hpp" -#include "unit-test-time-fixture.hpp" -#include +#include "tests/boost-test.hpp" +#include "tests/unit-test-time-fixture.hpp" + #include #include namespace psync { using namespace ndn; -using namespace std; class PartialSyncFixture : public tests::UnitTestTimeFixture { public: PartialSyncFixture() - : face(io, {true, true}) - , syncPrefix("psync") - , userPrefix("testUser-0") - , numHelloDataRcvd(0) - , numSyncDataRcvd(0) + : face(io, {true, true}) + , syncPrefix("psync") + , userPrefix("testUser-0") + , numHelloDataRcvd(0) + , numSyncDataRcvd(0) { producer = make_shared(40, face, syncPrefix, userPrefix); addUserNodes("testUser", 10); @@ -54,16 +54,16 @@ public: } void - addConsumer(int id, const vector& subscribeTo, bool linkToProducer = true) + addConsumer(int id, const std::vector& subscribeTo, bool linkToProducer = true) { - consumerFaces[id] = make_shared(io, util::DummyClientFace::Options{true, true}); + consumerFaces[id] = std::make_shared(io, util::DummyClientFace::Options{true, true}); if (linkToProducer) { face.linkTo(*consumerFaces[id]); } - consumers[id] = make_shared(syncPrefix, *consumerFaces[id], - [&, id] (const vector& availableSubs) + consumers[id] = std::make_shared(syncPrefix, *consumerFaces[id], + [&, id] (const std::vector& availableSubs) { numHelloDataRcvd++; BOOST_CHECK(checkSubList(availableSubs)); @@ -100,9 +100,9 @@ public: } bool - checkSubList(const vector& availableSubs) + checkSubList(const std::vector& availableSubs) const { - for (const auto& prefix : producer->m_prefixes ) { + for (const auto& prefix : producer->m_prefixes) { if (std::find(availableSubs.begin(), availableSubs.end(), prefix.first) == availableSubs.end()) { return false; } @@ -151,7 +151,7 @@ BOOST_FIXTURE_TEST_SUITE(TestPartialSync, PartialSyncFixture) BOOST_AUTO_TEST_CASE(Simple) { - vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; + std::vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; addConsumer(0, subscribeTo); consumers[0]->sendHelloInterest(); @@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE(Simple) BOOST_AUTO_TEST_CASE(MissedUpdate) { - vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; + std::vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; addConsumer(0, subscribeTo); consumers[0]->sendHelloInterest(); @@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE(MissedUpdate) BOOST_AUTO_TEST_CASE(LateSubscription) { - vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; + std::vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; addConsumer(0, subscribeTo); consumers[0]->sendHelloInterest(); @@ -207,7 +207,7 @@ BOOST_AUTO_TEST_CASE(LateSubscription) BOOST_AUTO_TEST_CASE(ConsumerSyncTimeout) { - vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; + std::vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; addConsumer(0, subscribeTo); consumers[0]->sendHelloInterest(); @@ -230,7 +230,7 @@ BOOST_AUTO_TEST_CASE(ConsumerSyncTimeout) BOOST_AUTO_TEST_CASE(MultipleConsumersWithSameSubList) { - vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; + std::vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; addConsumer(0, subscribeTo); addConsumer(1, subscribeTo); addConsumer(2, subscribeTo); @@ -251,13 +251,13 @@ BOOST_AUTO_TEST_CASE(MultipleConsumersWithSameSubList) BOOST_AUTO_TEST_CASE(MultipleConsumersWithDifferentSubList) { - vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; + std::vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; addConsumer(0, subscribeTo); - vector subscribeTo1{"testUser-1", "testUser-3", "testUser-5"}; + std::vector subscribeTo1{"testUser-1", "testUser-3", "testUser-5"}; addConsumer(1, subscribeTo1); - vector subscribeTo2{"testUser-2", "testUser-3"}; + std::vector subscribeTo2{"testUser-2", "testUser-3"}; addConsumer(2, subscribeTo2); consumers[0]->sendHelloInterest(); @@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE(MultipleConsumersWithDifferentSubList) BOOST_AUTO_TEST_CASE(ReplicatedProducer) { - vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; + std::vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; addConsumer(0, subscribeTo); consumers[0]->sendHelloInterest(); @@ -316,7 +316,7 @@ BOOST_AUTO_TEST_CASE(ApplicationNack) // 50 is more than expected number of entries of 40 in the producer's IBF addUserNodes("testUser", 50); - vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; + std::vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; addConsumer(0, subscribeTo); consumers[0]->sendHelloInterest(); @@ -354,7 +354,7 @@ BOOST_AUTO_TEST_CASE(ApplicationNack) BOOST_AUTO_TEST_CASE(SegmentedHello) { - vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; + std::vector subscribeTo{"testUser-2", "testUser-4", "testUser-6"}; addConsumer(0, subscribeTo); addUserNodes("testUser", 400); @@ -364,6 +364,7 @@ BOOST_AUTO_TEST_CASE(SegmentedHello) BOOST_CHECK_EQUAL(numHelloDataRcvd, 1); // Simulate sending delayed interest for second segment + BOOST_REQUIRE(!face.sentData.empty()); Name dataName = face.sentData.back().getName(); face.sentData.clear(); BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2); @@ -374,7 +375,8 @@ BOOST_AUTO_TEST_CASE(SegmentedHello) producer->onHelloInterest(consumers[0]->m_helloInterestPrefix, Interest(dataName)); advanceClocks(ndn::time::milliseconds(10)); BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2); - BOOST_CHECK_EQUAL(face.sentData.front().getName()[-1].toSegment(), 1); + BOOST_REQUIRE(!face.sentData.empty()); + BOOST_CHECK_EQUAL(face.sentData.front().getName().at(-1).toSegment(), 1); } BOOST_AUTO_TEST_CASE(SegmentedSync) @@ -385,7 +387,7 @@ BOOST_AUTO_TEST_CASE(SegmentedSync) } addUserNodes(longNameToExceedDataSize.toUri(), 10); - vector subscribeTo; + std::vector subscribeTo; for (int i = 1; i < 10; i++) { subscribeTo.push_back(longNameToExceedDataSize.toUri() + "-" + to_string(i)); } @@ -425,7 +427,8 @@ BOOST_AUTO_TEST_CASE(SegmentedSync) producer->onSyncInterest(consumers[0]->m_syncInterestPrefix, Interest(syncInterestName)); advanceClocks(ndn::time::milliseconds(10)); BOOST_CHECK_EQUAL(producer->m_segmentPublisher.m_ims.size(), 2); - BOOST_CHECK_EQUAL(face.sentData.front().getName()[-1].toSegment(), 1); + BOOST_REQUIRE(!face.sentData.empty()); + BOOST_CHECK_EQUAL(face.sentData.front().getName().at(-1).toSegment(), 1); } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test-producer-base.cpp b/tests/test-producer-base.cpp index c5f1112..e3a813c 100644 --- a/tests/test-producer-base.cpp +++ b/tests/test-producer-base.cpp @@ -20,8 +20,8 @@ #include "PSync/producer-base.hpp" #include "PSync/detail/util.hpp" -#include -#include +#include "tests/boost-test.hpp" + #include #include #include @@ -75,10 +75,9 @@ BOOST_AUTO_TEST_CASE(ApplicationNack) producerBase.m_syncReplyFreshness = time::milliseconds(1000); producerBase.sendApplicationNack(Name("test")); face.processEvents(time::milliseconds(10)); - BOOST_CHECK_EQUAL(face.sentData.size(), 1); - Data data = *face.sentData.begin(); - BOOST_CHECK_EQUAL(data.getContentType(), ndn::tlv::ContentType_Nack); + BOOST_REQUIRE_EQUAL(face.sentData.size(), 1); + BOOST_CHECK_EQUAL(face.sentData.front().getContentType(), ndn::tlv::ContentType_Nack); } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test-segment-publisher.cpp b/tests/test-segment-publisher.cpp index 46e6c5c..55db765 100644 --- a/tests/test-segment-publisher.cpp +++ b/tests/test-segment-publisher.cpp @@ -19,10 +19,10 @@ #include "PSync/segment-publisher.hpp" #include "PSync/detail/state.hpp" -#include "unit-test-time-fixture.hpp" -#include -#include +#include "tests/boost-test.hpp" +#include "tests/unit-test-time-fixture.hpp" + #include #include #include diff --git a/tests/test-state.cpp b/tests/test-state.cpp index 6d7239c..3f04c8b 100644 --- a/tests/test-state.cpp +++ b/tests/test-state.cpp @@ -19,8 +19,8 @@ #include "PSync/detail/state.hpp" -#include -#include +#include "tests/boost-test.hpp" + #include namespace psync { @@ -90,4 +90,4 @@ BOOST_AUTO_TEST_CASE(ReEncode) BOOST_AUTO_TEST_SUITE_END() -} // namespace psync \ No newline at end of file +} // namespace psync diff --git a/tests/test-util.cpp b/tests/test-util.cpp index 2ec1de8..bea4e68 100644 --- a/tests/test-util.cpp +++ b/tests/test-util.cpp @@ -18,17 +18,11 @@ **/ #include "PSync/detail/util.hpp" -#include "PSync/detail/config.hpp" -#include "unit-test-time-fixture.hpp" -#include -#include +#include "tests/boost-test.hpp" namespace psync { -using namespace ndn; -using namespace std; - BOOST_AUTO_TEST_SUITE(TestUtil) BOOST_AUTO_TEST_CASE(Basic) @@ -76,4 +70,4 @@ BOOST_AUTO_TEST_CASE(Basic) BOOST_AUTO_TEST_SUITE_END() -} // namespace psync \ No newline at end of file +} // namespace psync