MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 #include "TestUtil.hpp" 00002 #include "VarLenTag.hpp" 00003 00004 using namespace moab; 00005 00006 #include <iostream> 00007 00008 void test_valid_struct(); 00009 void test_inline(); 00010 void test_non_inline(); 00011 void test_resize_ii(); 00012 void test_resize_in(); 00013 void test_resize_ni(); 00014 void test_resize_nn(); 00015 00016 int main() 00017 { 00018 int count = 0; 00019 count += RUN_TEST( test_valid_struct ); 00020 if( count ) 00021 { 00022 std::cerr << "ABORTING VarLenTag TEST" << std::endl << "Structure is not valid" << std::endl; 00023 return count; 00024 } 00025 00026 count += RUN_TEST( test_inline ); 00027 count += RUN_TEST( test_non_inline ); 00028 count += RUN_TEST( test_resize_ii ); 00029 count += RUN_TEST( test_resize_in ); 00030 count += RUN_TEST( test_resize_ni ); 00031 count += RUN_TEST( test_resize_nn ); 00032 00033 return count; 00034 } 00035 00036 #define OFFSET( A ) ( (char*)( &( A ) ) - (char*)this ) 00037 class GetOffsets : public VarLenTag 00038 { 00039 public: 00040 unsigned pointer_array_offset() 00041 { 00042 return OFFSET( mData.mData.mPointer.array ); 00043 } 00044 unsigned pointer_size_offset() 00045 { 00046 return OFFSET( mData.mData.mPointer.size ); 00047 } 00048 #ifdef VAR_LEN_TAG_ELIDE_DATA 00049 unsigned inline_array_offset() 00050 { 00051 return OFFSET( mData.mData.mInline.array ); 00052 } 00053 unsigned inline_size_offset() 00054 { 00055 return OFFSET( mData.mData.mInline.size ); 00056 } 00057 #endif 00058 }; 00059 struct ExpectedSize 00060 { 00061 unsigned char* pointer; 00062 unsigned size; 00063 }; 00064 00065 void test_valid_struct() 00066 { 00067 GetOffsets off; 00068 CHECK_EQUAL( 0u, off.pointer_array_offset() ); 00069 #ifdef VAR_LEN_TAG_ELIDE_DATA 00070 CHECK_EQUAL( 0u, off.inline_array_offset() ); 00071 CHECK_EQUAL( off.pointer_size_offset(), off.inline_size_offset() ); 00072 #endif 00073 CHECK_EQUAL( sizeof( ExpectedSize ), sizeof( VarLenTag ) ); 00074 } 00075 00076 void test_inline() 00077 { 00078 VarLenTag tag( sizeof( void* ) ); 00079 CHECK_EQUAL( (unsigned char*)&tag, tag.data() ); 00080 } 00081 00082 void test_non_inline() 00083 { 00084 VarLenTag tag( 2 * sizeof( void* ) ); 00085 CHECK( (unsigned char*)&tag != tag.data() ); 00086 } 00087 00088 void test_resize_ii() 00089 { 00090 VarLenTag tag( 1 ); 00091 tag.data()[0] = 'X'; 00092 unsigned char* ptr = tag.resize( 3 ); 00093 CHECK_EQUAL( tag.data(), ptr ); 00094 CHECK_EQUAL( (unsigned char*)&tag, tag.data() ); 00095 CHECK_EQUAL( tag.data()[0], 'X' ); 00096 } 00097 00098 void test_resize_in() 00099 { 00100 VarLenTag tag( sizeof( void* ) ); 00101 memcpy( tag.data(), "ABCDEFGHIJKLMNOPQRST", sizeof( void* ) ); 00102 unsigned char* ptr = tag.resize( 2 * sizeof( void* ) ); 00103 CHECK_EQUAL( tag.data(), ptr ); 00104 CHECK( (unsigned char*)&tag != tag.data() ); 00105 CHECK( !memcmp( tag.data(), "ABCDEFGHIJKLMNOPQRST", sizeof( void* ) ) ); 00106 } 00107 00108 void test_resize_ni() 00109 { 00110 VarLenTag tag( 2 * sizeof( void* ) ); 00111 memcpy( tag.data(), "12345678901234567890", sizeof( void* ) ); 00112 unsigned char* ptr = tag.resize( sizeof( void* ) ); 00113 CHECK_EQUAL( tag.data(), ptr ); 00114 CHECK_EQUAL( (unsigned char*)&tag, tag.data() ); 00115 CHECK( !memcmp( tag.data(), "12345678901234567890", sizeof( void* ) ) ); 00116 } 00117 00118 void test_resize_nn() 00119 { 00120 VarLenTag tag( 2 * sizeof( void* ) ); 00121 memcpy( tag.data(), "TSRQPONMLKJIHGFEDCBA", 2 * sizeof( void* ) ); 00122 unsigned char* ptr = tag.resize( 4 * sizeof( void* ) ); 00123 CHECK_EQUAL( tag.data(), ptr ); 00124 CHECK( (unsigned char*)&tag != tag.data() ); 00125 CHECK( !memcmp( tag.data(), "TSRQPONMLKJIHGFEDCBA", sizeof( void* ) ) ); 00126 }