restore << operator for mapnik::enumeration + add unit test
This commit is contained in:
parent
6c1b6e301d
commit
8ecb42894f
2 changed files with 46 additions and 0 deletions
|
@ -246,6 +246,16 @@ private:
|
|||
static bool our_verified_flag_;
|
||||
};
|
||||
|
||||
/** ostream operator for enumeration
|
||||
* @relates mapnik::enumeration
|
||||
*/
|
||||
template <class ENUM, int THE_MAX>
|
||||
std::ostream &
|
||||
operator<<(std::ostream & os, const mapnik::enumeration<ENUM, THE_MAX> & e)
|
||||
{
|
||||
return os << e.as_string();
|
||||
}
|
||||
|
||||
} // end of namespace
|
||||
|
||||
/** Helper macro.
|
||||
|
|
36
test/unit/numerics/enumeration.cpp
Normal file
36
test/unit/numerics/enumeration.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include "catch.hpp"
|
||||
#include <mapnik/enumeration.hpp>
|
||||
#include <sstream>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
enum _test_enumeration_enum : std::uint8_t
|
||||
{
|
||||
TEST_ONE,
|
||||
TEST_TWO,
|
||||
_test_enumeration_enum_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM( _test_enumeration_e, _test_enumeration_enum );
|
||||
|
||||
static const char * _test_enumeration_strings[] = {
|
||||
"test_one",
|
||||
"test_two",
|
||||
""
|
||||
};
|
||||
|
||||
IMPLEMENT_ENUM( _test_enumeration_e, _test_enumeration_strings )
|
||||
|
||||
}
|
||||
|
||||
TEST_CASE("enumeration") {
|
||||
|
||||
mapnik::_test_enumeration_e e(mapnik::TEST_ONE);
|
||||
CHECK( e.as_string() == "test_one" );
|
||||
// test the << operator, which calls `as_string` internally
|
||||
// this is not used in mapnik, but kept for back compat
|
||||
std::stringstream s;
|
||||
s << e;
|
||||
CHECK( s.str() == "test_one" );
|
||||
|
||||
}
|
Loading…
Reference in a new issue