From c2675c0863bb351c2d514efcb40b9d523b943073 Mon Sep 17 00:00:00 2001 From: John Turpish Date: Tue, 8 Oct 2024 13:33:26 -0400 Subject: [PATCH] cov --- cmake/CodeCoverage.cmake | 4 ++-- library/include/multibase/algorithm.h | 4 ++++ library/include/multibase/basic_algorithm.h | 4 ++++ library/src/ipfs_client/gw/dnslink_requestor.cc | 2 +- .../src/ipfs_client/ipld/dag_node_unittest.cc | 17 +++++++++++++++++ library/src/ipfs_client/ipld/directory_shard.cc | 4 ++-- library/src/ipfs_client/redirects.cc | 2 +- library/src/log_macros.h | 13 ------------- 8 files changed, 31 insertions(+), 19 deletions(-) diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake index 00867801..71d4010b 100644 --- a/cmake/CodeCoverage.cmake +++ b/cmake/CodeCoverage.cmake @@ -296,8 +296,8 @@ function(setup_target_for_coverage_lcov) ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS} - --rc genhtml_hi_limit=88 - --rc genhtml_med_limit=74 + --rc genhtml_hi_limit=89 + --rc genhtml_med_limit=78 --prefix "${BASEDIR}" -o ${Coverage_NAME} ${Coverage_NAME}.info diff --git a/library/include/multibase/algorithm.h b/library/include/multibase/algorithm.h index ac0fbaa9..2bf2675f 100644 --- a/library/include/multibase/algorithm.h +++ b/library/include/multibase/algorithm.h @@ -1,5 +1,7 @@ #pragma once +// LCOV_EXCL_START + #include namespace multibase { @@ -26,3 +28,5 @@ class algorithm { }; } // namespace multibase + +// LCOV_EXCL_STOP diff --git a/library/include/multibase/basic_algorithm.h b/library/include/multibase/basic_algorithm.h index 5da225c8..01381f02 100644 --- a/library/include/multibase/basic_algorithm.h +++ b/library/include/multibase/basic_algorithm.h @@ -4,6 +4,8 @@ */ #pragma once +// LCOV_EXCL_START + #include #include @@ -320,3 +322,5 @@ struct traits { using base_64 = basic_algorithm; } // namespace multibase + +// LCOV_EXCL_STOP diff --git a/library/src/ipfs_client/gw/dnslink_requestor.cc b/library/src/ipfs_client/gw/dnslink_requestor.cc index 69f29ca1..9b11391c 100644 --- a/library/src/ipfs_client/gw/dnslink_requestor.cc +++ b/library/src/ipfs_client/gw/dnslink_requestor.cc @@ -64,7 +64,7 @@ bool parse_results(ipfs::gw::RequestPtr req, constexpr auto prefix = "dnslink="sv; auto t = Source::Clock::now(); for (auto& result : results) { - if (starts_with(result, prefix)) { + if (result.starts_with(prefix)) { Source src; src.fetched_at = t; src.load_duration = t - start; diff --git a/library/src/ipfs_client/ipld/dag_node_unittest.cc b/library/src/ipfs_client/ipld/dag_node_unittest.cc index 2513f230..88ad109f 100644 --- a/library/src/ipfs_client/ipld/dag_node_unittest.cc +++ b/library/src/ipfs_client/ipld/dag_node_unittest.cc @@ -2,6 +2,7 @@ #include #include +#include using T = ii::DagNode; @@ -18,3 +19,19 @@ TEST_F(DagNodeTest,ConstructDagJson) { auto d = dynamic_cast(p.get()); ASSERT_TRUE(d); } +TEST_F(DagNodeTest,DnsLinkIs) { + ii::DnsLinkName d{"/ipfs/baguqeaaeejugsiq"}; + auto p = static_cast(&d); + ASSERT_TRUE(p); + auto down = p->as_dnslink(); + EXPECT_TRUE(down); + EXPECT_TRUE(down == &d); +} +TEST_F(DagNodeTest,DagJsonIsNotOtherTHings) { + i::Cid cid{"baguqeaaeejugsiq"}; + auto p = T::fromBytes(api, cid, "\"hi\""); + ASSERT_TRUE(p); + EXPECT_FALSE(p->as_dnslink()); + EXPECT_FALSE(p->as_hamt()); + EXPECT_FALSE(p->as_ipns()); +} diff --git a/library/src/ipfs_client/ipld/directory_shard.cc b/library/src/ipfs_client/ipld/directory_shard.cc index c1f25267..70deefc7 100644 --- a/library/src/ipfs_client/ipld/directory_shard.cc +++ b/library/src/ipfs_client/ipld/directory_shard.cc @@ -46,10 +46,10 @@ auto Self::resolve_internal(ipfs::ipld::DirShard::HashIter hash_b, auto hash_chunk = hash_b == hash_e ? std::string{} : *hash_b; auto needed_size = hash_chunk.size() + human_name.size(); for (auto& [name, link] : links_) { - if (!starts_with(name, hash_chunk)) { + if (!name.starts_with(hash_chunk)) { continue; } - if (name.size() == needed_size && ends_with(name, human_name)) { + if (name.size() == needed_size && name.ends_with(human_name)) { return CallChild(parms, name); } auto node = parms.GetBlock(link.cid); diff --git a/library/src/ipfs_client/redirects.cc b/library/src/ipfs_client/redirects.cc index 813b5ef1..287d84e1 100644 --- a/library/src/ipfs_client/redirects.cc +++ b/library/src/ipfs_client/redirects.cc @@ -82,7 +82,7 @@ std::uint16_t r::Directive::rewrite(std::string& path) const { } } std::string r::Directive::error() const { - if (starts_with(to_, "ERROR: ")) { + if (to_.starts_with("ERROR: ")) { return to_; } if (status_ < 200 || status_ > 451) { diff --git a/library/src/log_macros.h b/library/src/log_macros.h index 312eb4ad..361107ab 100644 --- a/library/src/log_macros.h +++ b/library/src/log_macros.h @@ -37,17 +37,4 @@ static bool const is_logging_initialized = ::ipfs::log::IsInitialized(); #define L_VAR(X) LOG(INFO) << "VAR " << #X << "='" << (X) << '\''; -inline auto starts_with(std::string_view full_text, std::string_view prefix) -> bool { - if (prefix.size() > full_text.size()) { - return false; - } - return full_text.substr(0UL, prefix.size()) == prefix; -} -inline auto ends_with(std::string_view full_text, std::string_view suffix) -> bool { - if (suffix.size() > full_text.size()) { - return false; - } - return full_text.substr(full_text.size() - suffix.size()) == suffix; -} - #endif // IPFS_LOG_MACROS_H_