aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-11-13 12:08:26 +0000
committerfanquake <fanquake@gmail.com>2023-11-13 12:32:55 +0000
commit29c2c903621f7daae26113dd2902c016b56929d4 (patch)
tree8bfcf09ae9ba176c5b7f159e850986cef0393eaf /src/test
parente862bceb1705e6d8c1b738301ed10ae1b4413bfd (diff)
parent3b70f7b6156cb110c47a6e482791cf337bb6ad6d (diff)
downloadbitcoin-29c2c903621f7daae26113dd2902c016b56929d4.tar.xz
Merge bitcoin/bitcoin#28721: multiprocess compatibility updates
3b70f7b6156cb110c47a6e482791cf337bb6ad6d doc: fix broken doc/design/multiprocess.md links after #24352 (Ryan Ofsky) 6d43aad742c7ea28303cf2799528188938e7ce32 span: Make Span template deduction guides work in SFINAE context (Ryan Ofsky) 8062c3bdb9dd3062597ed8299e99151b612d32b7 util: Add ArgsManager SetConfigFilePath method (Ryan Ofsky) 441d00c60f0a67889d23f8556190ff99dde488bc interfaces: Rename CalculateBumpFees methods to be compatible with capn'proto (Ryan Ofsky) 156f49d682ef025fb942c997a6c5475e18eef9cf interfaces: Change getUnspentOutput return type to avoid multiprocess segfault (Ryan Ofsky) 4978754c0058bbdfbcd492f25fa49ef211e11d6e interfaces: Add schedulerMockForward method so mockscheduler RPC can work across processes (Ryan Ofsky) 924327eaf3ada45a603e80aa4a3ab38a0f8c8673 interfaces: Fix const virtual method that breaks multiprocess support (Ryan Ofsky) 82a379eca8251c736b4de6e7a2516582641ce397 streams: Add SpanReader ignore method (Russell Yanofsky) Pull request description: This is a collection of small changes to interfaces and code which were needed as part of multiprocess PR #10102, but have been moved here to make that PR smaller. All of these changes are refactoring changes which do not affect behavior of current code --- This PR is part of the [process separation project](https://github.com/bitcoin/bitcoin/issues/28722). ACKs for top commit: achow101: ACK 3b70f7b6156cb110c47a6e482791cf337bb6ad6d naumenkogs: ACK 3b70f7b6156cb110c47a6e482791cf337bb6ad6d maflcko: re-ACK 3b70f7b6156cb110c47a6e482791cf337bb6ad6d 🎆 Tree-SHA512: 2368772b887056ad8a9f84c299cfde76ba45943770e3b5353130580900afa9611302195b899ced7b6e303b11f053ff204cae7c28ff4e12c55562fcc81119ba4c
Diffstat (limited to 'src/test')
-rw-r--r--src/test/span_tests.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/test/span_tests.cpp b/src/test/span_tests.cpp
new file mode 100644
index 0000000000..f6cac10b09
--- /dev/null
+++ b/src/test/span_tests.cpp
@@ -0,0 +1,73 @@
+// Copyright (c) 2023 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <span.h>
+
+#include <boost/test/unit_test.hpp>
+#include <array>
+#include <set>
+#include <vector>
+
+namespace {
+struct Ignore
+{
+ template<typename T> Ignore(T&&) {}
+};
+template<typename T>
+bool Spannable(T&& value, decltype(Span{value})* enable = nullptr)
+{
+ return true;
+}
+bool Spannable(Ignore)
+{
+ return false;
+}
+
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wunneeded-member-function"
+# pragma clang diagnostic ignored "-Wunused-member-function"
+#endif
+struct SpannableYes
+{
+ int* data();
+ size_t size();
+};
+struct SpannableNo
+{
+ void* data();
+ size_t size();
+};
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#endif
+} // namespace
+
+BOOST_AUTO_TEST_SUITE(span_tests)
+
+// Make sure template Span template deduction guides accurately enable calls to
+// Span constructor overloads that work, and disable calls to constructor overloads that
+// don't work. This makes it is possible to use the Span constructor in a SFINAE
+// contexts like in the Spannable function above to detect whether types are or
+// aren't compatible with Spans at compile time.
+//
+// Previously there was a bug where writing a SFINAE check for vector<bool> was
+// not possible, because in libstdc++ vector<bool> has a data() memeber
+// returning void*, and the Span template guide ignored the data() return value,
+// so the template substitution would succeed, but the constructor would fail,
+// resulting in a fatal compile error, rather than a SFINAE error that could be
+// handled.
+BOOST_AUTO_TEST_CASE(span_constructor_sfinae)
+{
+ BOOST_CHECK(Spannable(std::vector<int>{}));
+ BOOST_CHECK(!Spannable(std::set<int>{}));
+ BOOST_CHECK(!Spannable(std::vector<bool>{}));
+ BOOST_CHECK(Spannable(std::array<int, 3>{}));
+ BOOST_CHECK(Spannable(Span<int>{}));
+ BOOST_CHECK(Spannable("char array"));
+ BOOST_CHECK(Spannable(SpannableYes{}));
+ BOOST_CHECK(!Spannable(SpannableNo{}));
+}
+
+BOOST_AUTO_TEST_SUITE_END()