libtenum
test/test_static_enum.cpp
Go to the documentation of this file.
00001 
00008 #define TENUM_USE_SHORTCUTS 1
00009 #include "tenum.hpp"
00010 
00011 #define BOOST_TEST_MODULE tenum_static_enum_tests
00012 #include <boost/test/unit_test.hpp>
00013 
00014 lte_enum(static_enum,
00015     lte_ev(value1,2)
00016     lte_e(value2)
00017     lte_en(value3,"value_number_3"),
00018     ::boost::uint8_t
00019 )
00020 
00021 BOOST_AUTO_TEST_SUITE(static_enum_tests)
00024 
00030 BOOST_AUTO_TEST_CASE(test_static_enum_from_enum_serialization) {
00031   static_enum_t enum_value = static_cast< static_enum_t > (static_enum::value1);
00032   ::std::string string_value;
00033   ::std::stringstream stream;
00034   stream << enum_value;
00035   stream >> string_value;
00036   BOOST_CHECK_EQUAL(string_value,"value1");
00037 }
00038 
00044 BOOST_AUTO_TEST_CASE(test_static_enum_from_int_explicit_serialization) {
00045   static_enum_t enum_value = static_cast< static_enum_t > (4);
00046   ::std::string string_value;
00047   ::std::stringstream stream;
00048   stream << enum_value;
00049   stream >> string_value;
00050   BOOST_CHECK_EQUAL(string_value,"value_number_3");
00051 }
00052 
00058 BOOST_AUTO_TEST_CASE(test_static_enum_deserialization) {
00059   static_enum_t enum_value;
00060   ::std::string string_value = "value2";
00061   ::std::stringstream stream;
00062   stream << string_value;
00063   stream >> enum_value;
00064   BOOST_CHECK_EQUAL(enum_value,static_cast< static_enum_t > (static_enum::value2));
00065   BOOST_CHECK_EQUAL(enum_value,static_cast< static_enum_t > (3));
00066 }
00067 
00073 BOOST_AUTO_TEST_CASE(test_static_enum_unknown_serialization) {
00074   static_enum_t enum_value = static_cast< static_enum_t > (static_enum::lte_unknown);
00075   ::std::string string_value;
00076   ::std::stringstream stream;
00077   stream << enum_value;
00078   stream >> string_value;
00079   BOOST_CHECK_EQUAL(string_value,"lte_unknown");
00080 }
00081 
00087 BOOST_AUTO_TEST_CASE(test_static_enum_unknown_integer_serialization) {
00088   static_enum_t enum_value = static_cast< static_enum_t > (-1);
00089   ::std::string string_value;
00090   ::std::stringstream stream;
00091   stream << enum_value;
00092   stream >> string_value;
00093   BOOST_CHECK_EQUAL(string_value,"lte_unknown");
00094 }
00095 
00101 BOOST_AUTO_TEST_CASE(test_static_enum_empty_deserialization) {
00102   static_enum_t enum_value;
00103   ::std::string string_value = "";
00104   ::std::stringstream stream;
00105   stream << string_value;
00106   stream >> enum_value;
00107   BOOST_CHECK_EQUAL(enum_value,static_cast< static_enum_t > (static_enum::lte_unknown));
00108 }
00109 
00115 BOOST_AUTO_TEST_CASE(test_static_enum_unknown_deserialization) {
00116   static_enum_t enum_value;
00117   ::std::string string_value = "foobar";
00118   ::std::stringstream stream;
00119   stream << string_value;
00120   stream >> enum_value;
00121   BOOST_CHECK_EQUAL(enum_value,static_cast< static_enum_t > (static_enum::lte_unknown));
00122 }
00123 
00129 BOOST_AUTO_TEST_CASE(test_static_enum_integers_eq) {
00130   static_enum_t enum_value = static_enum::value3;
00131   ::boost::uint64_t integer_value = 4;
00132   BOOST_CHECK(integer_value == enum_value);
00133   BOOST_CHECK(enum_value == integer_value);
00134 }
00135 
00141 BOOST_AUTO_TEST_CASE(test_static_enum_integers_neq) {
00142   static_enum_t enum_value = static_enum::value3;
00143   ::boost::uint64_t integer_value = 0;
00144   BOOST_CHECK(integer_value != enum_value);
00145   BOOST_CHECK(enum_value != integer_value);
00146 }
00147 
00153 BOOST_AUTO_TEST_CASE(test_static_enum_integers_bitwise_and) {
00154   static_enum_t enum_value = static_enum::value3;
00155   ::boost::uint64_t integer_value1 = 0b101 & enum_value;
00156   BOOST_CHECK(integer_value1 == 0b100);
00157   ::boost::uint64_t integer_value2 = enum_value & 0b101;
00158   BOOST_CHECK(integer_value2 == 0b100);
00159 }
00160 
00166 BOOST_AUTO_TEST_CASE(test_static_enum_integers_bitwise_or) {
00167   static_enum_t enum_value = static_enum::value3;
00168   ::boost::uint64_t integer_value1 = 0b001 | enum_value;
00169   BOOST_CHECK(integer_value1 == 0b101);
00170   ::boost::uint64_t integer_value2 = enum_value | 0b001;
00171   BOOST_CHECK(integer_value2 == 0b101);
00172 }
00173 
00179 BOOST_AUTO_TEST_CASE(test_static_enum_integers_bitwise_xor) {
00180   static_enum_t enum_value = static_enum::value3;
00181   ::boost::uint64_t integer_value1 = 0b101 ^ enum_value;
00182   BOOST_CHECK(integer_value1 == 0b001);
00183   ::boost::uint64_t integer_value2 = enum_value ^ 0b101;
00184   BOOST_CHECK(integer_value2 == 0b001);
00185 }
00186 
00192 BOOST_AUTO_TEST_CASE(test_static_enum_integers_bitwise_and_assign) {
00193   static_enum_t enum_value = static_enum::value3;
00194   ::boost::uint64_t integer_value = 0b101;
00195   integer_value &= enum_value;
00196   BOOST_CHECK(integer_value == 0b100);
00197 }
00198 
00204 BOOST_AUTO_TEST_CASE(test_static_enum_integers_bitwise_or_assign) {
00205   static_enum_t enum_value = static_enum::value3;
00206   ::boost::uint64_t integer_value = 0b001;
00207   integer_value |= enum_value;
00208   BOOST_CHECK(integer_value == 0b101);
00209 }
00210 
00216 BOOST_AUTO_TEST_CASE(test_static_enum_integers_bitwise_xor_assign) {
00217   static_enum_t enum_value = static_enum::value3;
00218   ::boost::uint64_t integer_value = 0b101;
00219   integer_value ^= enum_value;
00220   BOOST_CHECK(integer_value == 0b001);
00221 }
00222 
00223 BOOST_AUTO_TEST_SUITE_END()
 All Classes Namespaces Files Functions Defines