Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77407 - in trunk/libs: local_function/test scope_exit/test
From: lorcaminiti_at_[hidden]
Date: 2012-03-19 14:09:13


Author: lcaminiti
Date: 2012-03-19 14:09:12 EDT (Mon, 19 Mar 2012)
New Revision: 77407
URL: http://svn.boost.org/trac/boost/changeset/77407

Log:
Added tests for ScopeExit and LocalFunction _ID macros.
Added:
   trunk/libs/local_function/test/same_line.cpp (contents, props changed)
   trunk/libs/local_function/test/same_line_seq.cpp (contents, props changed)
   trunk/libs/scope_exit/test/same_line.cpp (contents, props changed)
   trunk/libs/scope_exit/test/same_line_seq.cpp (contents, props changed)
Text files modified:
   trunk/libs/local_function/test/Jamfile.v2 | 1 +
   trunk/libs/scope_exit/test/Jamfile.v2 | 1 +
   2 files changed, 2 insertions(+), 0 deletions(-)

Modified: trunk/libs/local_function/test/Jamfile.v2
==============================================================================
--- trunk/libs/local_function/test/Jamfile.v2 (original)
+++ trunk/libs/local_function/test/Jamfile.v2 2012-03-19 14:09:12 EDT (Mon, 19 Mar 2012)
@@ -52,6 +52,7 @@
 run-vaseq return_inc ;
 run-vaseq return_setget ;
 run-vaseq return_this ;
+run-vaseq same_line ;
 run ten_void.cpp ;
 run ten_void.cpp : : : <define>BOOST_NO_VARIADIC_MACROS : ten_void_nova : ;
 run-vaseq transform ;

Added: trunk/libs/local_function/test/same_line.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/local_function/test/same_line.cpp 2012-03-19 14:09:12 EDT (Mon, 19 Mar 2012)
@@ -0,0 +1,45 @@
+
+// Copyright (C) 2009-2012 Lorenzo Caminiti
+// Distributed under the Boost Software License, Version 1.0
+// (see accompanying file LICENSE_1_0.txt or a copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// Home at http://www.boost.org/libs/local_function
+
+#include <boost/config.hpp>
+#ifndef BOOST_NO_VARIADIC_MACROS
+
+#include <boost/local_function.hpp>
+#include <boost/preprocessor/cat.hpp>
+#define BOOST_TEST_MODULE TestSameLine
+#include <boost/test/unit_test.hpp>
+#include <iostream>
+
+//[same_line
+#define LOCAL_INC_DEC(offset) \
+ int BOOST_LOCAL_FUNCTION_ID( \
+ BOOST_PP_CAT(inc, __LINE__) /* unique ID */, 0 /* no TPL */, \
+ const bind offset, const int x) { \
+ return x + offset; \
+ } BOOST_LOCAL_FUNCTION_NAME(inc) \
+ \
+ int BOOST_LOCAL_FUNCTION_ID( \
+ BOOST_PP_CAT(dec, __LINE__) /* unique ID */, 0 /* no TPL */, \
+ const bind offset, const int x) { \
+ return x - offset; \
+ } BOOST_LOCAL_FUNCTION_NAME(dec)
+
+BOOST_AUTO_TEST_CASE(test_same_line)
+{
+ int delta = 10;
+ LOCAL_INC_DEC(delta) // Declare local functions on same line using `_ID`.
+
+ BOOST_CHECK(dec(inc(123)) == 123);
+}
+//]
+
+#else
+
+int main(void) { return 0; } // Trivial test.
+
+#endif
+

Added: trunk/libs/local_function/test/same_line_seq.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/local_function/test/same_line_seq.cpp 2012-03-19 14:09:12 EDT (Mon, 19 Mar 2012)
@@ -0,0 +1,34 @@
+
+// Copyright (C) 2009-2012 Lorenzo Caminiti
+// Distributed under the Boost Software License, Version 1.0
+// (see accompanying file LICENSE_1_0.txt or a copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// Home at http://www.boost.org/libs/local_function
+
+#include <boost/local_function.hpp>
+#include <boost/preprocessor/cat.hpp>
+#define BOOST_TEST_MODULE TestSameLineSeq
+#include <boost/test/unit_test.hpp>
+#include <iostream>
+
+#define LOCAL_INC_DEC(offset) \
+ int BOOST_LOCAL_FUNCTION_ID( \
+ BOOST_PP_CAT(inc, __LINE__) /* unique ID */, 0 /* no TPL */, \
+ (const bind offset) (const int x) ) { \
+ return x + offset; \
+ } BOOST_LOCAL_FUNCTION_NAME(inc) \
+ \
+ int BOOST_LOCAL_FUNCTION_ID( \
+ BOOST_PP_CAT(dec, __LINE__) /* unique ID */, 0 /* no TPL */, \
+ (const bind offset) (const int x) ) { \
+ return x - offset; \
+ } BOOST_LOCAL_FUNCTION_NAME(dec)
+
+BOOST_AUTO_TEST_CASE(test_same_line_seq)
+{
+ int delta = 10;
+ LOCAL_INC_DEC(delta) // Declare local functions on same line using `_ID`.
+
+ BOOST_CHECK(dec(inc(123)) == 123);
+}
+

Modified: trunk/libs/scope_exit/test/Jamfile.v2
==============================================================================
--- trunk/libs/scope_exit/test/Jamfile.v2 (original)
+++ trunk/libs/scope_exit/test/Jamfile.v2 2012-03-19 14:09:12 EDT (Mon, 19 Mar 2012)
@@ -32,6 +32,7 @@
         [ run-vaseq world_this ]
         [ run-vaseq world_tpl ]
         [ run world_void.cpp ]
