stencil.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Macros
00010 *****************************************************************************/
00011 
00012 // Make sure we enter debug mode.
00013 #ifdef NDEBUG
00014   #undef NDEBUG
00015 #endif
00016 #ifdef ECL_NDEBUG
00017   #undef ECL_NDEBUG
00018 #endif
00019 
00020 /*****************************************************************************
00021 ** Includes
00022 *****************************************************************************/
00023 
00024 #include <iostream>
00025 #include <gtest/gtest.h>
00026 //#include </ecl/config/ecl.hpp>
00027 #include "../../include/ecl/containers/array.hpp"
00028 #include "../../include/ecl/containers/stencil.hpp"
00029 #include <ecl/concepts/containers.hpp>
00030 
00031 /*****************************************************************************
00032 ** Using
00033 *****************************************************************************/
00034 
00035 using ecl::StandardException;
00036 using ecl::Array;
00037 using ecl::Stencil;
00038 using ecl::UnsignedByteContainerConcept;
00039 
00040 /*****************************************************************************
00041 ** Globals
00042 *****************************************************************************/
00043 
00044 typedef Stencil< Array<int,5> > FixedStencil;
00045 typedef Stencil< Array<int> > DynamicStencil;
00046 
00047 /*****************************************************************************
00048 ** Tests
00049 *****************************************************************************/
00050 
00051 TEST(StencilTests,construction) {
00052 
00053         Array<int,5> array;
00054         Array<int> darray(5);
00055         array << 1,2,3,4,5;
00056         darray << 6,7,8,9,10;
00057 
00058         FixedStencil stencil = array.stencil(1,3); // 2,3.4
00059         DynamicStencil dstencil(darray,darray.begin()+1,darray.begin()+4); // 7,8,9
00060         EXPECT_EQ(2,stencil[0]);
00061         EXPECT_EQ(3,stencil[1]);
00062         EXPECT_EQ(4,stencil[2]);
00063         EXPECT_EQ(7,dstencil[0]);
00064         EXPECT_EQ(8,dstencil[1]);
00065         EXPECT_EQ(9,dstencil[2]);
00066 }
00067 
00068 TEST(StencilTests,badConstruction) {
00069 
00070         Array<int> darray(5);
00071         darray << 6,7,8,9,10;
00072 
00073         bool result = false;
00074     try {
00075         DynamicStencil bad_stencil(darray,darray.begin()+1,darray.begin()+9);
00076     } catch ( StandardException &e ) {
00077         result = true;
00078     }
00079     EXPECT_TRUE(result);
00080 }
00081 
00082 TEST(StencilTests,badIndexing) {
00083 
00084         Array<int> darray(5);
00085         darray << 6,7,8,9,10;
00086 
00087         DynamicStencil dstencil(darray,darray.begin()+1,darray.begin()+4); // 7,8,9
00088         darray.resize(3);
00089         darray << 6,7,8;
00090         bool result = false;
00091     try {
00092         dstencil[2]; // Even something that looks good will generally fail as the memory has moved.
00093         dstencil[4];
00094     } catch ( StandardException &e ) {
00095         result = true;
00096     }
00097     EXPECT_TRUE(result);
00098 }
00099 TEST(StencilTests,modifying) {
00100         Array<int,5> array;
00101         Array<int> darray(5);
00102         array << 1,2,3,4,5;
00103         darray << 6,7,8,9,10;
00104         FixedStencil stencil = array.stencil(1,3); // 2,3.4
00105         stencil.resettle(0,2); // 1,2
00106         EXPECT_EQ(1,stencil[0]);
00107         EXPECT_EQ(2,stencil[1]);
00108         stencil = array.stencil(1,4); // 2,3,4,5
00109         EXPECT_EQ(2,stencil[0]);
00110         EXPECT_EQ(3,stencil[1]);
00111         EXPECT_EQ(4,stencil[2]);
00112         EXPECT_EQ(5,stencil[3]);
00113 }
00114 
00115 TEST(StencilTests,concepts) {
00116 
00117         typedef Array<unsigned char,6> ByteArray;
00118     typedef Stencil<ByteArray> ByteStencil;
00119 
00120     // ecl_compile_time_concept_check(ecl::concepts::ByteContainer<FixedStencil>); // this one fails
00121     ecl_compile_time_concept_check(UnsignedByteContainerConcept<ByteArray>);
00122     ecl_compile_time_concept_check(UnsignedByteContainerConcept<ByteStencil>);
00123     SUCCEED();
00124 }
00125 
00126 TEST(StencilTests,byteStrings) {
00127 
00128         std::string str("dude");
00129     Stencil<std::string> stencil( str, str.begin(), str.end() );
00130         EXPECT_EQ(4,stencil.size());
00131         EXPECT_EQ('d',stencil[0]);
00132         EXPECT_EQ('u',stencil[1]);
00133         EXPECT_EQ('d',stencil[2]);
00134         EXPECT_EQ('e',stencil[3]);
00135 //    for ( unsigned int i = 0; i < stencil.size(); ++i ) {
00136 //      std::cout << i << ": " << stencil[i] << std::endl;
00137 //    }
00138 
00139     SUCCEED();
00140 }
00141 
00142 TEST(StencilTests,unsignedCharArrays) {
00143 
00144     //unsigned char buffer[4] = { 0xff, 0x00, 0x01, 0x02 };
00145     unsigned char buffer[4];
00146     Stencil<unsigned char*> stencil( buffer, 4, buffer, buffer + 4);
00147     stencil << 0xff, 0x00, 0x01, 0x02;
00148     EXPECT_EQ(4,stencil.size());
00149     EXPECT_EQ(255,stencil[0]);
00150     EXPECT_EQ(0,stencil[1]);
00151     EXPECT_EQ(1,stencil[2]);
00152     EXPECT_EQ(2,stencil[3]);
00153 //    std::cout << std::hex;
00154 //    for ( unsigned int i = 0; i < stencil.size(); ++i ) {
00155 //      std::cout << i << ": " << static_cast<int>(stencil[i]) << std::endl;
00156 //    }
00157 //    std::cout << std::dec;
00158 
00159     SUCCEED();
00160 }
00161 
00162 
00163 /*****************************************************************************
00164 ** Main program
00165 *****************************************************************************/
00166 
00167 int main(int argc, char **argv) {
00168         testing::InitGoogleTest(&argc,argv);
00169     return RUN_ALL_TESTS();
00170 }
00171 
00172 


ecl_containers
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:42