Implement a simplified variant of std::unique_ptr<T>

This simplified variant supports only a subset of the functionality
in `std::unique_ptr<T>`. `Catch::Detail::unique_ptr<T>` only supports
single element pointer (no array support) with default deleter.

By removing the support for custom deleters, we also avoid requiring
significant machinery to support EBO, speeding up instantiations of
`unique_ptr<T>` significantly. Catch2 also currently does not need
to support `unique_ptr<T[]>`, so that is not supported either.
This commit is contained in:
Martin Hořeňovský 2020-05-24 23:41:02 +02:00
parent 66ab942903
commit 41bbaa6d57
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
14 changed files with 890 additions and 8 deletions

View File

@ -125,6 +125,7 @@ set(INTERNAL_HEADERS
${SOURCES_DIR}/catch_totals.hpp ${SOURCES_DIR}/catch_totals.hpp
${SOURCES_DIR}/catch_translate_exception.hpp ${SOURCES_DIR}/catch_translate_exception.hpp
${SOURCES_DIR}/internal/catch_uncaught_exceptions.hpp ${SOURCES_DIR}/internal/catch_uncaught_exceptions.hpp
${SOURCES_DIR}/internal/catch_unique_ptr.hpp
${SOURCES_DIR}/catch_version.hpp ${SOURCES_DIR}/catch_version.hpp
${SOURCES_DIR}/catch_version_macros.hpp ${SOURCES_DIR}/catch_version_macros.hpp
${SOURCES_DIR}/internal/catch_wildcard_pattern.hpp ${SOURCES_DIR}/internal/catch_wildcard_pattern.hpp

View File

@ -85,6 +85,7 @@
#include <catch2/internal/catch_text.hpp> #include <catch2/internal/catch_text.hpp>
#include <catch2/internal/catch_to_string.hpp> #include <catch2/internal/catch_to_string.hpp>
#include <catch2/internal/catch_uncaught_exceptions.hpp> #include <catch2/internal/catch_uncaught_exceptions.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_wildcard_pattern.hpp> #include <catch2/internal/catch_wildcard_pattern.hpp>
#include <catch2/internal/catch_windows_h_proxy.hpp> #include <catch2/internal/catch_windows_h_proxy.hpp>
#include <catch2/internal/catch_xmlwriter.hpp> #include <catch2/internal/catch_xmlwriter.hpp>

View File

@ -0,0 +1,110 @@
#ifndef CATCH_UNIQUE_PTR_HPP_INCLUDED
#define CATCH_UNIQUE_PTR_HPP_INCLUDED
#include <cassert>
#include <type_traits>
namespace Catch {
namespace Detail {
// reimplementation of unique_ptr for improved compilation times
// Does not support custom deleters (and thus does not require EBO)
// Does not support arrays
template <typename T>
class unique_ptr {
T* m_ptr;
public:
constexpr unique_ptr(std::nullptr_t = nullptr):
m_ptr{}
{}
explicit constexpr unique_ptr(T* ptr):
m_ptr(ptr)
{}
template <typename U, typename = std::enable_if_t<std::is_base_of<T, U>::value>>
unique_ptr(unique_ptr<U>&& from):
m_ptr(from.release())
{}
template <typename U, typename = std::enable_if_t<std::is_base_of<T, U>::value>>
unique_ptr& operator=(unique_ptr<U>&& from) {
reset(from.release());
return *this;
}
unique_ptr(unique_ptr const&) = delete;
unique_ptr& operator=(unique_ptr const&) = delete;
unique_ptr(unique_ptr&& rhs) noexcept:
m_ptr(rhs.m_ptr) {
rhs.m_ptr = nullptr;
}
unique_ptr& operator=(unique_ptr&& rhs) noexcept {
reset(rhs.release());
return *this;
}
~unique_ptr() {
delete m_ptr;
}
T& operator*() {
assert(m_ptr);
return *m_ptr;
}
T const& operator*() const {
assert(m_ptr);
return *m_ptr;
}
T* operator->() const noexcept {
assert(m_ptr);
return m_ptr;
}
T* get() { return m_ptr; }
T const* get() const { return m_ptr; }
void reset(T* ptr = nullptr) {
delete m_ptr;
m_ptr = ptr;
}
T* release() {
auto temp = m_ptr;
m_ptr = nullptr;
return temp;
}
explicit operator bool() const {
return m_ptr;
}
friend void swap(unique_ptr& lhs, unique_ptr& rhs) {
auto temp = lhs.m_ptr;
lhs.m_ptr = rhs.m_ptr;
rhs.m_ptr = temp;
}
};
// Purposefully doesn't exist
// We could also rely on compiler warning + werror for calling plain delete
// on a T[], but this seems better.
// Maybe add definition and a static assert?
template <typename T>
class unique_ptr<T[]>;
template <typename T, typename... Args>
unique_ptr<T> make_unique(Args&&... args) {
// static_cast<Args&&> does the same thing as std::forward in
// this case, but does not require including big header (<utility>)
// and compiles faster thanks to not requiring template instantiation
// and overload resolution
return unique_ptr<T>(new T(static_cast<Args&&>(args)...));
}
} // end namespace Detail
} // end namespace Catch
#endif // CATCH_UNIQUE_PTR_HPP_INCLUDED

View File

@ -27,6 +27,7 @@ set(TEST_SOURCES
${SELF_TEST_DIR}/IntrospectiveTests/StringManip.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/StringManip.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/ToString.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/ToString.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/UniquePtr.tests.cpp
${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp ${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp
${SELF_TEST_DIR}/UsageTests/BDD.tests.cpp ${SELF_TEST_DIR}/UsageTests/BDD.tests.cpp
${SELF_TEST_DIR}/UsageTests/Benchmark.tests.cpp ${SELF_TEST_DIR}/UsageTests/Benchmark.tests.cpp

View File

@ -222,6 +222,7 @@ Message from section two
:test-result: PASS Tracker :test-result: PASS Tracker
:test-result: PASS Trim strings :test-result: PASS Trim strings
:test-result: FAIL Unexpected exceptions can be translated :test-result: FAIL Unexpected exceptions can be translated
:test-result: PASS Upcasting special member functions
:test-result: PASS Usage of the SizeIs range matcher :test-result: PASS Usage of the SizeIs range matcher
:test-result: PASS Use a custom approx :test-result: PASS Use a custom approx
:test-result: PASS Variadic macros :test-result: PASS Variadic macros
@ -268,6 +269,7 @@ loose text artifact
:test-result: PASS long long :test-result: PASS long long
:test-result: FAIL looped SECTION tests :test-result: FAIL looped SECTION tests
:test-result: FAIL looped tests :test-result: FAIL looped tests
:test-result: PASS make_unique reimplementation
:test-result: PASS mean :test-result: PASS mean
:test-result: PASS measure :test-result: PASS measure
:test-result: FAIL mix info, unscoped info and warning :test-result: FAIL mix info, unscoped info and warning
@ -331,6 +333,7 @@ loose text artifact
:test-result: PASS tuple<string,string> :test-result: PASS tuple<string,string>
:test-result: PASS tuple<tuple<int>,tuple<>,float> :test-result: PASS tuple<tuple<int>,tuple<>,float>
:test-result: PASS uniform samples :test-result: PASS uniform samples
:test-result: PASS unique_ptr reimplementation: basic functionality
:test-result: PASS vec<vec<string,alloc>> -> toString :test-result: PASS vec<vec<string,alloc>> -> toString
:test-result: PASS vector<bool> -> toString :test-result: PASS vector<bool> -> toString
:test-result: PASS vector<int,allocator> -> toString :test-result: PASS vector<int,allocator> -> toString

View File

@ -1587,6 +1587,8 @@ StringManip.tests.cpp:<line number>: passed: trim(StringRef(whitespace_at_both_e
== ==
There is no extra whitespace here There is no extra whitespace here
Exception.tests.cpp:<line number>: failed: unexpected exception with message: '3.14' Exception.tests.cpp:<line number>: failed: unexpected exception with message: '3.14'
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
MatchersRanges.tests.cpp:<line number>: passed: empty_vec, SizeIs(0) for: { } has size == 0 MatchersRanges.tests.cpp:<line number>: passed: empty_vec, SizeIs(0) for: { } has size == 0
MatchersRanges.tests.cpp:<line number>: passed: empty_vec, !SizeIs(2) for: { } not has size == 2 MatchersRanges.tests.cpp:<line number>: passed: empty_vec, !SizeIs(2) for: { } not has size == 2
MatchersRanges.tests.cpp:<line number>: passed: empty_vec, SizeIs(Lt(2)) for: { } size matches is less than 2 MatchersRanges.tests.cpp:<line number>: passed: empty_vec, SizeIs(Lt(2)) for: { } size matches is less than 2
@ -1794,6 +1796,9 @@ Misc.tests.cpp:<line number>: failed: ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 mes
Misc.tests.cpp:<line number>: passed: ( fib[i] % 2 ) == 0 for: 0 == 0 with 1 message: 'Testing if fib[5] (8) is even' Misc.tests.cpp:<line number>: passed: ( fib[i] % 2 ) == 0 for: 0 == 0 with 1 message: 'Testing if fib[5] (8) is even'
Misc.tests.cpp:<line number>: failed: ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[6] (13) is even' Misc.tests.cpp:<line number>: failed: ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[6] (13) is even'
Misc.tests.cpp:<line number>: failed: ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[7] (21) is even' Misc.tests.cpp:<line number>: failed: ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[7] (21) is even'
UniquePtr.tests.cpp:<line number>: passed: !(lval.has_moved) for: !false
UniquePtr.tests.cpp:<line number>: passed: rval.has_moved for: true
UniquePtr.tests.cpp:<line number>: passed: *ptr == std::tuple<int, double, int>{1, 2., 3} for: {?} == {?}
InternalBenchmark.tests.cpp:<line number>: passed: m == 19. for: 19.0 == 19.0 InternalBenchmark.tests.cpp:<line number>: passed: m == 19. for: 19.0 == 19.0
InternalBenchmark.tests.cpp:<line number>: passed: x == 17 for: 17 == 17 InternalBenchmark.tests.cpp:<line number>: passed: x == 17 for: 17 == 17
InternalBenchmark.tests.cpp:<line number>: passed: x == 23 for: 23 == 23 InternalBenchmark.tests.cpp:<line number>: passed: x == 23 for: 23 == 23
@ -1990,6 +1995,29 @@ InternalBenchmark.tests.cpp:<line number>: passed: e.point == 23 for: 23.0 == 23
InternalBenchmark.tests.cpp:<line number>: passed: e.upper_bound == 23 for: 23.0 == 23 InternalBenchmark.tests.cpp:<line number>: passed: e.upper_bound == 23 for: 23.0 == 23
InternalBenchmark.tests.cpp:<line number>: passed: e.lower_bound == 23 for: 23.0 == 23 InternalBenchmark.tests.cpp:<line number>: passed: e.lower_bound == 23 for: 23.0 == 23
InternalBenchmark.tests.cpp:<line number>: passed: e.confidence_interval == 0.95 for: 0.95 == 0.95 InternalBenchmark.tests.cpp:<line number>: passed: e.confidence_interval == 0.95 for: 0.95 == 0.95
UniquePtr.tests.cpp:<line number>: passed: !(ptr) for: !{?}
UniquePtr.tests.cpp:<line number>: passed: ptr.get() == 0 for: 0 == 0
UniquePtr.tests.cpp:<line number>: passed: ptr for: {?}
UniquePtr.tests.cpp:<line number>: passed: *ptr == 0 for: 0 == 0
UniquePtr.tests.cpp:<line number>: passed: ptr.get() == naked_ptr for: 0x<hex digits> == 0x<hex digits>
UniquePtr.tests.cpp:<line number>: passed: !(ptr) for: !{?}
UniquePtr.tests.cpp:<line number>: passed: ptr.get() == 0 for: 0 == 0
UniquePtr.tests.cpp:<line number>: passed: ptr for: {?}
UniquePtr.tests.cpp:<line number>: passed: *ptr == 0 for: 0 == 0
UniquePtr.tests.cpp:<line number>: passed: ptr.get() == naked_ptr for: 0x<hex digits> == 0x<hex digits>
UniquePtr.tests.cpp:<line number>: passed: ptr for: {?}
UniquePtr.tests.cpp:<line number>: passed: ptr.get() != 0 for: 0x<hex digits> != 0
UniquePtr.tests.cpp:<line number>: passed: *ptr == 2 for: 2 == 2
UniquePtr.tests.cpp:<line number>: passed: !(ptr) for: !{?}
UniquePtr.tests.cpp:<line number>: passed: ptr.get() == 0 for: 0 == 0
UniquePtr.tests.cpp:<line number>: passed: !(ptr1) for: !{?}
UniquePtr.tests.cpp:<line number>: passed: ptr2 for: {?}
UniquePtr.tests.cpp:<line number>: passed: *ptr2 == 1 for: 1 == 1
UniquePtr.tests.cpp:<line number>: passed: !(ptr2) for: !{?}
UniquePtr.tests.cpp:<line number>: passed: ptr1 for: {?}
UniquePtr.tests.cpp:<line number>: passed: *ptr1 == 2 for: 2 == 2
UniquePtr.tests.cpp:<line number>: passed: *ptr1 == 2 for: 2 == 2
UniquePtr.tests.cpp:<line number>: passed: *ptr2 == 1 for: 1 == 1
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(v) == "{ }" for: "{ }" == "{ }" ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(v) == "{ }" for: "{ }" == "{ }"
ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(v) == "{ { \"hello\" }, { \"world\" } }" for: "{ { "hello" }, { "world" } }" ToStringVector.tests.cpp:<line number>: passed: ::Catch::Detail::stringify(v) == "{ { \"hello\" }, { \"world\" } }" for: "{ { "hello" }, { "world" } }"
== ==

View File

@ -1380,6 +1380,6 @@ due to unexpected exception with message:
Why would you throw a std::string? Why would you throw a std::string?
=============================================================================== ===============================================================================
test cases: 334 | 260 passed | 70 failed | 4 failed as expected test cases: 337 | 263 passed | 70 failed | 4 failed as expected
assertions: 1896 | 1744 passed | 131 failed | 21 failed as expected assertions: 1924 | 1772 passed | 131 failed | 21 failed as expected

View File

@ -11547,6 +11547,30 @@ Exception.tests.cpp:<line number>: FAILED:
due to unexpected exception with message: due to unexpected exception with message:
3.14 3.14
-------------------------------------------------------------------------------
Upcasting special member functions
Move constructor
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( bptr->i == 3 )
with expansion:
3 == 3
-------------------------------------------------------------------------------
Upcasting special member functions
move assignment
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( bptr->i == 3 )
with expansion:
3 == 3
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Usage of the SizeIs range matcher Usage of the SizeIs range matcher
Some with stdlib containers Some with stdlib containers
@ -13096,6 +13120,42 @@ with expansion:
with message: with message:
Testing if fib[7] (21) is even Testing if fib[7] (21) is even
-------------------------------------------------------------------------------
make_unique reimplementation
From lvalue copies
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( lval.has_moved )
with expansion:
!false
-------------------------------------------------------------------------------
make_unique reimplementation
From rvalue moves
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( rval.has_moved )
with expansion:
true
-------------------------------------------------------------------------------
make_unique reimplementation
Variadic constructor
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( *ptr == std::tuple<int, double, int>{1, 2., 3} )
with expansion:
{?} == {?}
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
mean mean
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -14485,6 +14545,186 @@ InternalBenchmark.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
0.95 == 0.95 0.95 == 0.95
-------------------------------------------------------------------------------
unique_ptr reimplementation: basic functionality
Default constructed unique_ptr is empty
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( ptr )
with expansion:
!{?}
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( ptr.get() == 0 )
with expansion:
0 == 0
-------------------------------------------------------------------------------
unique_ptr reimplementation: basic functionality
Take ownership of allocation
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( ptr )
with expansion:
{?}
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( *ptr == 0 )
with expansion:
0 == 0
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( ptr.get() == naked_ptr )
with expansion:
0x<hex digits> == 0x<hex digits>
-------------------------------------------------------------------------------
unique_ptr reimplementation: basic functionality
Take ownership of allocation
Plain reset deallocates
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( ptr )
with expansion:
!{?}
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( ptr.get() == 0 )
with expansion:
0 == 0
-------------------------------------------------------------------------------
unique_ptr reimplementation: basic functionality
Take ownership of allocation
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( ptr )
with expansion:
{?}
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( *ptr == 0 )
with expansion:
0 == 0
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( ptr.get() == naked_ptr )
with expansion:
0x<hex digits> == 0x<hex digits>
-------------------------------------------------------------------------------
unique_ptr reimplementation: basic functionality
Take ownership of allocation
Reset replaces ownership
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( ptr )
with expansion:
{?}
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( ptr.get() != 0 )
with expansion:
0x<hex digits> != 0
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( *ptr == 2 )
with expansion:
2 == 2
-------------------------------------------------------------------------------
unique_ptr reimplementation: basic functionality
Release releases ownership
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
CHECK_FALSE( ptr )
with expansion:
!{?}
UniquePtr.tests.cpp:<line number>: PASSED:
CHECK( ptr.get() == 0 )
with expansion:
0 == 0
-------------------------------------------------------------------------------
unique_ptr reimplementation: basic functionality
Move constructor
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( ptr1 )
with expansion:
!{?}
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( ptr2 )
with expansion:
{?}
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( *ptr2 == 1 )
with expansion:
1 == 1
-------------------------------------------------------------------------------
unique_ptr reimplementation: basic functionality
Move assignment
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( ptr2 )
with expansion:
!{?}
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( ptr1 )
with expansion:
{?}
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( *ptr1 == 2 )
with expansion:
2 == 2
-------------------------------------------------------------------------------
unique_ptr reimplementation: basic functionality
free swap
-------------------------------------------------------------------------------
UniquePtr.tests.cpp:<line number>
...............................................................................
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( *ptr1 == 2 )
with expansion:
2 == 2
UniquePtr.tests.cpp:<line number>: PASSED:
REQUIRE( *ptr2 == 1 )
with expansion:
1 == 1
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
vec<vec<string,alloc>> -> toString vec<vec<string,alloc>> -> toString
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -14792,6 +15032,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED: Misc.tests.cpp:<line number>: PASSED:
=============================================================================== ===============================================================================
test cases: 334 | 244 passed | 86 failed | 4 failed as expected test cases: 337 | 247 passed | 86 failed | 4 failed as expected
assertions: 1913 | 1744 passed | 148 failed | 21 failed as expected assertions: 1941 | 1772 passed | 148 failed | 21 failed as expected

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact <testsuitesloose text artifact
> >
<testsuite name="<exe-name>" errors="17" failures="132" tests="1914" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="17" failures="132" tests="1942" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties> <properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
<property name="random-seed" value="1"/> <property name="random-seed" value="1"/>
@ -1256,6 +1256,8 @@ FAILED:
Exception.tests.cpp:<line number> Exception.tests.cpp:<line number>
</error> </error>
</testcase> </testcase>
<testcase classname="<exe-name>.global" name="Upcasting special member functions/Move constructor" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Upcasting special member functions/move assignment" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Some with stdlib containers" time="{duration}"/> <testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Some with stdlib containers" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Type requires ADL found size free function" time="{duration}"/> <testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Type requires ADL found size free function" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Type has size member" time="{duration}"/> <testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Type has size member" time="{duration}"/>
@ -1577,6 +1579,9 @@ Testing if fib[7] (21) is even
Misc.tests.cpp:<line number> Misc.tests.cpp:<line number>
</failure> </failure>
</testcase> </testcase>
<testcase classname="<exe-name>.global" name="make_unique reimplementation/From lvalue copies" time="{duration}"/>
<testcase classname="<exe-name>.global" name="make_unique reimplementation/From rvalue moves" time="{duration}"/>
<testcase classname="<exe-name>.global" name="make_unique reimplementation/Variadic constructor" time="{duration}"/>
<testcase classname="<exe-name>.global" name="mean" time="{duration}"/> <testcase classname="<exe-name>.global" name="mean" time="{duration}"/>
<testcase classname="<exe-name>.global" name="measure" time="{duration}"/> <testcase classname="<exe-name>.global" name="measure" time="{duration}"/>
<testcase classname="<exe-name>.global" name="mix info, unscoped info and warning" time="{duration}"/> <testcase classname="<exe-name>.global" name="mix info, unscoped info and warning" time="{duration}"/>
@ -1733,6 +1738,14 @@ Exception.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="tuple&lt;string,string>" time="{duration}"/> <testcase classname="<exe-name>.global" name="tuple&lt;string,string>" time="{duration}"/>
<testcase classname="<exe-name>.global" name="tuple&lt;tuple&lt;int>,tuple&lt;>,float>" time="{duration}"/> <testcase classname="<exe-name>.global" name="tuple&lt;tuple&lt;int>,tuple&lt;>,float>" time="{duration}"/>
<testcase classname="<exe-name>.global" name="uniform samples" time="{duration}"/> <testcase classname="<exe-name>.global" name="uniform samples" time="{duration}"/>
<testcase classname="<exe-name>.global" name="unique_ptr reimplementation: basic functionality/Default constructed unique_ptr is empty" time="{duration}"/>
<testcase classname="<exe-name>.global" name="unique_ptr reimplementation: basic functionality/Take ownership of allocation" time="{duration}"/>
<testcase classname="<exe-name>.global" name="unique_ptr reimplementation: basic functionality/Take ownership of allocation/Plain reset deallocates" time="{duration}"/>
<testcase classname="<exe-name>.global" name="unique_ptr reimplementation: basic functionality/Take ownership of allocation/Reset replaces ownership" time="{duration}"/>
<testcase classname="<exe-name>.global" name="unique_ptr reimplementation: basic functionality/Release releases ownership" time="{duration}"/>
<testcase classname="<exe-name>.global" name="unique_ptr reimplementation: basic functionality/Move constructor" time="{duration}"/>
<testcase classname="<exe-name>.global" name="unique_ptr reimplementation: basic functionality/Move assignment" time="{duration}"/>
<testcase classname="<exe-name>.global" name="unique_ptr reimplementation: basic functionality/free swap" time="{duration}"/>
<testcase classname="<exe-name>.global" name="vec&lt;vec&lt;string,alloc>> -> toString" time="{duration}"/> <testcase classname="<exe-name>.global" name="vec&lt;vec&lt;string,alloc>> -> toString" time="{duration}"/>
<testcase classname="<exe-name>.global" name="vector&lt;bool> -> toString" time="{duration}"/> <testcase classname="<exe-name>.global" name="vector&lt;bool> -> toString" time="{duration}"/>
<testcase classname="<exe-name>.global" name="vector&lt;int,allocator> -> toString" time="{duration}"/> <testcase classname="<exe-name>.global" name="vector&lt;int,allocator> -> toString" time="{duration}"/>

View File

@ -180,6 +180,21 @@
<testCase name="parseEnums/One enum value" duration="{duration}"/> <testCase name="parseEnums/One enum value" duration="{duration}"/>
<testCase name="parseEnums/Multiple enum values" duration="{duration}"/> <testCase name="parseEnums/Multiple enum values" duration="{duration}"/>
</file> </file>
<file path="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp">
<testCase name="Upcasting special member functions/Move constructor" duration="{duration}"/>
<testCase name="Upcasting special member functions/move assignment" duration="{duration}"/>
<testCase name="make_unique reimplementation/From lvalue copies" duration="{duration}"/>
<testCase name="make_unique reimplementation/From rvalue moves" duration="{duration}"/>
<testCase name="make_unique reimplementation/Variadic constructor" duration="{duration}"/>
<testCase name="unique_ptr reimplementation: basic functionality/Default constructed unique_ptr is empty" duration="{duration}"/>
<testCase name="unique_ptr reimplementation: basic functionality/Take ownership of allocation" duration="{duration}"/>
<testCase name="unique_ptr reimplementation: basic functionality/Take ownership of allocation/Plain reset deallocates" duration="{duration}"/>
<testCase name="unique_ptr reimplementation: basic functionality/Take ownership of allocation/Reset replaces ownership" duration="{duration}"/>
<testCase name="unique_ptr reimplementation: basic functionality/Release releases ownership" duration="{duration}"/>
<testCase name="unique_ptr reimplementation: basic functionality/Move constructor" duration="{duration}"/>
<testCase name="unique_ptr reimplementation: basic functionality/Move assignment" duration="{duration}"/>
<testCase name="unique_ptr reimplementation: basic functionality/free swap" duration="{duration}"/>
</file>
<file path="tests/<exe-name>/IntrospectiveTests/Xml.tests.cpp"> <file path="tests/<exe-name>/IntrospectiveTests/Xml.tests.cpp">
<testCase name="XmlEncode/normal string" duration="{duration}"/> <testCase name="XmlEncode/normal string" duration="{duration}"/>
<testCase name="XmlEncode/empty string" duration="{duration}"/> <testCase name="XmlEncode/empty string" duration="{duration}"/>

View File

@ -3021,6 +3021,10 @@ ok {test-number} - trim(StringRef(trailing_whitespace)) == StringRef(no_whitespa
ok {test-number} - trim(StringRef(whitespace_at_both_ends)) == StringRef(no_whitespace) for: There is no extra whitespace here == There is no extra whitespace here ok {test-number} - trim(StringRef(whitespace_at_both_ends)) == StringRef(no_whitespace) for: There is no extra whitespace here == There is no extra whitespace here
# Unexpected exceptions can be translated # Unexpected exceptions can be translated
not ok {test-number} - unexpected exception with message: '3.14' not ok {test-number} - unexpected exception with message: '3.14'
# Upcasting special member functions
ok {test-number} - bptr->i == 3 for: 3 == 3
# Upcasting special member functions
ok {test-number} - bptr->i == 3 for: 3 == 3
# Usage of the SizeIs range matcher # Usage of the SizeIs range matcher
ok {test-number} - empty_vec, SizeIs(0) for: { } has size == 0 ok {test-number} - empty_vec, SizeIs(0) for: { } has size == 0
# Usage of the SizeIs range matcher # Usage of the SizeIs range matcher
@ -3418,6 +3422,12 @@ ok {test-number} - ( fib[i] % 2 ) == 0 for: 0 == 0 with 1 message: 'Testing if f
not ok {test-number} - ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[6] (13) is even' not ok {test-number} - ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[6] (13) is even'
# looped tests # looped tests
not ok {test-number} - ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[7] (21) is even' not ok {test-number} - ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[7] (21) is even'
# make_unique reimplementation
ok {test-number} - !(lval.has_moved) for: !false
# make_unique reimplementation
ok {test-number} - rval.has_moved for: true
# make_unique reimplementation
ok {test-number} - *ptr == std::tuple<int, double, int>{1, 2., 3} for: {?} == {?}
# mean # mean
ok {test-number} - m == 19. for: 19.0 == 19.0 ok {test-number} - m == 19. for: 19.0 == 19.0
# measure # measure
@ -3742,6 +3752,52 @@ ok {test-number} - e.upper_bound == 23 for: 23.0 == 23
ok {test-number} - e.lower_bound == 23 for: 23.0 == 23 ok {test-number} - e.lower_bound == 23 for: 23.0 == 23
# uniform samples # uniform samples
ok {test-number} - e.confidence_interval == 0.95 for: 0.95 == 0.95 ok {test-number} - e.confidence_interval == 0.95 for: 0.95 == 0.95
# unique_ptr reimplementation: basic functionality
ok {test-number} - !(ptr) for: !{?}
# unique_ptr reimplementation: basic functionality
ok {test-number} - ptr.get() == 0 for: 0 == 0
# unique_ptr reimplementation: basic functionality
ok {test-number} - ptr for: {?}
# unique_ptr reimplementation: basic functionality
ok {test-number} - *ptr == 0 for: 0 == 0
# unique_ptr reimplementation: basic functionality
ok {test-number} - ptr.get() == naked_ptr for: 0x<hex digits> == 0x<hex digits>
# unique_ptr reimplementation: basic functionality
ok {test-number} - !(ptr) for: !{?}
# unique_ptr reimplementation: basic functionality
ok {test-number} - ptr.get() == 0 for: 0 == 0
# unique_ptr reimplementation: basic functionality
ok {test-number} - ptr for: {?}
# unique_ptr reimplementation: basic functionality
ok {test-number} - *ptr == 0 for: 0 == 0
# unique_ptr reimplementation: basic functionality
ok {test-number} - ptr.get() == naked_ptr for: 0x<hex digits> == 0x<hex digits>
# unique_ptr reimplementation: basic functionality
ok {test-number} - ptr for: {?}
# unique_ptr reimplementation: basic functionality
ok {test-number} - ptr.get() != 0 for: 0x<hex digits> != 0
# unique_ptr reimplementation: basic functionality
ok {test-number} - *ptr == 2 for: 2 == 2
# unique_ptr reimplementation: basic functionality
ok {test-number} - !(ptr) for: !{?}
# unique_ptr reimplementation: basic functionality
ok {test-number} - ptr.get() == 0 for: 0 == 0
# unique_ptr reimplementation: basic functionality
ok {test-number} - !(ptr1) for: !{?}
# unique_ptr reimplementation: basic functionality
ok {test-number} - ptr2 for: {?}
# unique_ptr reimplementation: basic functionality
ok {test-number} - *ptr2 == 1 for: 1 == 1
# unique_ptr reimplementation: basic functionality
ok {test-number} - !(ptr2) for: !{?}
# unique_ptr reimplementation: basic functionality
ok {test-number} - ptr1 for: {?}
# unique_ptr reimplementation: basic functionality
ok {test-number} - *ptr1 == 2 for: 2 == 2
# unique_ptr reimplementation: basic functionality
ok {test-number} - *ptr1 == 2 for: 2 == 2
# unique_ptr reimplementation: basic functionality
ok {test-number} - *ptr2 == 1 for: 1 == 1
# vec<vec<string,alloc>> -> toString # vec<vec<string,alloc>> -> toString
ok {test-number} - ::Catch::Detail::stringify(v) == "{ }" for: "{ }" == "{ }" ok {test-number} - ::Catch::Detail::stringify(v) == "{ }" for: "{ }" == "{ }"
# vec<vec<string,alloc>> -> toString # vec<vec<string,alloc>> -> toString
@ -3818,5 +3874,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} - ok {test-number} -
# xmlentitycheck # xmlentitycheck
ok {test-number} - ok {test-number} -
1..1905 1..1933

View File

@ -547,6 +547,8 @@ Exception.tests.cpp:<line number>|nunexpected exception with message:|n "For so
##teamcity[testStarted name='Unexpected exceptions can be translated'] ##teamcity[testStarted name='Unexpected exceptions can be translated']
Exception.tests.cpp:<line number>|nunexpected exception with message:|n "3.14"'] Exception.tests.cpp:<line number>|nunexpected exception with message:|n "3.14"']
##teamcity[testFinished name='Unexpected exceptions can be translated' duration="{duration}"] ##teamcity[testFinished name='Unexpected exceptions can be translated' duration="{duration}"]
##teamcity[testStarted name='Upcasting special member functions']
##teamcity[testFinished name='Upcasting special member functions' duration="{duration}"]
##teamcity[testStarted name='Usage of the SizeIs range matcher'] ##teamcity[testStarted name='Usage of the SizeIs range matcher']
##teamcity[testFinished name='Usage of the SizeIs range matcher' duration="{duration}"] ##teamcity[testFinished name='Usage of the SizeIs range matcher' duration="{duration}"]
##teamcity[testStarted name='Use a custom approx'] ##teamcity[testStarted name='Use a custom approx']
@ -671,6 +673,8 @@ Misc.tests.cpp:<line number>|nexpression failed with message:|n "Testing if fib
Misc.tests.cpp:<line number>|nexpression failed with message:|n "Testing if fib|[6|] (13) is even"|n CHECK( ( fib|[i|] % 2 ) == 0 )|nwith expansion:|n 1 == 0|n'] Misc.tests.cpp:<line number>|nexpression failed with message:|n "Testing if fib|[6|] (13) is even"|n CHECK( ( fib|[i|] % 2 ) == 0 )|nwith expansion:|n 1 == 0|n']
Misc.tests.cpp:<line number>|nexpression failed with message:|n "Testing if fib|[7|] (21) is even"|n CHECK( ( fib|[i|] % 2 ) == 0 )|nwith expansion:|n 1 == 0|n'] Misc.tests.cpp:<line number>|nexpression failed with message:|n "Testing if fib|[7|] (21) is even"|n CHECK( ( fib|[i|] % 2 ) == 0 )|nwith expansion:|n 1 == 0|n']
##teamcity[testFinished name='looped tests' duration="{duration}"] ##teamcity[testFinished name='looped tests' duration="{duration}"]
##teamcity[testStarted name='make_unique reimplementation']
##teamcity[testFinished name='make_unique reimplementation' duration="{duration}"]
##teamcity[testStarted name='mean'] ##teamcity[testStarted name='mean']
##teamcity[testFinished name='mean' duration="{duration}"] ##teamcity[testFinished name='mean' duration="{duration}"]
##teamcity[testStarted name='measure'] ##teamcity[testStarted name='measure']
@ -807,6 +811,8 @@ Exception.tests.cpp:<line number>|nunexpected exception with message:|n "Why wo
##teamcity[testFinished name='tuple<tuple<int>,tuple<>,float>' duration="{duration}"] ##teamcity[testFinished name='tuple<tuple<int>,tuple<>,float>' duration="{duration}"]
##teamcity[testStarted name='uniform samples'] ##teamcity[testStarted name='uniform samples']
##teamcity[testFinished name='uniform samples' duration="{duration}"] ##teamcity[testFinished name='uniform samples' duration="{duration}"]
##teamcity[testStarted name='unique_ptr reimplementation: basic functionality']
##teamcity[testFinished name='unique_ptr reimplementation: basic functionality' duration="{duration}"]
##teamcity[testStarted name='vec<vec<string,alloc>> -> toString'] ##teamcity[testStarted name='vec<vec<string,alloc>> -> toString']
##teamcity[testFinished name='vec<vec<string,alloc>> -> toString' duration="{duration}"] ##teamcity[testFinished name='vec<vec<string,alloc>> -> toString' duration="{duration}"]
##teamcity[testStarted name='vector<bool> -> toString'] ##teamcity[testStarted name='vector<bool> -> toString']

View File

@ -13944,6 +13944,31 @@ There is no extra whitespace here
</Exception> </Exception>
<OverallResult success="false"/> <OverallResult success="false"/>
</TestCase> </TestCase>
<TestCase name="Upcasting special member functions" tags="[internals][unique-ptr]" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Section name="Move constructor" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
bptr->i == 3
</Original>
<Expanded>
3 == 3
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="move assignment" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
bptr->i == 3
</Original>
<Expanded>
3 == 3
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Usage of the SizeIs range matcher" tags="[matchers][size][templated]" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > <TestCase name="Usage of the SizeIs range matcher" tags="[matchers][size][templated]" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
<Section name="Some with stdlib containers" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > <Section name="Some with stdlib containers" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
<Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
@ -15773,6 +15798,42 @@ loose text artifact
</Expression> </Expression>
<OverallResult success="false"/> <OverallResult success="false"/>
</TestCase> </TestCase>
<TestCase name="make_unique reimplementation" tags="[internals][unique-ptr]" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Section name="From lvalue copies" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
!(lval.has_moved)
</Original>
<Expanded>
!false
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="From rvalue moves" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
rval.has_moved
</Original>
<Expanded>
true
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<Section name="Variadic constructor" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
*ptr == std::tuple&lt;int, double, int>{1, 2., 3}
</Original>
<Expanded>
{?} == {?}
</Expanded>
</Expression>
<OverallResults successes="1" failures="0" expectedFailures="0"/>
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="mean" tags="[benchmark]" filename="tests/<exe-name>/IntrospectiveTests/InternalBenchmark.tests.cpp" > <TestCase name="mean" tags="[benchmark]" filename="tests/<exe-name>/IntrospectiveTests/InternalBenchmark.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/InternalBenchmark.tests.cpp" > <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/InternalBenchmark.tests.cpp" >
<Original> <Original>
@ -17416,6 +17477,220 @@ loose text artifact
</Expression> </Expression>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<TestCase name="unique_ptr reimplementation: basic functionality" tags="[internals][unique-ptr]" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Section name="Default constructed unique_ptr is empty" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
!(ptr)
</Original>
<Expanded>
!{?}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
ptr.get() == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section>
<Section name="Take ownership of allocation" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
ptr
</Original>
<Expanded>
{?}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
*ptr == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
ptr.get() == naked_ptr
</Original>
<Expanded>
0x<hex digits> == 0x<hex digits>
</Expanded>
</Expression>
<Section name="Plain reset deallocates" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
!(ptr)
</Original>
<Expanded>
!{?}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
ptr.get() == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="5" failures="0" expectedFailures="0"/>
</Section>
<Section name="Take ownership of allocation" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
ptr
</Original>
<Expanded>
{?}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
*ptr == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
ptr.get() == naked_ptr
</Original>
<Expanded>
0x<hex digits> == 0x<hex digits>
</Expanded>
</Expression>
<Section name="Reset replaces ownership" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
ptr
</Original>
<Expanded>
{?}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
ptr.get() != 0
</Original>
<Expanded>
0x<hex digits> != 0
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
*ptr == 2
</Original>
<Expanded>
2 == 2
</Expanded>
</Expression>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="6" failures="0" expectedFailures="0"/>
</Section>
<Section name="Release releases ownership" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="CHECK_FALSE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
!(ptr)
</Original>
<Expanded>
!{?}
</Expanded>
</Expression>
<Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
ptr.get() == 0
</Original>
<Expanded>
0 == 0
</Expanded>
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section>
<Section name="Move constructor" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
!(ptr1)
</Original>
<Expanded>
!{?}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
ptr2
</Original>
<Expanded>
{?}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
*ptr2 == 1
</Original>
<Expanded>
1 == 1
</Expanded>
</Expression>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<Section name="Move assignment" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
!(ptr2)
</Original>
<Expanded>
!{?}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
ptr1
</Original>
<Expanded>
{?}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
*ptr1 == 2
</Original>
<Expanded>
2 == 2
</Expanded>
</Expression>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<Section name="free swap" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
*ptr1 == 2
</Original>
<Expanded>
2 == 2
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/UniquePtr.tests.cpp" >
<Original>
*ptr2 == 1
</Original>
<Expanded>
1 == 1
</Expanded>
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="vec&lt;vec&lt;string,alloc>> -> toString" tags="[toString][vector,allocator]" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" > <TestCase name="vec&lt;vec&lt;string,alloc>> -> toString" tags="[toString][vector,allocator]" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" > <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/ToStringVector.tests.cpp" >
<Original> <Original>
@ -17756,7 +18031,7 @@ loose text artifact
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="1744" failures="149" expectedFailures="21"/> <OverallResults successes="1772" failures="149" expectedFailures="21"/>
</Group> </Group>
<OverallResults successes="1744" failures="148" expectedFailures="21"/> <OverallResults successes="1772" failures="148" expectedFailures="21"/>
</Catch> </Catch>

View File

@ -0,0 +1,133 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <tuple>
namespace {
struct unique_ptr_test_helper {
bool dummy = false;
};
} // end unnamed namespace
TEST_CASE("unique_ptr reimplementation: basic functionality", "[internals][unique-ptr]") {
using Catch::Detail::unique_ptr;
SECTION("Default constructed unique_ptr is empty") {
unique_ptr<int> ptr;
REQUIRE_FALSE(ptr);
REQUIRE(ptr.get() == nullptr);
}
SECTION("Take ownership of allocation") {
auto naked_ptr = new int{ 0 };
unique_ptr<int> ptr(naked_ptr);
REQUIRE(ptr);
REQUIRE(*ptr == 0);
REQUIRE(ptr.get() == naked_ptr);
SECTION("Plain reset deallocates") {
ptr.reset(); // this makes naked_ptr dangling!
REQUIRE_FALSE(ptr);
REQUIRE(ptr.get() == nullptr);
}
SECTION("Reset replaces ownership") {
ptr.reset(new int{ 2 });
REQUIRE(ptr);
REQUIRE(ptr.get() != nullptr);
REQUIRE(*ptr == 2);
}
}
SECTION("Release releases ownership") {
auto naked_ptr = new int{ 1 };
unique_ptr<int> ptr(naked_ptr);
ptr.release();
CHECK_FALSE(ptr);
CHECK(ptr.get() == nullptr);
delete naked_ptr;
}
SECTION("Move constructor") {
unique_ptr<int> ptr1(new int{ 1 });
auto ptr2(std::move(ptr1));
REQUIRE_FALSE(ptr1);
REQUIRE(ptr2);
REQUIRE(*ptr2 == 1);
}
SECTION("Move assignment") {
unique_ptr<int> ptr1(new int{ 1 }), ptr2(new int{ 2 });
ptr1 = std::move(ptr2);
REQUIRE_FALSE(ptr2);
REQUIRE(ptr1);
REQUIRE(*ptr1 == 2);
}
SECTION("free swap") {
unique_ptr<int> ptr1(new int{ 1 }), ptr2(new int{ 2 });
swap(ptr1, ptr2);
REQUIRE(*ptr1 == 2);
REQUIRE(*ptr2 == 1);
}
}
namespace {
struct base {
int i;
base(int i) :i(i) {}
};
struct derived : base { using base::base; };
struct unrelated {};
} // end unnamed namespace
static_assert( std::is_constructible<Catch::Detail::unique_ptr<base>,
Catch::Detail::unique_ptr<derived>>::value, "Upcasting is supported");
static_assert(!std::is_constructible<Catch::Detail::unique_ptr<derived>,
Catch::Detail::unique_ptr<base>>::value, "Downcasting is not supported");
static_assert(!std::is_constructible<Catch::Detail::unique_ptr<base>,
Catch::Detail::unique_ptr<unrelated>>::value, "Cannot just convert one ptr type to another");
TEST_CASE("Upcasting special member functions", "[internals][unique-ptr]") {
using Catch::Detail::unique_ptr;
unique_ptr<derived> dptr(new derived{3});
SECTION("Move constructor") {
unique_ptr<base> bptr(std::move(dptr));
REQUIRE(bptr->i == 3);
}
SECTION("move assignment") {
unique_ptr<base> bptr(new base{ 1 });
bptr = std::move(dptr);
REQUIRE(bptr->i == 3);
}
}
namespace {
struct move_detector {
bool has_moved = false;
move_detector() = default;
move_detector(move_detector const& rhs) = default;
move_detector& operator=(move_detector const& rhs) = default;
move_detector(move_detector&& rhs) {
rhs.has_moved = true;
}
move_detector& operator=(move_detector&& rhs) {
rhs.has_moved = true;
return *this;
}
};
} // end unnamed namespace
TEST_CASE("make_unique reimplementation", "[internals][unique-ptr]") {
using Catch::Detail::make_unique;
SECTION("From lvalue copies") {
move_detector lval;
auto ptr = make_unique<move_detector>(lval);
REQUIRE_FALSE(lval.has_moved);
}
SECTION("From rvalue moves") {
move_detector rval;
auto ptr = make_unique<move_detector>(std::move(rval));
REQUIRE(rval.has_moved);
}
SECTION("Variadic constructor") {
auto ptr = make_unique<std::tuple<int, double, int>>(1, 2., 3);
REQUIRE(*ptr == std::tuple<int, double, int>{1, 2., 3});
}
}