libtenum
|
00001 00008 #define TENUM_USE_SHORTCUTS 1 00009 #include "tenum.hpp" 00010 00011 #define BOOST_TEST_MODULE tenum_dynamic_enum_tests 00012 #include <boost/test/unit_test.hpp> 00013 00014 lte_dynamic_enum(dynamic_enum, 00015 lte_ev(value1,2) 00016 lte_evn(value2,5,"test_value2") 00017 lte_e(value3), 00018 value3+10, 00019 ::boost::uint16_t 00020 ) 00021 00022 BOOST_AUTO_TEST_SUITE(dynamic_enum_tests) 00025 00031 BOOST_AUTO_TEST_CASE(test_dynamic_enum_from_offset_serialization) { 00032 dynamic_enum_t enum_value = static_cast< dynamic_enum_t > (dynamic_enum::value2 - 1); 00033 ::std::string string_value; 00034 ::std::stringstream stream; 00035 stream << enum_value; 00036 stream >> string_value; 00037 // (value2 - 1) is 4, which is (value1 + 2) 00038 BOOST_CHECK_EQUAL(string_value,"value1#2"); 00039 } 00040 00046 BOOST_AUTO_TEST_CASE(test_dynamic_enum_serialization_explicit) { 00047 dynamic_enum_t enum_value = static_cast< dynamic_enum_t > (dynamic_enum::value2); 00048 ::std::string string_value; 00049 ::std::stringstream stream; 00050 stream << enum_value; 00051 stream >> string_value; 00052 BOOST_CHECK_EQUAL(string_value,"test_value2"); 00053 } 00054 00060 BOOST_AUTO_TEST_CASE(test_dynamic_enum_from_integer_serialization) { 00061 dynamic_enum_t enum_value = static_cast< dynamic_enum_t > (3); 00062 ::std::string string_value; 00063 ::std::stringstream stream; 00064 stream << enum_value; 00065 stream >> string_value; 00066 BOOST_CHECK_EQUAL(string_value,"value1#1"); 00067 } 00068 00074 BOOST_AUTO_TEST_CASE(test_dynamic_enum_deserialization) { 00075 dynamic_enum_t enum_value; 00076 ::std::string string_value = "value3#4"; 00077 ::std::stringstream stream; 00078 stream << string_value; 00079 stream >> enum_value; 00080 BOOST_CHECK_EQUAL(enum_value,static_cast< dynamic_enum_t > (dynamic_enum::value3 + 4)); 00081 BOOST_CHECK_EQUAL(enum_value,static_cast< dynamic_enum_t > (10)); 00082 } 00083 00089 BOOST_AUTO_TEST_CASE(test_dynamic_enum_unknown_serialization) { 00090 dynamic_enum_t enum_value = static_cast< dynamic_enum_t > (dynamic_enum::lte_unknown); 00091 ::std::string string_value; 00092 ::std::stringstream stream; 00093 stream << enum_value; 00094 stream >> string_value; 00095 BOOST_CHECK_EQUAL(string_value,"lte_unknown"); 00096 } 00097 00103 BOOST_AUTO_TEST_CASE(test_dynamic_enum_out_of_range_serialization) { 00104 dynamic_enum_t enum_value = static_cast< dynamic_enum_t > (0); 00105 ::std::string string_value; 00106 ::std::stringstream stream; 00107 stream << enum_value; 00108 stream >> string_value; 00109 BOOST_CHECK_EQUAL(string_value,"lte_unknown"); 00110 } 00111 00117 BOOST_AUTO_TEST_CASE(test_dynamic_enum_out_of_range_deserialization) { 00118 dynamic_enum_t enum_value; 00119 ::std::string string_value = "value3#123456789"; 00120 ::std::stringstream stream; 00121 stream << string_value; 00122 stream >> enum_value; 00123 BOOST_CHECK_EQUAL(enum_value,static_cast< dynamic_enum_t > (dynamic_enum::lte_unknown)); 00124 BOOST_CHECK_EQUAL(enum_value,static_cast< dynamic_enum_t > (static_cast< int >(dynamic_enum::value3+10))); 00125 } 00126 00132 BOOST_AUTO_TEST_CASE(test_dynamic_enum_empty_deserialization) { 00133 dynamic_enum_t enum_value; 00134 ::std::string string_value = ""; 00135 ::std::stringstream stream; 00136 stream << string_value; 00137 stream >> enum_value; 00138 BOOST_CHECK_EQUAL(enum_value,static_cast< dynamic_enum_t > (dynamic_enum::lte_unknown)); 00139 BOOST_CHECK_EQUAL(enum_value,static_cast< dynamic_enum_t > (static_cast< int >(dynamic_enum::value3+10))); 00140 } 00141 00147 BOOST_AUTO_TEST_CASE(test_dynamic_enum_correct_deserialization) { 00148 dynamic_enum_t enum_value; 00149 ::std::string string_value = "value1#3"; 00150 ::std::stringstream stream; 00151 stream << string_value; 00152 stream >> enum_value; 00153 00154 ::std::stringstream outstream; 00155 outstream << enum_value; 00156 outstream >> string_value; 00157 BOOST_CHECK_EQUAL(string_value,"test_value2"); 00158 } 00159 00165 BOOST_AUTO_TEST_CASE(test_dynamic_enum_integers_eq) { 00166 dynamic_enum_t enum_value = dynamic_enum::value1; 00167 ::boost::uint64_t integer_value = 2; 00168 BOOST_CHECK(integer_value == enum_value); 00169 BOOST_CHECK(enum_value == integer_value); 00170 } 00171 00177 BOOST_AUTO_TEST_CASE(test_dynamic_enum_integers_neq) { 00178 dynamic_enum_t enum_value = dynamic_enum::value1; 00179 ::boost::uint64_t integer_value = 0; 00180 BOOST_CHECK(integer_value != enum_value); 00181 BOOST_CHECK(enum_value != integer_value); 00182 } 00183 00189 BOOST_AUTO_TEST_CASE(test_dynamic_enum_integers_bitwise_and) { 00190 dynamic_enum_t enum_value = dynamic_enum::value1; 00191 ::boost::uint64_t integer_value1 = 0b011 & enum_value; 00192 BOOST_CHECK(integer_value1 == 0b010); 00193 ::boost::uint64_t integer_value2 = enum_value & 0b011; 00194 BOOST_CHECK(integer_value2 == 0b010); 00195 } 00196 00202 BOOST_AUTO_TEST_CASE(test_dynamic_enum_integers_bitwise_or) { 00203 dynamic_enum_t enum_value = dynamic_enum::value1; 00204 ::boost::uint64_t integer_value1 = 0b001 | enum_value; 00205 BOOST_CHECK(integer_value1 == 0b011); 00206 ::boost::uint64_t integer_value2 = enum_value | 0b001; 00207 BOOST_CHECK(integer_value2 == 0b011); 00208 } 00209 00215 BOOST_AUTO_TEST_CASE(test_dynamic_enum_integers_bitwise_xor) { 00216 dynamic_enum_t enum_value = dynamic_enum::value1; 00217 ::boost::uint64_t integer_value1 = 0b011 ^ enum_value; 00218 BOOST_CHECK(integer_value1 == 0b001); 00219 ::boost::uint64_t integer_value2 = enum_value ^ 0b011; 00220 BOOST_CHECK(integer_value2 == 0b001); 00221 } 00222 00228 BOOST_AUTO_TEST_CASE(test_dynamic_enum_integers_bitwise_and_assign) { 00229 dynamic_enum_t enum_value = dynamic_enum::value1; 00230 ::boost::uint64_t integer_value = 0b011; 00231 integer_value &= enum_value; 00232 BOOST_CHECK(integer_value == 0b010); 00233 } 00234 00240 BOOST_AUTO_TEST_CASE(test_dynamic_enum_integers_bitwise_or_assign) { 00241 dynamic_enum_t enum_value = dynamic_enum::value1; 00242 ::boost::uint64_t integer_value = 0b001; 00243 integer_value |= enum_value; 00244 BOOST_CHECK(integer_value == 0b011); 00245 } 00246 00252 BOOST_AUTO_TEST_CASE(test_dynamic_enum_integers_bitwise_xor_assign) { 00253 dynamic_enum_t enum_value = dynamic_enum::value1; 00254 ::boost::uint64_t integer_value = 0b011; 00255 integer_value ^= enum_value; 00256 BOOST_CHECK(integer_value == 0b001); 00257 } 00258 00259 BOOST_AUTO_TEST_SUITE_END()