From 8663ed1c2149b4950c17f3d2366868ac9535de18 Mon Sep 17 00:00:00 2001 From: Davide Pesavento Date: Sat, 23 Jul 2022 03:04:27 -0400 Subject: [PATCH] build: migrate to C++17 Change-Id: Ic5c01274f62556764ea96fc232cf3d835c4ab659 --- .jenkins.d/40-headers-check.sh | 2 +- .waf-tools/default-compiler-flags.py | 2 +- src/detail/bzip2-helper.cpp | 8 ++-- src/detail/bzip2-helper.hpp | 8 ++-- src/detail/common.hpp | 7 ++-- src/detail/tlv.hpp | 8 ++-- src/logic.cpp | 52 ++++++++----------------- src/logic.hpp | 40 ++++++++----------- src/socket.cpp | 8 ++-- src/socket.hpp | 21 ++++------ src/state.cpp | 8 ++-- tests/identity-management-fixture.cpp | 8 ++-- tests/identity-management-fixture.hpp | 14 +++---- tests/unit-test-time-fixture.hpp | 14 +++---- tests/unit-tests/test-logic.cpp | 6 +-- tests/unit-tests/test-multiple-user.cpp | 20 +++------- tests/unit-tests/test-socket.cpp | 12 +++--- 17 files changed, 91 insertions(+), 147 deletions(-) diff --git a/.jenkins.d/40-headers-check.sh b/.jenkins.d/40-headers-check.sh index efc3bf9..b0f9987 100755 --- a/.jenkins.d/40-headers-check.sh +++ b/.jenkins.d/40-headers-check.sh @@ -17,7 +17,7 @@ if has CentOS-8 $NODE_LABELS; then fi CXX=${CXX:-g++} -STD=-std=c++14 +STD=-std=c++17 CXXFLAGS="-O2 -Wall -Wno-unneeded-internal-declaration -Wno-unused-const-variable $(pkg-config --cflags libndn-cxx $PROJ)" INCLUDEDIR="$(pkg-config --variable=includedir $PROJ)"/$PROJ diff --git a/.waf-tools/default-compiler-flags.py b/.waf-tools/default-compiler-flags.py index f086c17..7c6d282 100644 --- a/.waf-tools/default-compiler-flags.py +++ b/.waf-tools/default-compiler-flags.py @@ -136,7 +136,7 @@ class GccBasicFlags(CompilerFlags): """ def getGeneralFlags(self, conf): flags = super(GccBasicFlags, self).getGeneralFlags(conf) - flags['CXXFLAGS'] += ['-std=c++14'] + flags['CXXFLAGS'] += ['-std=c++17'] if Utils.unversioned_sys_platform() == 'linux': flags['LINKFLAGS'] += ['-fuse-ld=gold'] elif Utils.unversioned_sys_platform() == 'freebsd': diff --git a/src/detail/bzip2-helper.cpp b/src/detail/bzip2-helper.cpp index 4c5617e..a774b50 100644 --- a/src/detail/bzip2-helper.cpp +++ b/src/detail/bzip2-helper.cpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2021 University of California, Los Angeles + * Copyright (c) 2012-2022 University of California, Los Angeles * * This file is part of ChronoSync, synchronization library for distributed realtime * applications for NDN. @@ -27,8 +27,7 @@ #include -namespace chronosync { -namespace bzip2 { +namespace chronosync::bzip2 { namespace bio = boost::iostreams; @@ -56,5 +55,4 @@ decompress(const char* buffer, size_t bufferSize) return os.buf(); } -} // namespace bzip2 -} // namespace chronosync +} // namespace chronosync::bzip2 diff --git a/src/detail/bzip2-helper.hpp b/src/detail/bzip2-helper.hpp index 47ff5ac..9eb966d 100644 --- a/src/detail/bzip2-helper.hpp +++ b/src/detail/bzip2-helper.hpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2021 University of California, Los Angeles + * Copyright (c) 2012-2022 University of California, Los Angeles * * This file is part of ChronoSync, synchronization library for distributed realtime * applications for NDN. @@ -22,8 +22,7 @@ #include -namespace chronosync { -namespace bzip2 { +namespace chronosync::bzip2 { /** * @brief Compress @p buffer of size @p bufferSize with bzip2 @@ -37,7 +36,6 @@ compress(const char* buffer, size_t bufferSize); std::shared_ptr decompress(const char* buffer, size_t bufferSize); -} // namespace bzip2 -} // namespace chronosync +} // namespace chronosync::bzip2 #endif // CHRONOSYNC_DETAIL_BZIP2_HELPER_HPP diff --git a/src/detail/common.hpp b/src/detail/common.hpp index dffd218..cb75626 100644 --- a/src/detail/common.hpp +++ b/src/detail/common.hpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2021 University of California, Los Angeles + * Copyright (c) 2012-2022 University of California, Los Angeles * * This file is part of ChronoSync, synchronization library for distributed realtime * applications for NDN. @@ -65,9 +65,7 @@ using boost::noncopyable; using std::size_t; using std::bind; -using std::function; using std::make_shared; -using std::ref; using std::shared_ptr; using ndn::Block; @@ -79,8 +77,9 @@ using ndn::security::Validator; using ndn::security::ValidationError; namespace name = ndn::name; -namespace time = ndn::time; namespace security = ndn::security; +namespace time = ndn::time; +using namespace ndn::time_literals; } // namespace chronosync diff --git a/src/detail/tlv.hpp b/src/detail/tlv.hpp index 5f9bd31..2a4b9b1 100644 --- a/src/detail/tlv.hpp +++ b/src/detail/tlv.hpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2021 University of California, Los Angeles + * Copyright (c) 2012-2022 University of California, Los Angeles * * This file is part of ChronoSync, synchronization library for distributed realtime * applications for NDN. @@ -22,8 +22,7 @@ #ifndef CHRONOSYNC_DETAIL_TLV_HPP #define CHRONOSYNC_DETAIL_TLV_HPP -namespace chronosync { -namespace tlv { +namespace chronosync::tlv { /** * @brief Type value of sync reply related TLVs @@ -35,7 +34,6 @@ enum { SeqNo = 130, // 0x82 }; -} // namespace tlv -} // namespace chronosync +} // namespace chronosync::tlv #endif // CHRONOSYNC_DETAIL_TLV_HPP diff --git a/src/logic.cpp b/src/logic.cpp index 05defbd..387690d 100644 --- a/src/logic.cpp +++ b/src/logic.cpp @@ -37,29 +37,15 @@ NDN_LOG_INIT(sync.Logic); namespace chronosync { -const uint8_t EMPTY_DIGEST_VALUE[] = { +const std::vector EMPTY_DIGEST{ 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55 }; -int Logic::s_instanceCounter = 0; - -const ndn::Name Logic::DEFAULT_NAME; -const ndn::Name Logic::EMPTY_NAME; -const std::shared_ptr Logic::DEFAULT_VALIDATOR; -const time::steady_clock::Duration Logic::DEFAULT_RESET_TIMER = time::seconds(0); -const time::steady_clock::Duration Logic::DEFAULT_CANCEL_RESET_TIMER = time::milliseconds(500); -const time::milliseconds Logic::DEFAULT_RESET_INTEREST_LIFETIME(1000); -const time::milliseconds Logic::DEFAULT_SYNC_INTEREST_LIFETIME(1000); -const time::milliseconds Logic::DEFAULT_SYNC_REPLY_FRESHNESS(1000); -const time::milliseconds Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME(1000); - -const ConstBufferPtr Logic::EMPTY_DIGEST(new ndn::Buffer(EMPTY_DIGEST_VALUE, 32)); -const ndn::name::Component Logic::RESET_COMPONENT("reset"); -const ndn::name::Component Logic::RECOVERY_COMPONENT("recovery"); - +const name::Component RESET_COMPONENT("reset"); +const name::Component RECOVERY_COMPONENT("recovery"); const size_t NDNLP_EXPECTED_OVERHEAD = 20; /** @@ -84,7 +70,7 @@ getMaxPacketLimit() if (getenv("CHRONOSYNC_MAX_PACKET_SIZE") != nullptr) { try { - limit = ndn::clamp(boost::lexical_cast(getenv("CHRONOSYNC_MAX_PACKET_SIZE")), + limit = std::clamp(boost::lexical_cast(getenv("CHRONOSYNC_MAX_PACKET_SIZE")), 500, ndn::MAX_NDN_PACKET_SIZE); } catch (const boost::bad_lexical_cast&) { @@ -104,8 +90,8 @@ Logic::Logic(ndn::Face& face, const UpdateCallback& onUpdate, const Name& defaultSigningId, std::shared_ptr validator, - const time::steady_clock::Duration& resetTimer, - const time::steady_clock::Duration& cancelResetTimer, + const time::steady_clock::duration& resetTimer, + const time::steady_clock::duration& cancelResetTimer, const time::milliseconds& resetInterestLifetime, const time::milliseconds& syncInterestLifetime, const time::milliseconds& syncReplyFreshness, @@ -129,7 +115,7 @@ Logic::Logic(ndn::Face& face, , m_syncInterestLifetime(syncInterestLifetime) , m_syncReplyFreshness(syncReplyFreshness) , m_recoveryInterestLifetime(recoveryInterestLifetime) - , m_validator(validator) + , m_validator(std::move(validator)) , m_instanceId(s_instanceCounter++) { CHRONO_LOG_DBG(">> Logic::Logic"); @@ -275,19 +261,16 @@ Logic::updateSeqNo(const SeqNo& seqNo, const Name& updatePrefix) ConstBufferPtr previousRoot = m_state.getRootDigest(); printDigest(previousRoot); - bool isInserted = false; - bool isUpdated = false; - SeqNo oldSeq; - std::tie(isInserted, isUpdated, oldSeq) = m_state.update(node.sessionName, node.seqNo); - + auto [isInserted, isUpdated, oldSeq] = m_state.update(node.sessionName, node.seqNo); CHRONO_LOG_DBG("Insert: " << std::boolalpha << isInserted); CHRONO_LOG_DBG("Updated: " << std::boolalpha << isUpdated); + (void)oldSeq; // silence "unused variable" warning with gcc 7 + if (isInserted || isUpdated) { DiffStatePtr commit = make_shared(); commit->update(node.sessionName, node.seqNo); commit->setRootDigest(m_state.getRootDigest()); insertToDiffLog(commit, previousRoot); - satisfyPendingSyncInterests(prefix, commit); } } @@ -445,7 +428,7 @@ Logic::processSyncInterest(const Interest& interest, bool isTimedProcessing/*=fa } // If the digest of incoming interest is an "empty" digest - if (*digest == *EMPTY_DIGEST) { + if (*digest == EMPTY_DIGEST) { CHRONO_LOG_DBG("Poor guy, he knows nothing"); sendSyncData(m_defaultUserPrefix, name, m_state); return; @@ -505,10 +488,7 @@ Logic::processSyncData(const Name&, ConstBufferPtr digest, const Block& syncRepl const Name& info = leaf->getSessionName(); SeqNo seq = leaf->getSeq(); - bool isInserted = false; - bool isUpdated = false; - SeqNo oldSeq; - std::tie(isInserted, isUpdated, oldSeq) = m_state.update(info, seq); + auto [isInserted, isUpdated, oldSeq] = m_state.update(info, seq); if (isInserted || isUpdated) { commit->update(info, seq); oldSeq++; @@ -610,7 +590,7 @@ Logic::sendSyncInterest() Name interestName; interestName.append(m_syncPrefix) - .append(ndn::name::Component(*m_state.getRootDigest())); + .append(name::Component(*m_state.getRootDigest())); m_pendingSyncInterestName = interestName; @@ -688,7 +668,7 @@ Logic::encodeSyncReply(const Name& nodePrefix, const Name& name, const State& st trimState(partialState, state, nExcludedStates); finalizeReply(partialState); - BOOST_ASSERT(state.getLeaves().size() != 0); + BOOST_ASSERT(!state.getLeaves().empty()); nExcludedStates *= 2; } @@ -746,7 +726,7 @@ Logic::sendRecoveryInterest(ConstBufferPtr digest) Name interestName; interestName.append(m_syncPrefix) .append(RECOVERY_COMPONENT) - .append(ndn::name::Component(*digest)); + .append(name::Component(*digest)); Interest interest(interestName); interest.setMustBeFresh(true); @@ -771,7 +751,7 @@ Logic::processRecoveryInterest(const Interest& interest) ConstBufferPtr rootDigest = m_state.getRootDigest(); auto stateIter = m_log.find(digest); - if (stateIter != m_log.end() || *digest == *EMPTY_DIGEST || *rootDigest == *digest) { + if (stateIter != m_log.end() || *digest == EMPTY_DIGEST || *rootDigest == *digest) { CHRONO_LOG_DBG("I can help you recover"); sendSyncData(m_defaultUserPrefix, name, m_state); return; diff --git a/src/logic.hpp b/src/logic.hpp index 1383ef2..b180ca0 100644 --- a/src/logic.hpp +++ b/src/logic.hpp @@ -70,7 +70,7 @@ public: * The parameter is a set of MissingDataInfo, of which each corresponds to * a session that has changed its state. */ -using UpdateCallback = function&)>; +using UpdateCallback = std::function&)>; /** * @brief Logic of ChronoSync @@ -84,12 +84,15 @@ public: using std::runtime_error::runtime_error; }; - static const time::steady_clock::Duration DEFAULT_RESET_TIMER; - static const time::steady_clock::Duration DEFAULT_CANCEL_RESET_TIMER; - static const time::milliseconds DEFAULT_RESET_INTEREST_LIFETIME; - static const time::milliseconds DEFAULT_SYNC_INTEREST_LIFETIME; - static const time::milliseconds DEFAULT_SYNC_REPLY_FRESHNESS; - static const time::milliseconds DEFAULT_RECOVERY_INTEREST_LIFETIME; + static inline const Name EMPTY_NAME; + static inline const Name DEFAULT_NAME; + static inline const std::shared_ptr DEFAULT_VALIDATOR; + static constexpr time::steady_clock::duration DEFAULT_RESET_TIMER = 0_ms; + static constexpr time::steady_clock::duration DEFAULT_CANCEL_RESET_TIMER = 500_ms; + static constexpr time::milliseconds DEFAULT_RESET_INTEREST_LIFETIME = 1_s; + static constexpr time::milliseconds DEFAULT_SYNC_INTEREST_LIFETIME = 1_s; + static constexpr time::milliseconds DEFAULT_SYNC_REPLY_FRESHNESS = 1_s; + static constexpr time::milliseconds DEFAULT_RECOVERY_INTEREST_LIFETIME = 1_s; /** * @brief Constructor @@ -114,8 +117,8 @@ public: const UpdateCallback& onUpdate, const Name& defaultSigningId = DEFAULT_NAME, std::shared_ptr validator = DEFAULT_VALIDATOR, - const time::steady_clock::Duration& resetTimer = DEFAULT_RESET_TIMER, - const time::steady_clock::Duration& cancelResetTimer = DEFAULT_CANCEL_RESET_TIMER, + const time::steady_clock::duration& resetTimer = DEFAULT_RESET_TIMER, + const time::steady_clock::duration& cancelResetTimer = DEFAULT_CANCEL_RESET_TIMER, const time::milliseconds& resetInterestLifetime = DEFAULT_RESET_INTEREST_LIFETIME, const time::milliseconds& syncInterestLifetime = DEFAULT_SYNC_INTEREST_LIFETIME, const time::milliseconds& syncReplyFreshness = DEFAULT_SYNC_REPLY_FRESHNESS, @@ -442,17 +445,8 @@ private: void onRecoveryTimeout(const Interest& interest); -public: - static const ndn::Name DEFAULT_NAME; - static const ndn::Name EMPTY_NAME; - static const std::shared_ptr DEFAULT_VALIDATOR; - private: - using NodeList = std::unordered_map; - - static const ConstBufferPtr EMPTY_DIGEST; - static const ndn::name::Component RESET_COMPONENT; - static const ndn::name::Component RECOVERY_COMPONENT; + using NodeList = std::unordered_map; // Communication ndn::Face& m_face; @@ -487,9 +481,9 @@ private: std::uniform_int_distribution<> m_rangeUniformRandom; std::uniform_int_distribution<> m_reexpressionJitter; /// @brief Timer to send next reset 0 for no reset - time::steady_clock::Duration m_resetTimer; + time::steady_clock::duration m_resetTimer; /// @brief Timer to cancel reset state - time::steady_clock::Duration m_cancelResetTimer; + time::steady_clock::duration m_cancelResetTimer; /// @brief Lifetime of reset interest time::milliseconds m_resetInterestLifetime; /// @brief Lifetime of sync interest @@ -503,8 +497,8 @@ private: ndn::KeyChain m_keyChain; std::shared_ptr m_validator; - int m_instanceId; - static int s_instanceCounter; + const int m_instanceId; + static inline int s_instanceCounter = 0; }; #ifdef CHRONOSYNC_WITH_TESTS diff --git a/src/socket.cpp b/src/socket.cpp index e2c8b66..820b0a0 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -30,10 +30,6 @@ NDN_LOG_INIT(sync.Socket); namespace chronosync { -const ndn::Name Socket::DEFAULT_NAME; -const ndn::Name Socket::DEFAULT_PREFIX; -const std::shared_ptr Socket::DEFAULT_VALIDATOR; - Socket::Socket(const Name& syncPrefix, const Name& userPrefix, ndn::Face& face, @@ -49,14 +45,16 @@ Socket::Socket(const Name& syncPrefix, syncInterestLifetime, Logic::DEFAULT_SYNC_REPLY_FRESHNESS, Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME, session) , m_signingId(signingId) - , m_validator(validator) + , m_validator(std::move(validator)) { NDN_LOG_DEBUG(">> Socket::Socket"); + if (m_userPrefix != DEFAULT_NAME) m_registeredPrefixList[m_userPrefix] = m_face.setInterestFilter(m_userPrefix, [this] (auto&&... args) { onInterest(std::forward(args)...); }, [] (auto&&...) {}); + NDN_LOG_DEBUG("<< Socket::Socket"); } diff --git a/src/socket.hpp b/src/socket.hpp index e7fb4ef..78e67d2 100644 --- a/src/socket.hpp +++ b/src/socket.hpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2019 University of California, Los Angeles + * Copyright (c) 2012-2022 University of California, Los Angeles * * This file is part of ChronoSync, synchronization library for distributed realtime * applications for NDN. @@ -52,11 +52,7 @@ public: class Error : public std::runtime_error { public: - explicit - Error(const std::string& what) - : std::runtime_error(what) - { - } + using std::runtime_error::runtime_error; }; Socket(const Name& syncPrefix, @@ -70,9 +66,8 @@ public: ~Socket(); - using DataValidatedCallback = function; - - using DataValidationErrorCallback = function ; + using DataValidatedCallback = std::function; + using DataValidationErrorCallback = std::function ; /** * @brief Add a sync node under same logic @@ -232,12 +227,12 @@ private: const ValidationError& error); public: - static const ndn::Name DEFAULT_NAME; - static const ndn::Name DEFAULT_PREFIX; - static const std::shared_ptr DEFAULT_VALIDATOR; + static inline const Name DEFAULT_NAME; + static inline const Name DEFAULT_PREFIX; + static inline const std::shared_ptr DEFAULT_VALIDATOR; private: - using RegisteredPrefixList = std::unordered_map; + using RegisteredPrefixList = std::unordered_map; Name m_userPrefix; ndn::Face& m_face; diff --git a/src/state.cpp b/src/state.cpp index 00df7b9..260d493 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -40,16 +40,16 @@ State::update(const Name& info, const SeqNo& seq) auto leaf = m_leaves.find(info); if (leaf == m_leaves.end()) { m_leaves.insert(make_shared(info, seq)); - return std::make_tuple(true, false, 0); + return {true, false, 0}; } else { if ((*leaf)->getSeq() == seq || seq < (*leaf)->getSeq()) { - return std::make_tuple(false, false, 0); + return {false, false, 0}; } SeqNo old = (*leaf)->getSeq(); m_leaves.modify(leaf, [seq] (LeafPtr& leaf) { leaf->setSeq(seq); } ); - return std::make_tuple(false, true, old); + return {false, true, old}; } } @@ -128,7 +128,7 @@ State::wireDecode(const Block& wire) NDN_THROW(Error("The supplied block does not contain wire format")); if (wire.type() != tlv::SyncReply) - NDN_THROW(Error("Unexpected TLV type when decoding SyncReply: " + ndn::to_string(wire.type()))); + NDN_THROW(Error("Unexpected TLV type when decoding SyncReply: " + std::to_string(wire.type()))); wire.parse(); m_wire = wire; diff --git a/tests/identity-management-fixture.cpp b/tests/identity-management-fixture.cpp index 007b35b..f545710 100644 --- a/tests/identity-management-fixture.cpp +++ b/tests/identity-management-fixture.cpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2017 University of California, Los Angeles + * Copyright (c) 2012-2022 University of California, Los Angeles * * This file is part of ChronoSync, synchronization library for distributed realtime * applications for NDN. @@ -22,8 +22,7 @@ #include #include -namespace ndn { -namespace tests { +namespace ndn::tests { IdentityManagementFixture::IdentityManagementFixture() : m_keyChain("pib-memory:", "tpm-memory:") @@ -75,5 +74,4 @@ IdentityManagementFixture::saveIdentityCertificate(const Name& identity, const s } } -} // namespace tests -} // namespace ndn +} // namespace ndn::tests diff --git a/tests/identity-management-fixture.hpp b/tests/identity-management-fixture.hpp index 7bb39f8..6b81859 100644 --- a/tests/identity-management-fixture.hpp +++ b/tests/identity-management-fixture.hpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2021 University of California, Los Angeles + * Copyright (c) 2012-2022 University of California, Los Angeles * * This file is part of ChronoSync, synchronization library for distributed realtime * applications for NDN. @@ -17,15 +17,14 @@ * ChronoSync, e.g., in COPYING.md file. If not, see . */ -#ifndef NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP -#define NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP +#ifndef CHRONOSYNC_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP +#define CHRONOSYNC_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP #include "detail/common.hpp" #include "unit-test-time-fixture.hpp" -namespace ndn { -namespace tests { +namespace ndn::tests { /** \brief a fixture that cleans up KeyChain identities and certificate files upon destruction */ @@ -69,7 +68,6 @@ class IdentityManagementTimeFixture : public UnitTestTimeFixture { }; -} // namespace tests -} // namespace ndn +} // namespace ndn::tests -#endif // NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP +#endif // CHRONOSYNC_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP diff --git a/tests/unit-test-time-fixture.hpp b/tests/unit-test-time-fixture.hpp index f172cff..a8b46f7 100644 --- a/tests/unit-test-time-fixture.hpp +++ b/tests/unit-test-time-fixture.hpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2017 University of California, Los Angeles + * Copyright (c) 2012-2022 University of California, Los Angeles * * This file is part of ChronoSync, synchronization library for distributed realtime * applications for NDN. @@ -17,15 +17,14 @@ * ChronoSync, e.g., in COPYING.md file. If not, see . */ -#ifndef NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP -#define NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP +#ifndef CHRONOSYNC_TESTS_UNIT_TEST_TIME_FIXTURE_HPP +#define CHRONOSYNC_TESTS_UNIT_TEST_TIME_FIXTURE_HPP #include #include -namespace ndn { -namespace tests { +namespace ndn::tests { class UnitTestTimeFixture { @@ -61,7 +60,6 @@ public: boost::asio::io_service io; }; -} // namespace tests -} // namespace ndn +} // namespace ndn::tests -#endif // NDN_TESTS_UNIT_TESTS_UNIT_TEST_TIME_FIXTURE_HPP +#endif // CHRONOSYNC_TESTS_UNIT_TEST_TIME_FIXTURE_HPP diff --git a/tests/unit-tests/test-logic.cpp b/tests/unit-tests/test-logic.cpp index 8459158..d883fe7 100644 --- a/tests/unit-tests/test-logic.cpp +++ b/tests/unit-tests/test-logic.cpp @@ -432,12 +432,12 @@ public: { unsetenv("CHRONOSYNC_MAX_PACKET_SIZE"); if (oldSize) { - setenv("CHRONOSYNC_MAX_PACKET_SIZE", oldSize->c_str(), 1); + setenv("CHRONOSYNC_MAX_PACKET_SIZE", oldSize->data(), 1); } } private: - ndn::optional oldSize; + std::optional oldSize; }; BOOST_FIXTURE_TEST_CASE(MaxPacketCustomization, MaxPacketCustomizationFixture) @@ -447,7 +447,7 @@ BOOST_FIXTURE_TEST_CASE(MaxPacketCustomization, MaxPacketCustomizationFixture) setenv("CHRONOSYNC_MAX_PACKET_SIZE", "1500", 1); BOOST_CHECK_EQUAL(getMaxPacketLimit(), 1500); - setenv("CHRONOSYNC_MAX_PACKET_SIZE", ndn::to_string(ndn::MAX_NDN_PACKET_SIZE * 100).c_str(), 1); + setenv("CHRONOSYNC_MAX_PACKET_SIZE", std::to_string(ndn::MAX_NDN_PACKET_SIZE * 100).data(), 1); BOOST_CHECK_EQUAL(getMaxPacketLimit(), ndn::MAX_NDN_PACKET_SIZE); setenv("CHRONOSYNC_MAX_PACKET_SIZE", "1", 1); diff --git a/tests/unit-tests/test-multiple-user.cpp b/tests/unit-tests/test-multiple-user.cpp index db8ffcf..b8a5dbd 100644 --- a/tests/unit-tests/test-multiple-user.cpp +++ b/tests/unit-tests/test-multiple-user.cpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2019 University of California, Los Angeles + * Copyright (c) 2012-2022 University of California, Los Angeles * * This file is part of ChronoSync, synchronization library for distributed realtime * applications for NDN. @@ -27,18 +27,8 @@ namespace test { class Handler { public: - Handler(ndn::Face& face, - const Name& syncPrefix, - const Name& userPrefix) - : logic(face, - syncPrefix, - userPrefix, - bind(&Handler::onUpdate, this, _1)) - { - } - - void - onUpdate(const std::vector& v) + Handler(ndn::Face& face, const Name& syncPrefix, const Name& userPrefix) + : logic(face, syncPrefix, userPrefix, [] (auto&&...) {}) { } @@ -76,7 +66,7 @@ public: userPrefix[1] = Name("/user1"); userPrefix[2] = Name("/user2"); - face = make_shared(ref(io)); + face = std::make_shared(io); } Name syncPrefix; @@ -92,7 +82,7 @@ BOOST_FIXTURE_TEST_SUITE(MultiUserTests, MultiUserFixture) BOOST_AUTO_TEST_CASE(ThreeUserNode) { - handler = make_shared(ref(*face), syncPrefix, userPrefix[0]); + handler = std::make_shared(*face, syncPrefix, userPrefix[0]); handler->addUserNode(userPrefix[1]); handler->addUserNode(userPrefix[2]); handler->removeUserNode(userPrefix[0]); diff --git a/tests/unit-tests/test-socket.cpp b/tests/unit-tests/test-socket.cpp index 3b16939..67f1c3e 100644 --- a/tests/unit-tests/test-socket.cpp +++ b/tests/unit-tests/test-socket.cpp @@ -1,6 +1,6 @@ /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ /* - * Copyright (c) 2012-2019 University of California, Los Angeles + * Copyright (c) 2012-2022 University of California, Los Angeles * * This file is part of ChronoSync, synchronization library for distributed realtime * applications for NDN. @@ -48,7 +48,7 @@ public: userPrefix, face, isNum ? bind(&SocketTestApp::fetchNumbers, this, _1) : - bind(&SocketTestApp::fetchAll, this, _1), + bind(&SocketTestApp::fetchAll, this, _1), Logic::DEFAULT_NAME, Logic::DEFAULT_VALIDATOR, Logic::DEFAULT_SYNC_INTEREST_LIFETIME, @@ -63,14 +63,14 @@ public: Name dataName(dataPacket.getName()); string str2(reinterpret_cast(dataPacket.getContent().value()), dataPacket.getContent().value_size()); - data.insert(make_pair(dataName, str2)); + data.emplace(dataName, str2); } void set(Name name, const char* buf, int len) { string str2(buf, len); - data.insert(make_pair(name, str2)); + data.emplace(name, str2); } void @@ -139,7 +139,7 @@ public: } public: - std::map data; + std::map data; uint32_t sum; Socket socket; }; @@ -194,7 +194,7 @@ public: void createSocket(size_t idx, bool isNum) { - app[idx] = make_shared(syncPrefix, userPrefix[idx], ref(*faces[idx]), isNum); + app[idx] = make_shared(syncPrefix, userPrefix[idx], std::ref(*faces[idx]), isNum); sessionName[idx] = app[idx]->socket.getLogic().getSessionName(); }