$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r83977 - in trunk/libs/log/test: . run
From: andrey.semashev_at_[hidden]
Date: 2013-04-20 07:15:37
Author: andysem
Date: 2013-04-20 07:15:36 EDT (Sat, 20 Apr 2013)
New Revision: 83977
URL: http://svn.boost.org/trac/boost/changeset/83977
Log:
Made tests build in multithreaded environment by default (this can still be changed by specifying threading=single in the command line). The util_once_block test updated to be usable in singlethreaded builds.
Text files modified: 
   trunk/libs/log/test/Jamfile.v2              |     3 +                                       
   trunk/libs/log/test/run/util_once_block.cpp |   107 +++++++++++++++++++++++++++++++++++++-- 
   2 files changed, 102 insertions(+), 8 deletions(-)
Modified: trunk/libs/log/test/Jamfile.v2
==============================================================================
--- trunk/libs/log/test/Jamfile.v2	(original)
+++ trunk/libs/log/test/Jamfile.v2	2013-04-20 07:15:36 EDT (Sat, 20 Apr 2013)
@@ -28,6 +28,9 @@
         <library>/boost/test//boost_unit_test_framework
         <threading>single:<define>BOOST_LOG_NO_THREADS
         <threading>multi:<library>/boost/thread//boost_thread
+    : default-build
+        # Testers typically don't specify threading environment and the library can be built and tested for single and multi. I'm more interested in multi though.
+        <threading>multi
 #        <link>static
     ;
 
Modified: trunk/libs/log/test/run/util_once_block.cpp
==============================================================================
--- trunk/libs/log/test/run/util_once_block.cpp	(original)
+++ trunk/libs/log/test/run/util_once_block.cpp	2013-04-20 07:15:36 EDT (Sat, 20 Apr 2013)
@@ -17,10 +17,10 @@
 #define BOOST_TEST_MODULE util_once_block
 
 #include <boost/log/utility/once_block.hpp>
+#include <boost/test/included/unit_test.hpp>
 
 #if !defined(BOOST_LOG_NO_THREADS)
 
-#include <boost/test/included/unit_test.hpp>
 #include <boost/thread/thread.hpp>
 #include <boost/thread/mutex.hpp>
 #include <boost/thread/locks.hpp>
@@ -50,7 +50,7 @@
 void once_block_flag_thread()
 {
     int my_once_value = 0;
-    for (unsigned i = 0; i < LOOP_COUNT; ++i)
+    for (unsigned int i = 0; i < LOOP_COUNT; ++i)
     {
         BOOST_LOG_ONCE_BLOCK_FLAG(flag)
         {
@@ -74,7 +74,7 @@
 
     try
     {
-        for (unsigned i = 0; i < THREAD_COUNT; ++i)
+        for (unsigned int i = 0; i < THREAD_COUNT; ++i)
         {
             group.create_thread(&once_block_flag_thread);
         }
@@ -95,7 +95,7 @@
 void once_block_thread()
 {
     int my_once_value = 0;
-    for (unsigned i = 0; i < LOOP_COUNT; ++i)
+    for (unsigned int i = 0; i < LOOP_COUNT; ++i)
     {
         BOOST_LOG_ONCE_BLOCK()
         {
@@ -121,7 +121,7 @@
 
     try
     {
-        for (unsigned i = 0; i < THREAD_COUNT; ++i)
+        for (unsigned int i = 0; i < THREAD_COUNT; ++i)
         {
             group.create_thread(&once_block_thread);
         }
@@ -142,8 +142,8 @@
 {
 };
 
-unsigned pass_counter = 0;
-unsigned exception_counter = 0;
+unsigned int pass_counter = 0;
+unsigned int exception_counter = 0;
 
 void once_block_with_exception_thread()
 {
@@ -173,7 +173,7 @@
 
     try
     {
-        for (unsigned i = 0; i < THREAD_COUNT; ++i)
+        for (unsigned int i = 0; i < THREAD_COUNT; ++i)
         {
             group.create_thread(&once_block_with_exception_thread);
         }
@@ -190,4 +190,95 @@
     BOOST_CHECK_EQUAL(exception_counter, 2u);
 }
 
+#else // BOOST_LOG_NO_THREADS
+
+namespace logging = boost::log;
+
+enum config
+{
+    LOOP_COUNT = 100
+};
+
+logging::once_block_flag flag = BOOST_LOG_ONCE_BLOCK_INIT;
+int var_to_init_once_flag = 0;
+
+void initialize_variable()
+{
+    ++var_to_init_once_flag;
+}
+
+
+// The test checks if the BOOST_LOG_ONCE_BLOCK_FLAG macro works
+BOOST_AUTO_TEST_CASE(once_block_flag)
+{
+    for (unsigned int i = 0; i < LOOP_COUNT; ++i)
+    {
+        BOOST_LOG_ONCE_BLOCK_FLAG(flag)
+        {
+            initialize_variable();
+        }
+
+        if (var_to_init_once_flag != 1)
+        {
+            break;
+        }
+    }
+
+    BOOST_CHECK_EQUAL(var_to_init_once_flag, 1);
+}
+
+int var_to_init_once = 0;
+
+// The test checks if the BOOST_LOG_ONCE_BLOCK macro works
+BOOST_AUTO_TEST_CASE(once_block)
+{
+    for (unsigned int i = 0; i < LOOP_COUNT; ++i)
+    {
+        BOOST_LOG_ONCE_BLOCK()
+        {
+            ++var_to_init_once;
+        }
+
+        if (var_to_init_once != 1)
+        {
+            break;
+        }
+    }
+
+    BOOST_CHECK_EQUAL(var_to_init_once, 1);
+}
+
+struct my_exception
+{
+};
+
+unsigned int pass_counter = 0;
+unsigned int exception_counter = 0;
+
+// The test verifies that the once_block flag is not set if an exception is thrown from the once-block
+BOOST_AUTO_TEST_CASE(once_block_retried_on_exception)
+{
+    for (unsigned int i = 0; i < LOOP_COUNT; ++i)
+    {
+        try
+        {
+            BOOST_LOG_ONCE_BLOCK()
+            {
+                ++pass_counter;
+                if (pass_counter < 3)
+                {
+                    throw my_exception();
+                }
+            }
+        }
+        catch (my_exception&)
+        {
+            ++exception_counter;
+        }
+    }
+
+    BOOST_CHECK_EQUAL(pass_counter, 3u);
+    BOOST_CHECK_EQUAL(exception_counter, 2u);
+}
+
 #endif // BOOST_LOG_NO_THREADS