From 334516a019f8855bcb13cacadfe5b1a8c420114c Mon Sep 17 00:00:00 2001 From: Davide Pesavento Date: Fri, 9 Feb 2024 18:02:36 -0500 Subject: [PATCH] name: remove unused and redundant `push_back(const T&)` Change-Id: I88b9070eda34c31aea03d1772c14bdc596947b00 --- ndn-cxx/name.hpp | 80 +++++++++---------- tests/unit/name.t.cpp | 8 +- tests/unit/security/tpm/back-end.t.cpp | 5 +- .../security/validator-config/checker.t.cpp | 49 ++++++------ tests/unit/util/sha256.t.cpp | 10 ++- 5 files changed, 75 insertions(+), 77 deletions(-) diff --git a/ndn-cxx/name.hpp b/ndn-cxx/name.hpp index 5f72ef822..2a07f1bff 100644 --- a/ndn-cxx/name.hpp +++ b/ndn-cxx/name.hpp @@ -44,12 +44,10 @@ using PartialName = Name; class Name : private boost::totally_ordered { public: // nested types - using Error = name::Component::Error; - using Component = name::Component; - using component_container = std::vector; + using Error = Component::Error; - // Name appears as a container of name components + // Name appears as an ordered sequence of name components using value_type = Component; using allocator_type = void; using reference = Component&; @@ -60,8 +58,8 @@ class Name : private boost::totally_ordered using const_iterator = const Component*; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - using difference_type = component_container::difference_type; - using size_type = component_container::size_type; + using difference_type = std::vector::difference_type; + using size_type = std::vector::size_type; public: // constructors, encoding, decoding /** @@ -344,13 +342,14 @@ class Name : private boost::totally_ordered return append(Component(tlv::GenericNameComponent, value)); } - /** @brief Append a `NameComponent` of TLV-TYPE @p type, copying the TLV-VALUE from a range. - * @tparam Iterator an @c InputIterator dereferencing to a one-octet value type. More efficient - * implementation is available when it is a @c RandomAccessIterator. - * @param type the TLV-TYPE. - * @param first beginning of the range. - * @param last past-end of the range. - * @return A reference to this Name, to allow chaining. + /** + * @brief Append a `NameComponent` of TLV-TYPE @p type, copying the TLV-VALUE from a range. + * @tparam Iterator an @c InputIterator dereferencing to a one-octet value type. More efficient + * implementation is available when it is a @c RandomAccessIterator. + * @param type the TLV-TYPE. + * @param first beginning of the range. + * @param last past-end of the range. + * @return A reference to this Name, to allow chaining. */ template Name& @@ -359,12 +358,13 @@ class Name : private boost::totally_ordered return append(Component(type, first, last)); } - /** @brief Append a `GenericNameComponent`, copying the TLV-VALUE from a range. - * @tparam Iterator an @c InputIterator dereferencing to a one-octet value type. More efficient - * implementation is available when it is a @c RandomAccessIterator. - * @param first beginning of the range. - * @param last past-end of the range. - * @return A reference to this Name, to allow chaining. + /** + * @brief Append a `GenericNameComponent`, copying the TLV-VALUE from a range. + * @tparam Iterator an @c InputIterator dereferencing to a one-octet value type. More efficient + * implementation is available when it is a @c RandomAccessIterator. + * @param first beginning of the range. + * @param last past-end of the range. + * @return A reference to this Name, to allow chaining. */ template Name& @@ -373,10 +373,11 @@ class Name : private boost::totally_ordered return append(Component(tlv::GenericNameComponent, first, last)); } - /** @brief Append a `GenericNameComponent`, copying TLV-VALUE from a null-terminated string. - * @param str a null-terminated string. Bytes from the string are copied as is, and not - * interpreted as URI component. - * @return A reference to this Name, to allow chaining. + /** + * @brief Append a `GenericNameComponent`, copying the TLV-VALUE from a null-terminated string. + * @param str a null-terminated string. Bytes from the string are copied as is, and not + * interpreted as a URI component. + * @return A reference to this Name, to allow chaining. */ Name& append(const char* str) @@ -384,9 +385,10 @@ class Name : private boost::totally_ordered return append(Component(str)); } - /** @brief Append a PartialName. - * @param name the components to append - * @return A reference to this Name, to allow chaining. + /** + * @brief Append a PartialName. + * @param name the components to append + * @return A reference to this Name, to allow chaining. */ Name& append(const PartialName& name); @@ -402,15 +404,16 @@ class Name : private boost::totally_ordered return append(Component::fromNumber(number)); } - /** @brief Append a component with a marked number. - * @param marker 1-octet marker - * @param number the number + /** + * @brief Append a component with a marked number. + * @param marker 1-octet marker + * @param number the number * - * The component is encoded as a 1-octet marker, followed by a NonNegativeInteger. + * The component is encoded as a 1-octet marker, followed by a NonNegativeInteger. * - * @return A reference to this Name, to allow chaining. - * @sa NDN Naming Conventions revision 1 (obsolete) - * https://named-data.net/wp-content/uploads/2014/08/ndn-tr-22-ndn-memo-naming-conventions.pdf + * @return A reference to this Name, to allow chaining. + * @sa NDN Naming Conventions revision 1 (obsolete) + * https://named-data.net/wp-content/uploads/2014/08/ndn-tr-22-ndn-memo-naming-conventions.pdf */ Name& appendNumberWithMarker(uint8_t marker, uint64_t number) @@ -543,17 +546,6 @@ class Name : private boost::totally_ordered {reinterpret_cast(keyword.data()), keyword.size()})); } - /** - * @brief Append a name component. - * @note This makes push_back() an alias of append(), giving Name a similar API as `std::vector`. - */ - template - void - push_back(const T& component) - { - append(component); - } - /** * @brief Erase the component at the specified index. * @param i zero-based index of the component to erase; diff --git a/tests/unit/name.t.cpp b/tests/unit/name.t.cpp index b105818db..a7fdf7a76 100644 --- a/tests/unit/name.t.cpp +++ b/tests/unit/name.t.cpp @@ -459,7 +459,7 @@ BOOST_AUTO_TEST_CASE(IsPrefixOf) BOOST_AUTO_TEST_CASE(CompareOp) { - std::vector names = { + const std::vector names = { Name("/"), Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000000"), Name("/sha256digest=0000000000000000000000000000000000000000000000000000000000000001"), @@ -501,8 +501,10 @@ BOOST_AUTO_TEST_CASE(CompareOp) for (size_t i = 0; i < names.size(); ++i) { for (size_t j = 0; j < names.size(); ++j) { - Name lhs = names[i]; - Name rhs = names[j]; + const auto& lhs = names[i]; + const auto& rhs = names[j]; + BOOST_TEST_INFO_SCOPE("lhs = " << lhs); + BOOST_TEST_INFO_SCOPE("rhs = " << rhs); BOOST_CHECK_EQUAL(lhs == rhs, i == j); BOOST_CHECK_EQUAL(lhs != rhs, i != j); BOOST_CHECK_EQUAL(lhs < rhs, i < j); diff --git a/tests/unit/security/tpm/back-end.t.cpp b/tests/unit/security/tpm/back-end.t.cpp index d432d735c..cb0ec5d2a 100644 --- a/tests/unit/security/tpm/back-end.t.cpp +++ b/tests/unit/security/tpm/back-end.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2023 Regents of the University of California. + * Copyright (c) 2013-2024 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -343,7 +343,8 @@ BOOST_AUTO_TEST_CASE(RandomKeyId) for (int i = 0; i < 100; i++) { auto key = tpm.createKey(identity, RsaKeyParams()); Name keyName = key->getKeyName(); - BOOST_CHECK(keyNames.insert(keyName).second); + BOOST_TEST_INFO_SCOPE("KeyName = " << keyName); + BOOST_TEST(keyNames.insert(keyName).second); } } diff --git a/tests/unit/security/validator-config/checker.t.cpp b/tests/unit/security/validator-config/checker.t.cpp index 523f1a248..e340b265a 100644 --- a/tests/unit/security/validator-config/checker.t.cpp +++ b/tests/unit/security/validator-config/checker.t.cpp @@ -40,10 +40,10 @@ class CheckerFixture : public KeyChainFixture public: CheckerFixture() { - names.push_back("/foo/bar"); - names.push_back("/foo/bar/bar"); - names.push_back("/foo"); - names.push_back("/other/prefix"); + names.emplace_back("/foo/bar"); + names.emplace_back("/foo/bar/bar"); + names.emplace_back("/foo"); + names.emplace_back("/other/prefix"); } static Name @@ -60,22 +60,6 @@ class CheckerFixture : public KeyChainFixture return Name(name).append(suffix); } - template - static void - testChecker(C& checker, tlv::SignatureTypeValue sigType, const Name& pktName, const Name& klName, bool expectedOutcome) - { - BOOST_TEST_INFO_SCOPE("Packet = " << pktName); - BOOST_TEST_INFO_SCOPE("KeyLocator = " << klName); - - auto state = PktType::makeState(); - auto result = checker.check(PktType::getType(), sigType, pktName, klName, *state); - BOOST_CHECK_EQUAL(bool(result), expectedOutcome); - BOOST_CHECK(boost::logic::indeterminate(state->getOutcome())); - if (!result) { - BOOST_CHECK_NE(result.getErrorMessage(), ""); - } - } - public: std::vector names; }; @@ -308,6 +292,23 @@ using Tests = boost::mp11::mp_product< CheckerFixtures >; +template +static void +testChecker(C& checker, tlv::SignatureTypeValue sigType, const Name& pktName, const Name& klName, bool expectedOutcome) +{ + BOOST_TEST_INFO_SCOPE("Packet = " << pktName); + BOOST_TEST_INFO_SCOPE("SignatureType = " << sigType); + BOOST_TEST_INFO_SCOPE("KeyLocator = " << klName); + + auto state = PktType::makeState(); + auto result = checker.check(PktType::getType(), sigType, pktName, klName, *state); + BOOST_TEST(bool(result) == expectedOutcome); + BOOST_TEST(boost::logic::indeterminate(state->getOutcome())); + if (!result) { + BOOST_TEST(!result.getErrorMessage().empty()); + } +} + BOOST_FIXTURE_TEST_CASE_TEMPLATE(Checks, T, Tests, boost::mp11::mp_second) { using PktType = boost::mp11::mp_first; @@ -321,12 +322,12 @@ BOOST_FIXTURE_TEST_CASE_TEMPLATE(Checks, T, Tests, boost::mp11::mp_second) bool expectedOutcome = this->outcomes[i][j]; auto klName = this->makeKeyLocatorKeyName(this->names[j]); - this->template testChecker(this->checker, tlv::SignatureSha256WithRsa, pktName, klName, expectedOutcome); - this->template testChecker(this->checker, tlv::SignatureSha256WithEcdsa, pktName, klName, false); + testChecker(this->checker, tlv::SignatureSha256WithRsa, pktName, klName, expectedOutcome); + testChecker(this->checker, tlv::SignatureSha256WithEcdsa, pktName, klName, false); klName = this->makeKeyLocatorCertName(this->names[j]); - this->template testChecker(this->checker, tlv::SignatureSha256WithRsa, pktName, klName, expectedOutcome); - this->template testChecker(this->checker, tlv::SignatureSha256WithEcdsa, pktName, klName, false); + testChecker(this->checker, tlv::SignatureSha256WithRsa, pktName, klName, expectedOutcome); + testChecker(this->checker, tlv::SignatureSha256WithEcdsa, pktName, klName, false); } } } diff --git a/tests/unit/util/sha256.t.cpp b/tests/unit/util/sha256.t.cpp index 4a31ac745..55eaa10c1 100644 --- a/tests/unit/util/sha256.t.cpp +++ b/tests/unit/util/sha256.t.cpp @@ -1,6 +1,6 @@ /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ /* - * Copyright (c) 2013-2023 Regents of the University of California. + * Copyright (c) 2013-2024 Regents of the University of California. * * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). * @@ -25,6 +25,8 @@ #include "tests/boost-test.hpp" #include + +#include #include namespace ndn::tests { @@ -114,12 +116,12 @@ BOOST_AUTO_TEST_CASE(InsertionOperatorString) BOOST_AUTO_TEST_CASE(InsertionOperatorUnsignedInt) { - const uint64_t input[] = {1, 2, 3, 4}; + const std::array input{1, 2, 3, 4}; auto expected = fromHex("7236c00c170036c6de133a878210ddd58567aa1d0619a0f70f69e38ae6f916e9"); Sha256 statefulSha256; - for (size_t i = 0; i < sizeof(input) / sizeof(uint64_t); ++i) { - statefulSha256 << boost::endian::native_to_big(input[i]); + for (auto i : input) { + statefulSha256 << boost::endian::native_to_big(static_cast(i)); } ConstBufferPtr digest = statefulSha256.computeDigest();