From 808067397797ab85d7b80820411c78f0a28ad5dc Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Sun, 9 Dec 2007 11:53:08 +0000 Subject: [PATCH] Added value_init tests if a copy function of T is called when value_initialized is copied -- a case I hadn't thought of before... [SVN r41919] --- value_init_test.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/value_init_test.cpp b/value_init_test.cpp index fcbada5..00c3333 100644 --- a/value_init_test.cpp +++ b/value_init_test.cpp @@ -156,6 +156,29 @@ bool operator == ( AggregatePODStructWrapper const& lhs, AggregatePODStructWrapp typedef unsigned char ArrayOfBytes[256]; + +// +// A struct that allows testing whether the appropriate copy functions are called. +// +struct CopyFunctionCallTester +{ + bool is_copy_constructed; + bool is_assignment_called; + + CopyFunctionCallTester() + : is_copy_constructed(false), is_assignment_called(false) {} + + CopyFunctionCallTester(const CopyFunctionCallTester & ) + : is_copy_constructed(true), is_assignment_called(false) {} + + CopyFunctionCallTester & operator=(const CopyFunctionCallTester & ) + { + is_assignment_called = true ; + return *this ; + } +}; + + // // This test function tests boost::value_initialized for a specific type T. // The first argument (y) is assumed have the value of a value-initialized object. @@ -244,8 +267,22 @@ int test_main(int, char **) boost::value_initialized valueInitializedArrayOfBytes; BOOST_CHECK (std::memcmp(get(valueInitializedArrayOfBytes), zeroInitializedArrayOfBytes, sizeof(ArrayOfBytes)) == 0); + boost::value_initialized copyFunctionCallTester1; + BOOST_CHECK ( ! get(copyFunctionCallTester1).is_copy_constructed); + BOOST_CHECK ( ! get(copyFunctionCallTester1).is_assignment_called); + + boost::value_initialized copyFunctionCallTester2 = boost::value_initialized(copyFunctionCallTester1); + BOOST_CHECK ( get(copyFunctionCallTester2).is_copy_constructed); + BOOST_CHECK ( ! get(copyFunctionCallTester2).is_assignment_called); + + boost::value_initialized copyFunctionCallTester3; + copyFunctionCallTester3 = boost::value_initialized(copyFunctionCallTester1); + BOOST_CHECK ( ! get(copyFunctionCallTester3).is_copy_constructed); + BOOST_CHECK ( get(copyFunctionCallTester3).is_assignment_called); + return 0; } unsigned int expected_failures = 0; +