15 #include <gtest/gtest.h> 17 #include "../../include/ecl/converters/to_byte_array.hpp" 18 #include "../../include/ecl/converters/from_byte_array.hpp" 40 for (
unsigned int i = 0; i < byte_array.size(); ++i ) {
41 std::cout <<
"0x" << std::hex << static_cast<unsigned int>(byte_array[i]) <<
" ";
43 std::cout << std::endl;
47 void print(
const std::vector<char> &byte_array) {
49 for (
unsigned int i = 0; i < byte_array.size(); ++i ) {
50 std::cout <<
"0x" << std::hex << static_cast<unsigned int>(byte_array[i]) <<
" ";
52 std::cout << std::endl;
61 byte_array.push_back(0x01);
62 byte_array.push_back(0x02);
63 byte_array.push_back(0x03);
66 EXPECT_EQ(197121,converter(byte_array));
72 toByteArray(byte_array, 363);
74 EXPECT_EQ(107,byte_array[0]);
75 toByteArray(byte_array,-2);
77 EXPECT_EQ(254,byte_array[0]);
79 int i = fromByteArray(byte_array);
81 std::cout << std::dec <<
"i: " << i << std::endl;
84 toByteArray(byte_array, 258);
86 i = fromByteArray(byte_array);
88 std::cout << std::dec <<
"i: " << i << std::endl;
92 #if defined(NDEBUG) || defined(ECL_NDEBUG) 93 std::cout <<
"Skipping toByteArrayFailedSize test, it only throws in debug mode" << std::endl;
100 byte_array = toByteArray(byte_array, i);
102 if (
debug_output ) { std::cout <<
"Caught an exception from improper size of reserved memory." << std::endl; }
115 std::vector<char> bytes = toCharByteArray(
"0x32 0x54");
119 EXPECT_EQ(50,bytes[0]);
120 EXPECT_EQ(84,bytes[1]);
121 std::vector<char> bytes_258(4,0x00);
122 toCharByteArray(bytes_258, ecl::int32(258));
125 ecl::int32 i = fromCharByteArray(bytes_258);
127 std::cout << std::dec <<
"i: " << i << std::endl;
132 std::string str(
"dude");
133 ecl::converters::FromByteArray<ecl::int32,std::string> from_byte_array;
134 int i = from_byte_array(str);
136 std::cout <<
"i: " << i << std::endl;
139 EXPECT_EQ(1701082468,i);
146 int main(
int argc,
char **argv) {
148 testing::InitGoogleTest(&argc,argv);
149 return RUN_ALL_TESTS();
virtual ErrorFlag flag() const
TEST(Converter, fromByteArray)
std::vector< unsigned char > ByteArray
Primary template and general fallback for converter classes.
void print(const ByteArray &byte_array)
int main(int argc, char **argv)