|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r53128 - in trunk: boost/signals2 libs/signals2/doc/reference libs/signals2/test
From: fmhess_at_[hidden]
Date: 2009-05-20 10:36:53
Author: fmhess
Date: 2009-05-20 10:36:49 EDT (Wed, 20 May 2009)
New Revision: 53128
URL: http://svn.boost.org/trac/boost/changeset/53128
Log:
Made shared_connection_block default constructible. Split shared_connection_block
tests out of deletion_test, and added a little test for a
default-constructed shared_connection_block.
Added:
trunk/libs/signals2/test/shared_connection_block_test.cpp (contents, props changed)
Text files modified:
trunk/boost/signals2/shared_connection_block.hpp | 2 +-
trunk/libs/signals2/doc/reference/shared_connection_block.xml | 7 +++++++
trunk/libs/signals2/test/Jamfile.v2 | 3 ++-
trunk/libs/signals2/test/deletion_test.cpp | 30 ------------------------------
4 files changed, 10 insertions(+), 32 deletions(-)
Modified: trunk/boost/signals2/shared_connection_block.hpp
==============================================================================
--- trunk/boost/signals2/shared_connection_block.hpp (original)
+++ trunk/boost/signals2/shared_connection_block.hpp 2009-05-20 10:36:49 EDT (Wed, 20 May 2009)
@@ -22,7 +22,7 @@
class shared_connection_block
{
public:
- shared_connection_block(const connection &conn, bool initially_blocked = true):
+ shared_connection_block(const connection &conn = connection(), bool initially_blocked = true):
_weak_connection_body(conn._weak_connection_body)
{
if(initially_blocked) block();
Modified: trunk/libs/signals2/doc/reference/shared_connection_block.xml
==============================================================================
--- trunk/libs/signals2/doc/reference/shared_connection_block.xml (original)
+++ trunk/libs/signals2/doc/reference/shared_connection_block.xml 2009-05-20 10:36:49 EDT (Wed, 20 May 2009)
@@ -45,6 +45,7 @@
<constructor>
<parameter name="conn">
<paramtype>const boost::signals2::connection &</paramtype>
+ <default>connection()</default>
</parameter>
<parameter name="initially_blocking">
<paramtype>bool</paramtype>
@@ -59,6 +60,12 @@
parameter is <code>true</code>. The block on the connection may be released
by calling the <methodname>unblock</methodname> method,
or destroying the <code>shared_connection_block</code> object.</para>
+ <para>Default construction of a <code>shared_connection_block</code> results in a
+ <code>shared_connection_block</code> which references the NULL connection.
+ Such a <code>shared_connection_block</code> is safe to use, though not
+ particularly useful until it is assigned another
+ <code>shared_connection_block</code> which references a real connection.
+ </para>
</effects>
<postconditions><para><code>this->blocking() == initially_blocking</code></para></postconditions>
</constructor>
Modified: trunk/libs/signals2/test/Jamfile.v2
==============================================================================
--- trunk/libs/signals2/test/Jamfile.v2 (original)
+++ trunk/libs/signals2/test/Jamfile.v2 2009-05-20 10:36:49 EDT (Wed, 20 May 2009)
@@ -1,4 +1,4 @@
-# Boost.Signals2 Library
+# Boost.Signals2 Library
# Copyright Douglas Gregor 2001-2003.
# Copyright Frank Mori Hess 2009.
@@ -38,6 +38,7 @@
[ thread-run mutex_test.cpp ]
[ run ordering_test.cpp ]
[ run regression_test.cpp ]
+ [ run shared_connection_block_test.cpp ]
[ run signal_n_test.cpp ]
[ run signal_test.cpp ]
[ run signal_type_test.cpp ]
Modified: trunk/libs/signals2/test/deletion_test.cpp
==============================================================================
--- trunk/libs/signals2/test/deletion_test.cpp (original)
+++ trunk/libs/signals2/test/deletion_test.cpp 2009-05-20 10:36:49 EDT (Wed, 20 May 2009)
@@ -93,36 +93,6 @@
s0(); std::cout << std::endl;
BOOST_CHECK(test_output == "123");
- std::cout << "Blocking 2" << std::endl;
-
- {
- boost::signals2::shared_connection_block block(connections[2]);
- test_output = "";
- s0(); std::cout << std::endl;
- BOOST_CHECK(test_output == "13");
- }
-
- std::cout << "Unblocking 2" << std::endl;
-
- test_output = "";
- s0(); std::cout << std::endl;
- BOOST_CHECK(test_output == "123");
-
- std::cout << "Blocking 1 through const connection" << std::endl;
-
- {
- const boost::signals2::connection conn = connections[1];
- boost::signals2::shared_connection_block block(conn);
- test_output = "";
- s0(); std::cout << std::endl;
- BOOST_CHECK(test_output == "23");
- std::cout << "Unblocking 1" << std::endl;
- block.unblock();
- test_output = "";
- s0(); std::cout << std::endl;
- BOOST_CHECK(test_output == "123");
- }
-
s0.disconnect_all_slots();
BOOST_CHECK(s0.empty());
Added: trunk/libs/signals2/test/shared_connection_block_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/signals2/test/shared_connection_block_test.cpp 2009-05-20 10:36:49 EDT (Wed, 20 May 2009)
@@ -0,0 +1,98 @@
+// Boost.Signals2 library
+
+// Copyright Douglas Gregor 2001-2003.
+// Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// For more information, see http://www.boost.org
+
+#include <boost/test/minimal.hpp>
+#include <boost/array.hpp>
+#include <boost/signals2/shared_connection_block.hpp>
+#include <boost/signals2/signal.hpp>
+#include <iostream>
+#include <sstream>
+#include <string>
+
+static boost::array<boost::signals2::connection, 4> connections;
+
+static std::ostringstream test_output;
+
+struct test_slot {
+ explicit test_slot(int v = 0) : value(v)
+ {}
+
+ void operator()() const {
+ test_output << value;
+ }
+
+ int value;
+};
+
+int test_main(int, char* [])
+{
+ boost::signals2::signal0<void> s0;
+
+ for(unsigned i = 0; i < connections.size(); ++i)
+ {
+ connections.at(i) = s0.connect(test_slot(i));
+ }
+
+
+ {
+ // Blocking 2
+ boost::signals2::shared_connection_block block(connections.at(2));
+ BOOST_CHECK(block.blocking());
+ test_output.str("");
+ s0();
+ BOOST_CHECK(test_output.str() == "013");
+ }
+
+ // Unblocking 2
+ test_output.str("");
+ s0();
+ BOOST_CHECK(test_output.str() == "0123");
+
+ {
+ // Blocking 1 through const connection
+ const boost::signals2::connection conn = connections.at(1);
+ boost::signals2::shared_connection_block block(conn);
+ test_output.str("");
+ s0();
+ std::cout << test_output.str() << std::endl;
+ BOOST_CHECK(test_output.str() == "023");
+ // Unblocking 1
+ block.unblock();
+ BOOST_CHECK(block.blocking() == false);
+ test_output.str("");
+ s0();
+ BOOST_CHECK(test_output.str() == "0123");
+ }
+
+ {
+ // initially unblocked
+ boost::signals2::shared_connection_block block(connections.at(3), false);
+ BOOST_CHECK(block.blocking() == false);
+ test_output.str("");
+ s0();
+ BOOST_CHECK(test_output.str() == "0123");
+ // block
+ block.block();
+ test_output.str("");
+ s0();
+ BOOST_CHECK(test_output.str() == "012");
+ }
+
+ {
+ // default construction
+ boost::signals2::shared_connection_block block;
+ BOOST_CHECK(block.blocking() == true);
+ block.unblock();
+ BOOST_CHECK(block.blocking() == false);
+ block.block();
+ BOOST_CHECK(block.blocking() == true);
+ }
+ return 0;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk