[error_state] add a sneaky little stream operator to simplify combining error_states
This commit is contained in:
parent
0fee897fda
commit
a934ee69c4
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
@ -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 \
|
||||||
|
31
unit-tests/error_state_t.cc
Normal file
31
unit-tests/error_state_t.cc
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------
|
Loading…
Reference in New Issue
Block a user