MOAB: Mesh Oriented datABase  (version 5.5.0)
VarLenTagTest.cpp File Reference
#include "TestUtil.hpp"
#include "VarLenTag.hpp"
#include <iostream>
+ Include dependency graph for VarLenTagTest.cpp:

Go to the source code of this file.

Classes

class  GetOffsets
 
struct  ExpectedSize
 

Macros

#define OFFSET(A)   ( (char*)( &( A ) ) - (char*)this )
 

Functions

void test_valid_struct ()
 
void test_inline ()
 
void test_non_inline ()
 
void test_resize_ii ()
 
void test_resize_in ()
 
void test_resize_ni ()
 
void test_resize_nn ()
 
int main ()
 

Macro Definition Documentation

◆ OFFSET

#define OFFSET (   A)    ( (char*)( &( A ) ) - (char*)this )

Definition at line 36 of file VarLenTagTest.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 16 of file VarLenTagTest.cpp.

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 }

References RUN_TEST, test_inline(), test_non_inline(), test_resize_ii(), test_resize_in(), test_resize_ni(), test_resize_nn(), and test_valid_struct().

◆ test_inline()

void test_inline ( )

Definition at line 76 of file VarLenTagTest.cpp.

77 {
78  VarLenTag tag( sizeof( void* ) );
79  CHECK_EQUAL( (unsigned char*)&tag, tag.data() );
80 }

References CHECK_EQUAL, and moab::VarLenTag::data().

Referenced by main().

◆ test_non_inline()

void test_non_inline ( )

Definition at line 82 of file VarLenTagTest.cpp.

83 {
84  VarLenTag tag( 2 * sizeof( void* ) );
85  CHECK( (unsigned char*)&tag != tag.data() );
86 }

References CHECK, and moab::VarLenTag::data().

Referenced by main().

◆ test_resize_ii()

void test_resize_ii ( )

Definition at line 88 of file VarLenTagTest.cpp.

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 }

References CHECK_EQUAL, moab::VarLenTag::data(), and moab::VarLenTag::resize().

Referenced by main().

◆ test_resize_in()

void test_resize_in ( )

Definition at line 98 of file VarLenTagTest.cpp.

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 }

References CHECK, CHECK_EQUAL, moab::VarLenTag::data(), and moab::VarLenTag::resize().

Referenced by main().

◆ test_resize_ni()

void test_resize_ni ( )

Definition at line 108 of file VarLenTagTest.cpp.

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 }

References CHECK, CHECK_EQUAL, moab::VarLenTag::data(), and moab::VarLenTag::resize().

Referenced by main().

◆ test_resize_nn()

void test_resize_nn ( )

Definition at line 118 of file VarLenTagTest.cpp.

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 }

References CHECK, CHECK_EQUAL, moab::VarLenTag::data(), and moab::VarLenTag::resize().

Referenced by main().

◆ test_valid_struct()

void test_valid_struct ( )

Definition at line 65 of file VarLenTagTest.cpp.

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 }

References CHECK_EQUAL, GetOffsets::pointer_array_offset(), and GetOffsets::pointer_size_offset().

Referenced by main().