MOAB: Mesh Oriented datABase  (version 5.5.0)
VarLenTagTest.cpp
Go to the documentation of this file.
1 #include "TestUtil.hpp"
2 #include "VarLenTag.hpp"
3 
4 using namespace moab;
5 
6 #include <iostream>
7 
8 void test_valid_struct();
9 void test_inline();
10 void test_non_inline();
11 void test_resize_ii();
12 void test_resize_in();
13 void test_resize_ni();
14 void test_resize_nn();
15 
16 int main()
17 {
18  int count = 0;
19  count += RUN_TEST( test_valid_struct );
20  if( count )
21  {
22  std::cerr << "ABORTING VarLenTag TEST" << std::endl << "Structure is not valid" << std::endl;
23  return count;
24  }
25 
26  count += RUN_TEST( test_inline );
27  count += RUN_TEST( test_non_inline );
28  count += RUN_TEST( test_resize_ii );
29  count += RUN_TEST( test_resize_in );
30  count += RUN_TEST( test_resize_ni );
31  count += RUN_TEST( test_resize_nn );
32 
33  return count;
34 }
35 
36 #define OFFSET( A ) ( (char*)( &( A ) ) - (char*)this )
37 class GetOffsets : public VarLenTag
38 {
39  public:
41  {
42  return OFFSET( mData.mData.mPointer.array );
43  }
45  {
46  return OFFSET( mData.mData.mPointer.size );
47  }
48 #ifdef VAR_LEN_TAG_ELIDE_DATA
49  unsigned inline_array_offset()
50  {
51  return OFFSET( mData.mData.mInline.array );
52  }
53  unsigned inline_size_offset()
54  {
55  return OFFSET( mData.mData.mInline.size );
56  }
57 #endif
58 };
60 {
61  unsigned char* pointer;
62  unsigned size;
63 };
64 
66 {
67  GetOffsets off;
68  CHECK_EQUAL( 0u, off.pointer_array_offset() );
69 #ifdef VAR_LEN_TAG_ELIDE_DATA
70  CHECK_EQUAL( 0u, off.inline_array_offset() );
71  CHECK_EQUAL( off.pointer_size_offset(), off.inline_size_offset() );
72 #endif
73  CHECK_EQUAL( sizeof( ExpectedSize ), sizeof( VarLenTag ) );
74 }
75 
77 {
78  VarLenTag tag( sizeof( void* ) );
79  CHECK_EQUAL( (unsigned char*)&tag, tag.data() );
80 }
81 
83 {
84  VarLenTag tag( 2 * sizeof( void* ) );
85  CHECK( (unsigned char*)&tag != tag.data() );
86 }
87 
89 {
90  VarLenTag tag( 1 );
91  tag.data()[0] = 'X';
92  unsigned char* ptr = tag.resize( 3 );
93  CHECK_EQUAL( tag.data(), ptr );
94  CHECK_EQUAL( (unsigned char*)&tag, tag.data() );
95  CHECK_EQUAL( tag.data()[0], 'X' );
96 }
97 
99 {
100  VarLenTag tag( sizeof( void* ) );
101  memcpy( tag.data(), "ABCDEFGHIJKLMNOPQRST", sizeof( void* ) );
102  unsigned char* ptr = tag.resize( 2 * sizeof( void* ) );
103  CHECK_EQUAL( tag.data(), ptr );
104  CHECK( (unsigned char*)&tag != tag.data() );
105  CHECK( !memcmp( tag.data(), "ABCDEFGHIJKLMNOPQRST", sizeof( void* ) ) );
106 }
107 
109 {
110  VarLenTag tag( 2 * sizeof( void* ) );
111  memcpy( tag.data(), "12345678901234567890", sizeof( void* ) );
112  unsigned char* ptr = tag.resize( sizeof( void* ) );
113  CHECK_EQUAL( tag.data(), ptr );
114  CHECK_EQUAL( (unsigned char*)&tag, tag.data() );
115  CHECK( !memcmp( tag.data(), "12345678901234567890", sizeof( void* ) ) );
116 }
117 
119 {
120  VarLenTag tag( 2 * sizeof( void* ) );
121  memcpy( tag.data(), "TSRQPONMLKJIHGFEDCBA", 2 * sizeof( void* ) );
122  unsigned char* ptr = tag.resize( 4 * sizeof( void* ) );
123  CHECK_EQUAL( tag.data(), ptr );
124  CHECK( (unsigned char*)&tag != tag.data() );
125  CHECK( !memcmp( tag.data(), "TSRQPONMLKJIHGFEDCBA", sizeof( void* ) ) );
126 }