14 #include <gtest/gtest.h> 15 #include "../../include/ecl/containers/array.hpp" 16 #include "../../include/ecl/containers/converters.hpp" 17 #include "../../include/ecl/containers/stencil.hpp" 36 template <
typename Container>
37 void print(
const Container &byte_array) {
39 std::cout << byte_array << std::endl;
64 TEST(ConverterTests,fromArray) {
66 byte_array << 0x01, 0x02, 0x03;
68 if(
debug_output ) { std::cout <<
"Conversion: " << toInt(byte_array) << std::endl; }
69 EXPECT_EQ(197121,toInt(byte_array));
71 unsigned_byte_array << 0x01, 0x02, 0x03;
73 if(
debug_output ) { std::cout <<
"Conversion: " << utoInt(unsigned_byte_array) << std::endl; }
74 EXPECT_EQ(197121,utoInt(unsigned_byte_array));
76 signed_byte_array << 0x01, 0x02, 0x03;
78 if(
debug_output ) { std::cout <<
"Conversion: " << stoInt(signed_byte_array) << std::endl; }
79 EXPECT_EQ(197121,stoInt(signed_byte_array));
82 TEST(ConverterTests,toArray) {
84 ecl::int32 i = 197121;
91 toByteArray(byte_array, i);
92 toSignedByteArray(signed_byte_array,i);
93 toUnsignedByteArray(unsigned_byte_array, i);
95 print(signed_byte_array);
96 print(unsigned_byte_array);
97 EXPECT_EQ(1,byte_array[0]);
98 EXPECT_EQ(2,byte_array[1]);
99 EXPECT_EQ(3,byte_array[2]);
100 EXPECT_EQ(1,signed_byte_array[0]);
101 EXPECT_EQ(2,signed_byte_array[1]);
102 EXPECT_EQ(3,signed_byte_array[2]);
103 EXPECT_EQ(1,unsigned_byte_array[0]);
104 EXPECT_EQ(2,unsigned_byte_array[1]);
105 EXPECT_EQ(3,unsigned_byte_array[2]);
108 TEST(ConverterTests,fromStencil) {
112 byte_array << 0x01, 0x02, 0x03;
113 signed_byte_array << 0x01, 0x02, 0x03;
114 unsigned_byte_array << 0x01, 0x02, 0x03;
118 int i = toInt(byte_array.stencil(0,2));
119 int si = stoInt(signed_byte_array.
stencil(0,2));
120 int ui = utoInt(unsigned_byte_array.
stencil(0,2));
121 if(
debug_output ) { std::cout <<
"Conversion: " << std::dec << i << std::endl; }
122 if(
debug_output ) { std::cout <<
"Conversion: " << std::dec << si << std::endl; }
123 if(
debug_output ) { std::cout <<
"Conversion: " << std::dec << ui << std::endl; }
128 TEST(ConverterTests,toStencil) {
132 stencil = fromInt(stencil, 197121);
135 EXPECT_EQ(1,stencil[0]);
136 EXPECT_EQ(2,stencil[1]);
137 EXPECT_EQ(3,stencil[2]);
143 int main(
int argc,
char **argv) {
144 testing::InitGoogleTest(&argc,argv);
145 return RUN_ALL_TESTS();
Fixed size container with a few bells and whistles.
void print(const Container &byte_array)
Array< unsigned char > DynamicUnsignedByteArray
std::vector< unsigned char > ByteArray
Array< signed char > DynamicSignedByteArray
Stencil< Array< char, 3 > > ByteStencil
Stencil< Array< Type, Size > > stencil(const unsigned int &start_index, const unsigned int &n) ecl_assert_throw_decl(StandardException)
Open a window (stencil) onto the array.
Array< signed char, 3 > SignedByteArray
Stencil< Array< signed char > > DynamicSignedByteStencil
Array< char, 3 > ByteArray
Stencil< Array< unsigned char, 3 > > UnsignedByteStencil
A safe windowing class that opens onto array-like containers.
TEST(ConverterTests, fromArray)
int main(int argc, char **argv)
Array< unsigned char, 3 > UnsignedByteArray
Stencil< Array< signed char, 3 > > SignedByteStencil
Stencil< Array< unsigned char > > DynamicUnsignedByteStencil
Stencil< Array< char > > DynamicByteStencil
Array< char > DynamicByteArray