[error_state] add a sneaky little stream operator to simplify combining error_states

This commit is contained in:
Joe Thornber 2015-04-08 13:58:41 +01:00
parent 0fee897fda
commit a934ee69c4
3 changed files with 37 additions and 0 deletions

View File

@ -11,6 +11,11 @@ namespace base {
}; };
error_state combine_errors(error_state lhs, error_state rhs); error_state combine_errors(error_state lhs, error_state rhs);
inline error_state &operator <<(error_state &err, error_state rhs) {
err = combine_errors(err, rhs);
return err;
}
} }
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -57,6 +57,7 @@ TEST_SOURCE=\
unit-tests/cache_superblock_t.cc \ unit-tests/cache_superblock_t.cc \
unit-tests/damage_tracker_t.cc \ unit-tests/damage_tracker_t.cc \
unit-tests/endian_t.cc \ unit-tests/endian_t.cc \
unit-tests/error_state_t.cc \
unit-tests/rmap_visitor_t.cc \ unit-tests/rmap_visitor_t.cc \
unit-tests/run_set_t.cc \ unit-tests/run_set_t.cc \
unit-tests/space_map_t.cc \ unit-tests/space_map_t.cc \

View File

@ -0,0 +1,31 @@
#include "gmock/gmock.h"
#include "base/error_state.h"
using namespace base;
using namespace std;
using namespace testing;
//----------------------------------------------------------------
TEST(ErrorStateTests, stream_operator)
{
{
error_state err = NO_ERROR;
err << NO_ERROR << FATAL;
ASSERT_THAT(err, Eq(FATAL));
}
{
error_state err = NO_ERROR;
err << NO_ERROR << NON_FATAL;
ASSERT_THAT(err, Eq(NON_FATAL));
}
{
error_state err = NO_ERROR;
err << NO_ERROR << FATAL << NO_ERROR << NON_FATAL;
ASSERT_THAT(err, Eq(FATAL));
}
}
//----------------------------------------------------------------