+ [ run-vaseq same_line ]
     ;
 
 test-suite native_tests

Added: trunk/libs/scope_exit/test/same_line.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/same_line.cpp 2012-03-19 14:09:12 EDT (Mon, 19 Mar 2012)
@@ -0,0 +1,63 @@
+
+// Copyright (C) 2006-2009, 2012 Alexander Nasonov
+// Copyright (C) 2012 Lorenzo Caminiti
+// Distributed under the Boost Software License, Version 1.0
+// (see accompanying file LICENSE_1_0.txt or a copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// Home at http://www.boost.org/libs/scope_exit
+
+#include <boost/config.hpp>
+#ifndef BOOST_NO_VARIADIC_MACROS
+
+#include <boost/scope_exit.hpp>
+#include <boost/preprocessor/cat.hpp>
+#define BOOST_TEST_MODULE TestSameLine
+#include <boost/test/unit_test.hpp>
+
+//[same_line
+#define SCOPE_EXIT_INC_DEC(variable, offset) \
+ BOOST_SCOPE_EXIT_ID( \
+ BOOST_PP_CAT(inc, __LINE__) /* unique ID */, 0 /* no TPL */, \
+ &variable, offset) { \
+ variable += offset; \
+ } BOOST_SCOPE_EXIT_END_ID(BOOST_PP_CAT(inc, __LINE__)) \
+ \
+ BOOST_SCOPE_EXIT_ID( \
+ BOOST_PP_CAT(dec, __LINE__) /* unique ID */, 0 /* no TPL */, \
+ &variable, offset) { \
+ variable -= offset; \
+ } BOOST_SCOPE_EXIT_END_ID(BOOST_PP_CAT(dec, __LINE__))
+
+#define SCOPE_EXIT_ALL_INC_DEC(variable, offset) \
+ BOOST_SCOPE_EXIT_ALL_ID(BOOST_PP_CAT(inc, __LINE__) /* unique ID */, \
+ =, &variable) { \
+ variable += offset; \
+ }; \
+ BOOST_SCOPE_EXIT_ALL_ID(BOOST_PP_CAT(dec, __LINE__) /* unique ID */, \
+ =, &variable) { \
+ variable -= offset; \
+ };
+
+BOOST_AUTO_TEST_CASE(test_same_line) {
+ int x = 0, delta = 10;
+
+ {
+ SCOPE_EXIT_INC_DEC(x, delta)
+ }
+ BOOST_CHECK(x == 0);
+
+#ifndef BOOST_NO_LAMBDAS
+ {
+ SCOPE_EXIT_ALL_INC_DEC(x, delta)
+ }
+ BOOST_CHECK(x == 0);
+#endif
+}
+//]
+
+#else
+
+int main(void) { return 0; } // Trivial test.
+
+#endif
+

Added: trunk/libs/scope_exit/test/same_line_seq.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/same_line_seq.cpp 2012-03-19 14:09:12 EDT (Mon, 19 Mar 2012)
@@ -0,0 +1,53 @@
+
+// Copyright (C) 2006-2009, 2012 Alexander Nasonov
+// Copyright (C) 2012 Lorenzo Caminiti
+// Distributed under the Boost Software License, Version 1.0
+// (see accompanying file LICENSE_1_0.txt or a copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+// Home at http://www.boost.org/libs/scope_exit
+
+#include <boost/scope_exit.hpp>
+#include <boost/preprocessor/cat.hpp>
+#include <boost/config.hpp>
+#define BOOST_TEST_MODULE TestSameLineSeq
+#include <boost/test/unit_test.hpp>
+
+#define SCOPE_EXIT_INC_DEC(variable, offset) \
+ BOOST_SCOPE_EXIT_ID( \
+ BOOST_PP_CAT(inc, __LINE__) /* unique ID */, 0 /* no TPL */, \
+ (&variable) (offset) ) { \
+ variable += offset; \
+ } BOOST_SCOPE_EXIT_END_ID(BOOST_PP_CAT(inc, __LINE__)) \
+ \
+ BOOST_SCOPE_EXIT_ID( \
+ BOOST_PP_CAT(dec, __LINE__) /* unique ID */, 0 /* no TPL */, \
+ (&variable) (offset) ) { \
+ variable -= offset; \
+ } BOOST_SCOPE_EXIT_END_ID(BOOST_PP_CAT(dec, __LINE__))
+
+#define SCOPE_EXIT_ALL_INC_DEC(variable, offset) \
+ BOOST_SCOPE_EXIT_ALL_ID(BOOST_PP_CAT(inc, __LINE__) /* unique ID */, \
+ (=) (&variable) ) { \
+ variable += offset; \
+ }; \
+ BOOST_SCOPE_EXIT_ALL_ID(BOOST_PP_CAT(dec, __LINE__) /* unique ID */, \
+ (=) (&variable) ) { \
+ variable -= offset; \
+ };
+
+BOOST_AUTO_TEST_CASE(test_same_line_seq) {
+ int x = 0, delta = 10;
+
+ {
+ SCOPE_EXIT_INC_DEC(x, delta)
+ }
+ BOOST_CHECK(x == 0);
+
+#ifndef BOOST_NO_LAMBDAS
+ {
+ SCOPE_EXIT_ALL_INC_DEC(x, delta)
+ }
+ BOOST_CHECK(x == 0);
+#endif
+}
+


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