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

Go to the source code of this file.

Macros

#define handle_test_assert(C)
 
#define tag_test_assert(C)
 

Functions

HandleUtils handleUtils (0, 1)
 
bool internal_assert (bool c)
 
bool handle_test (EntityType type, EntityID id, int proc, bool should_fail)
 
bool tag_test (TagId id, TagType prop)
 
int main ()
 Sample code on a 32-bit system. More...
 

Macro Definition Documentation

◆ handle_test_assert

#define handle_test_assert (   C)
Value:
if( internal_assert( C ) ) \
{ \
cout << "Test: " #C " failed ." << endl; \
return false; \
}

Definition at line 14 of file internals_test.cpp.

◆ tag_test_assert

#define tag_test_assert (   C)
Value:
if( internal_assert( C ) ) \
{ \
cout << "Test: " #C " failed." << endl; \
return false; \
}

Definition at line 43 of file internals_test.cpp.

Function Documentation

◆ handle_test()

bool handle_test ( EntityType  type,
EntityID  id,
int  proc,
bool  should_fail 
)

Definition at line 21 of file internals_test.cpp.

22 {
23  int err = 0;
24  EntityHandle handle = CREATE_HANDLE( type, handleUtils.create_id( id, proc ), err );
25  if( should_fail )
26  {
27  handle_test_assert( err ) return true;
28  }
29  handle_test_assert( !err )
30 
31  EntityType type_from_handle = TYPE_FROM_HANDLE( handle );
32  handle_test_assert( type_from_handle == type )
33 
34  EntityID id_from_handle = handleUtils.id_from_handle( handle );
35  handle_test_assert( id_from_handle == id )
36 
37  int proc_from_handle = handleUtils.rank_from_handle( handle );
38  handle_test_assert( proc_from_handle == proc )
39 
40  return true;
41 }

References moab::CREATE_HANDLE(), handle_test_assert, handleUtils(), and moab::TYPE_FROM_HANDLE().

Referenced by main().

◆ handleUtils()

HandleUtils handleUtils ( ,
 
)

Referenced by handle_test(), and main().

◆ internal_assert()

bool internal_assert ( bool  c)

Definition at line 9 of file internals_test.cpp.

10 {
11  return !c;
12 }

◆ main()

int main ( )

Sample code on a 32-bit system.

Definition at line 64 of file internals_test.cpp.

65 {
66  const unsigned cpus[] = { 1, 4, 16, 5, 20 };
67  const int num_cpus = sizeof( cpus ) / sizeof( cpus[0] );
68  unsigned errors = 0, tests = 0;
69  const int num_prop = MB_TAG_LAST + 1;
70 
71  ++tests;
72  if( MB_TAG_LAST > num_prop )
73  {
74  cout << "MB_TAG_PROP_WIDTH insufficient for size of TagType" << endl;
75  ++errors;
76  }
77 
78  ++tests;
79  if( MBMAXTYPE > 1 << MB_TYPE_WIDTH )
80  {
81  cout << "MB_TYPE_WIDTH insufficient for size of EntityType" << endl;
82  ++errors;
83  }
84 
85  // if any errors so far, abort because everything else will
86  // probably fail.
87  if( errors ) return errors;
88 
89  for( int num_cpu = 0; num_cpu < num_cpus; ++num_cpu )
90  {
91 
92  handleUtils = HandleUtils( 0, cpus[num_cpu] );
93 
94  // init these after setting num_cpu, because max id depends on num cpu.
95  const EntityID ids[] = { 0, 1, handleUtils.max_id() / 2, handleUtils.max_id() - 1, handleUtils.max_id() };
96  const TagId tids[] = { 0, 1, MB_TAG_PROP_MASK / 2, MB_TAG_PROP_MASK - 1, MB_TAG_PROP_MASK };
97  const int num_ids = sizeof( ids ) / sizeof( ids[0] );
98  const int num_tids = sizeof( tids ) / sizeof( tids[0] );
99 
100  for( unsigned cpu = 0; cpu < cpus[num_cpu]; ++cpu )
101  {
102  for( EntityType type = MBVERTEX; type < MBMAXTYPE; ++type )
103  for( int id = 0; id < num_ids; ++id )
104  {
105  ++tests;
106  if( !handle_test( type, ids[id], cpu, false ) )
107  {
108  cout << "Test of handle with type=" << type << ", id=" << ids[id] << ", proc=" << cpu
109  << ", and numproc=" << cpus[num_cpu] << endl;
110  ++errors;
111  }
112  }
113 
114  for( int prop = 0; prop < num_prop; ++prop )
115  for( int id = 0; id < num_tids; ++id )
116  {
117  ++tests;
118  if( !tag_test( tids[id], (TagType)prop ) )
119  {
120  cout << "Test of tag handle with prop=" << prop << ", id=" << tids[id] << ", proc=" << cpu
121  << ", and numproc=" << cpus[num_cpu] << endl;
122  ++errors;
123  }
124  }
125  }
126  }
127 
128  // test some stuff that should fail
129  handleUtils = HandleUtils( 0, 16 );
130  ++tests;
131  if( !handle_test( MBVERTEX, MB_END_ID + 1, 0, true ) )
132  {
133  cout << "Failed to catch ID overflow" << endl;
134  ++errors;
135  }
136  ++tests;
137  if( !handle_test( (EntityType)( MBMAXTYPE + 1 ), 1, 0, true ) )
138  {
139  cout << "Failed to catch type overflow" << endl;
140  ++errors;
141  }
142  // ++tests;
143  // if (!handle_test( MBHEX, 1, 17, true)) {
144  // cout << "Failed to catch Proc# overflow" << endl;
145  // ++errors;
146  // }
147 
148  if( errors )
149  cout << endl << errors << " of " << tests << " tests failed." << endl << endl;
150  else
151  cout << endl << tests << " tests passed." << endl << endl;
152  return errors;
153 }

References handle_test(), handleUtils(), MB_END_ID, MB_TYPE_WIDTH, MBMAXTYPE, MBVERTEX, tag_test(), and TagType.

◆ tag_test()

bool tag_test ( TagId  id,
TagType  prop 
)

Definition at line 50 of file internals_test.cpp.

51 {
52  Tag tag = TAG_HANDLE_FROM_ID( id, prop );
53 
54  unsigned long id_from_handle = ID_FROM_TAG_HANDLE( tag );
55  tag_test_assert( id_from_handle == id )
56 
57  TagType prop_from_handle = PROP_FROM_TAG_HANDLE( tag );
58  tag_test_assert( prop_from_handle == prop )
59 
60  return true;
61 }

References tag_test_assert, and TagType.

Referenced by main().