|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77085 - in trunk/libs/scope_exit: example test
From: lorcaminiti_at_[hidden]
Date: 2012-02-20 16:47:48
Author: lcaminiti
Date: 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
New Revision: 77085
URL: http://svn.boost.org/trac/boost/changeset/77085
Log:
Fixed all sequence syntax tests and examples and always compiling them also forcing BOOST_NO_VARIADIC_MACROS.
Text files modified:
trunk/libs/scope_exit/example/Jamfile.v2 | 20 +++++++++---------
trunk/libs/scope_exit/example/try_catch.cpp | 4 +-
trunk/libs/scope_exit/example/try_catch_seq.cpp | 4 +-
trunk/libs/scope_exit/test/Jamfile.v2 | 42 ++++++++++++++-------------------------
trunk/libs/scope_exit/test/world.cpp | 4 +-
trunk/libs/scope_exit/test/world_checkpoint.cpp | 8 +++---
trunk/libs/scope_exit/test/world_checkpoint_all.cpp | 8 +++---
trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp | 18 +++++++---------
trunk/libs/scope_exit/test/world_checkpoint_seq.cpp | 15 +++++--------
trunk/libs/scope_exit/test/world_seq.cpp | 13 ++++++-----
trunk/libs/scope_exit/test/world_this.cpp | 4 +-
trunk/libs/scope_exit/test/world_this_seq.cpp | 14 ++++--------
trunk/libs/scope_exit/test/world_tpl.cpp | 4 +-
trunk/libs/scope_exit/test/world_tpl_seq.cpp | 8 ++----
14 files changed, 72 insertions(+), 94 deletions(-)
Modified: trunk/libs/scope_exit/example/Jamfile.v2
==============================================================================
--- trunk/libs/scope_exit/example/Jamfile.v2 (original)
+++ trunk/libs/scope_exit/example/Jamfile.v2 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -8,15 +8,15 @@
import testing ;
-# Compile sequence syntax also forcing no varadic macros.
+# Run variadic and sequence syntax (also forcing no variadic macros).
+rule run-vaseq ( file_name )
+{
+ run $(file_name).cpp ;
+ run $(file_name)_seq.cpp ;
+ run $(file_name)_seq.cpp : : : <define>BOOST_NO_VARIADIC_MACROS :
+ $(file_name)_seq_nova : ;
+}
-run try_catch.cpp ;
-run try_catch_seq.cpp ;
-run try_catch_seq.cpp : : : <define>BOOST_NO_VARIADIC_MACROS
- : try_catch_seq_no_variadics : ;
-
-run scope_guard.cpp ;
-run scope_guard_seq.cpp ;
-run scope_guard_seq.cpp : : : <define>BOOST_NO_VARIADIC_MACROS
- : scope_guard_seq_no_variadics : ;
+run-vaseq try_catch ;
+run-vaseq scope_guard ;
Modified: trunk/libs/scope_exit/example/try_catch.cpp
==============================================================================
--- trunk/libs/scope_exit/example/try_catch.cpp (original)
+++ trunk/libs/scope_exit/example/try_catch.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -13,13 +13,13 @@
#include <iostream>
struct file {
- file() : open_(false) {}
+ file(void) : open_(false) {}
file(char const* path) : open_(false) { open(path); }
void open(char const* path) { open_ = true; }
void close(void) { open_ = false; }
-
bool is_open(void) const { return open_; }
+
private:
bool open_;
};
Modified: trunk/libs/scope_exit/example/try_catch_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/example/try_catch_seq.cpp (original)
+++ trunk/libs/scope_exit/example/try_catch_seq.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -10,13 +10,13 @@
#include <iostream>
struct file {
- file() : open_(false) {}
+ file(void) : open_(false) {}
file(char const* path) : open_(false) { open(path); }
void open(char const* path) { open_ = true; }
void close(void) { open_ = false; }
-
bool is_open(void) const { return open_; }
+
private:
bool open_;
};
Modified: trunk/libs/scope_exit/test/Jamfile.v2
==============================================================================
--- trunk/libs/scope_exit/test/Jamfile.v2 (original)
+++ trunk/libs/scope_exit/test/Jamfile.v2 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -15,35 +15,23 @@
<link>static
;
-# Compile sequence syntax also forcing no variadic macros.
+# Run variadic and sequence syntax (also forcing no variadic macros).
+rule run-vaseq ( file_name )
+{
+ run $(file_name).cpp ;
+ run $(file_name)_seq.cpp ;
+ run $(file_name)_seq.cpp : : : <define>BOOST_NO_VARIADIC_MACROS :
+ $(file_name)_seq_nova : ;
+}
+
test-suite world_tests
- : [ run world.cpp ]
- [ run world_seq.cpp ]
- [ run world_seq.cpp : : : <define>BOOST_NO_VARIADIC_MACROS
- : world_seq_no_variadics ]
-
- [ run world_void.cpp ]
-
- [ run world_this.cpp ]
- [ run world_this_seq.cpp ]
- [ run world_this_seq.cpp : : : <define>BOOST_NO_VARIADIC_MACROS
- : world_this_seq_no_variadics ]
-
- [ run world_tpl.cpp ]
- [ run world_tpl_seq.cpp ]
- [ run world_tpl_seq.cpp : : : <define>BOOST_NO_VARIADIC_MACROS
- : world_tpl_seq_no_variadics ]
-
- [ run world_checkpoint.cpp ]
- [ run world_checkpoint_seq.cpp ]
- [ run world_checkpoint_seq.cpp : : : <define>BOOST_NO_VARIADIC_MACROS
- : world_checkpoint_seq_no_variadics ]
-
- [ run world_checkpoint_all.cpp ]
- # SCOPE_EXIT_ALL requires C++11 so do not compile forcing no variadics.
- [ run world_checkpoint_all_seq.cpp ]
-
+ : [ run-vaseq world ]
+ [ run-vaseq world_checkpoint ]
+ [ run-vaseq world_checkpoint_all ]
[ run world_lambda.cpp ]
+ [ run-vaseq world_this ]
+ [ run-vaseq world_tpl ]
+ [ run world_void.cpp ]
;
test-suite native_tests
Modified: trunk/libs/scope_exit/test/world.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world.cpp (original)
+++ trunk/libs/scope_exit/test/world.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -45,11 +45,11 @@
}
//]
-BOOST_AUTO_TEST_CASE( test_world ) {
+BOOST_AUTO_TEST_CASE(test_world) {
world w;
person p;
w.add_person(p);
- BOOST_CHECK( w.population() == 1 );
+ BOOST_CHECK(w.population() == 1);
}
#else
Modified: trunk/libs/scope_exit/test/world_checkpoint.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_checkpoint.cpp (original)
+++ trunk/libs/scope_exit/test/world_checkpoint.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -84,17 +84,17 @@
}
//]
-BOOST_AUTO_TEST_CASE( test_world_checkpoint ) {
+BOOST_AUTO_TEST_CASE(test_world_checkpoint) {
person adam, eva;
std::ostringstream oss;
oss << adam;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "person(0, 0)" );
+ BOOST_CHECK(oss.str() == "person(0, 0)");
oss.str("");
oss << eva;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "person(0, 0)" );
+ BOOST_CHECK(oss.str() == "person(0, 0)");
world w;
w.add_person(adam);
@@ -102,7 +102,7 @@
oss.str("");
oss << w;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "world(3, { person(1, 2), person(2, 2), })" );
+ BOOST_CHECK(oss.str() == "world(3, { person(1, 2), person(2, 2), })");
}
#else
Modified: trunk/libs/scope_exit/test/world_checkpoint_all.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_checkpoint_all.cpp (original)
+++ trunk/libs/scope_exit/test/world_checkpoint_all.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -84,17 +84,17 @@
}
//]
-BOOST_AUTO_TEST_CASE( test_world_checkpoint_all ) {
+BOOST_AUTO_TEST_CASE(test_world_checkpoint_all) {
person adam, eva;
std::ostringstream oss;
oss << adam;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "person(0, 0)" );
+ BOOST_CHECK(oss.str() == "person(0, 0)");
oss.str("");
oss << eva;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "person(0, 0)" );
+ BOOST_CHECK(oss.str() == "person(0, 0)");
world w;
w.add_person(adam);
@@ -102,7 +102,7 @@
oss.str("");
oss << w;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "world(3, { person(1, 2), person(2, 2), })" );
+ BOOST_CHECK(oss.str() == "world(3, { person(1, 2), person(2, 2), })");
}
#else
Modified: trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp (original)
+++ trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -23,7 +23,7 @@
struct person {
typedef unsigned int id_t;
typedef unsigned int evolution_t;
-
+
id_t id;
evolution_t evolution;
@@ -53,7 +53,6 @@
};
BOOST_TYPEOF_REGISTER_TYPE(world)
-//[world_checkpoint_all_seq
void world::add_person(person const& a_person) {
persons_.push_back(a_person);
@@ -76,25 +75,24 @@
this->next_id_ = p.id;
p.id = prev_id;
}
- };
+ }; // Use `;` instead of `SCOPE_EXIT_END` (C++11).
// ...
checkpoint = ++p.evolution;
}
-//]
-BOOST_AUTO_TEST_CASE( test_world_checkpoint_all_seq ) {
+BOOST_AUTO_TEST_CASE(test_world_checkpoint_all_seq) {
person adam, eva;
std::ostringstream oss;
oss << adam;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "person(0, 0)" );
+ BOOST_CHECK(oss.str() == "person(0, 0)");
oss.str("");
oss << eva;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "person(0, 0)" );
+ BOOST_CHECK(oss.str() == "person(0, 0)");
world w;
w.add_person(adam);
@@ -102,12 +100,12 @@
oss.str("");
oss << w;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "world(3, { person(1, 2), person(2, 2), })" );
+ BOOST_CHECK(oss.str() == "world(3, { person(1, 2), person(2, 2), })");
}
-#else // No lambdas (trivial test).
+#else
-int main(void) { return 0; }
+int main(void) { return 0; } // Trivial test.
#endif
Modified: trunk/libs/scope_exit/test/world_checkpoint_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_checkpoint_seq.cpp (original)
+++ trunk/libs/scope_exit/test/world_checkpoint_seq.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -20,7 +20,7 @@
struct person {
typedef unsigned int id_t;
typedef unsigned int evolution_t;
-
+
id_t id;
evolution_t evolution;
@@ -34,7 +34,6 @@
struct world {
world(void) : next_id_(1) {}
-
void add_person(person const& a_person);
friend std::ostream& operator<<(std::ostream& o, world const& w) {
@@ -51,14 +50,13 @@
};
BOOST_TYPEOF_REGISTER_TYPE(world)
-//[world_checkpoint_seq
void world::add_person(person const& a_person) {
persons_.push_back(a_person);
// This block must be no-throw.
person& p = persons_.back();
person::evolution_t checkpoint = p.evolution;
- BOOST_SCOPE_EXIT( (checkpoint) (&p) (&persons_) ) { // Sequence, not commas.
+ BOOST_SCOPE_EXIT( (checkpoint) (&p) (&persons_) ) {
if(checkpoint == p.evolution) persons_.pop_back();
} BOOST_SCOPE_EXIT_END
@@ -80,19 +78,18 @@
checkpoint = ++p.evolution;
}
-//]
-BOOST_AUTO_TEST_CASE( test_world_checkpoint_seq ) {
+BOOST_AUTO_TEST_CASE(test_world_checkpoint_seq) {
person adam, eva;
std::ostringstream oss;
oss << adam;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "person(0, 0)" );
+ BOOST_CHECK(oss.str() == "person(0, 0)");
oss.str("");
oss << eva;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "person(0, 0)" );
+ BOOST_CHECK(oss.str() == "person(0, 0)");
world w;
w.add_person(adam);
@@ -100,6 +97,6 @@
oss.str("");
oss << w;
std::cout << oss.str() << std::endl;
- BOOST_CHECK( oss.str() == "world(3, { person(1, 2), person(2, 2), })" );
+ BOOST_CHECK(oss.str() == "world(3, { person(1, 2), person(2, 2), })");
}
Modified: trunk/libs/scope_exit/test/world_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_seq.cpp (original)
+++ trunk/libs/scope_exit/test/world_seq.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -30,21 +30,22 @@
void world::add_person(person const& a_person) {
bool commit = false;
- persons_.push_back(a_person);
+ persons_.push_back(a_person); // (1) direct action
+ // Following block is executed when the enclosing scope exits.
BOOST_SCOPE_EXIT( (&commit) (&persons_) ) {
- if(!commit) persons_.pop_back();
+ if(!commit) persons_.pop_back(); // (2) rollback action
} BOOST_SCOPE_EXIT_END
- // ...
+ // ... // (3) other operations
- commit = true;
+ commit = true; // (4) disable rollback actions
}
//]
-BOOST_AUTO_TEST_CASE( test_world_seq ) {
+BOOST_AUTO_TEST_CASE(test_world_seq) {
world w;
person p;
w.add_person(p);
- BOOST_CHECK( w.population() == 1 );
+ BOOST_CHECK(w.population() == 1);
}
Modified: trunk/libs/scope_exit/test/world_this.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_this.cpp (original)
+++ trunk/libs/scope_exit/test/world_this.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -53,11 +53,11 @@
commit = true;
}
-BOOST_AUTO_TEST_CASE( test_world_this ) {
+BOOST_AUTO_TEST_CASE(test_world_this) {
world w;
person p;
w.add_person(p);
- BOOST_CHECK( w.population() == 1 );
+ BOOST_CHECK(w.population() == 1);
}
#else
Modified: trunk/libs/scope_exit/test/world_this_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_this_seq.cpp (original)
+++ trunk/libs/scope_exit/test/world_this_seq.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -32,17 +32,13 @@
persons_.push_back(a_person);
#ifdef BOOST_NO_LAMBDAS
- //[world_this_
- BOOST_SCOPE_EXIT( (&commit) (this_) ) { // Capture object `this_`.
+ BOOST_SCOPE_EXIT( (&commit) (this_) ) {
if(!commit) this_->persons_.pop_back();
} BOOST_SCOPE_EXIT_END
- //]
#else
- //[world_this
- BOOST_SCOPE_EXIT( (&commit) (this) ) { // Use `this` (C++11).
+ BOOST_SCOPE_EXIT( (&commit) (this) ) {
if(!commit) this->persons_.pop_back();
- }; // Use `;` instead of `BOOST_SCOPE_EXIT_END` (C++11).
- //]
+ };
#endif
// ...
@@ -50,10 +46,10 @@
commit = true;
}
-BOOST_AUTO_TEST_CASE( test_world_this_seq ) {
+BOOST_AUTO_TEST_CASE(test_world_this_seq) {
world w;
person p;
w.add_person(p);
- BOOST_CHECK( w.population() == 1 );
+ BOOST_CHECK(w.population() == 1);
}
Modified: trunk/libs/scope_exit/test/world_tpl.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_tpl.cpp (original)
+++ trunk/libs/scope_exit/test/world_tpl.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -46,11 +46,11 @@
}
//]
-BOOST_AUTO_TEST_CASE( test_world_tpl ) {
+BOOST_AUTO_TEST_CASE(test_world_tpl) {
world<person> w;
person p;
w.add_person(p);
- BOOST_CHECK( w.population() == 1 );
+ BOOST_CHECK(w.population() == 1);
}
#else
Modified: trunk/libs/scope_exit/test/world_tpl_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_tpl_seq.cpp (original)
+++ trunk/libs/scope_exit/test/world_tpl_seq.cpp 2012-02-20 16:47:47 EST (Mon, 20 Feb 2012)
@@ -15,7 +15,7 @@
#include <vector>
struct person {};
-BOOST_TYPEOF_REGISTER_TYPE(person)
+BOOST_TYPEOF_REGISTER_TYPE(peron)
template<typename Person>
struct world {
@@ -27,7 +27,6 @@
};
BOOST_TYPEOF_REGISTER_TEMPLATE(world, 1)
-//[world_tpl_seq
template<typename Person>
void world<Person>::add_person(Person const& a_person) {
bool commit = false;
@@ -41,12 +40,11 @@
commit = true;
}
-//]
-BOOST_AUTO_TEST_CASE( test_world_tpl_seq ) {
+BOOST_AUTO_TEST_CASE(test_world_tpl_seq) {
world<person> w;
person p;
w.add_person(p);
- BOOST_CHECK( w.population() == 1 );
+ BOOST_CHECK(w.population() == 1);
}
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