![]() |
Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
00001 /**
00002 * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003 * storing and accessing finite element mesh data.
00004 *
00005 * Copyright 2004 Sandia Corporation. Under the terms of Contract
00006 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007 * retains certain rights in this software.
00008 *
00009 * This library is free software; you can redistribute it and/or
00010 * modify it under the terms of the GNU Lesser General Public
00011 * License as published by the Free Software Foundation; either
00012 * version 2.1 of the License, or (at your option) any later version.
00013 *
00014 */
00015
00016 /** TSTT Mesh Interface Unit Test
00017 *
00018 * This program tests TSTT mesh interface functions through the SIDL interface.
00019 * In a nutshell, the test creates (or accesses) an implementation instance,
00020 * tells it to load a file (specified on the command line), then calls a
00021 * number of functions evaluating that mesh. This test also tests mesh, set
00022 * and tag creation and evaluation functions.
00023 *
00024 * Usage: testcxx
00025 *
00026 * Compiling
00027 * ---------
00028 * 1. Build your server (your implementation of the TSTT mesh interface) under
00029 * SIDL/Babel and put it in a library in the Babel-generated server directory,
00030 * ${SERVER_DIR}/libimpl.so. Any include files needed to instantiate this
00031 * server from applications should also be in that directory. See note a) below.
00032 * 2. Change the definition of IMPLEMENTATION_CLASS below to be the
00033 * namespace-qualified name of your implementation class. This definition is
00034 * used in the main to instantiate the server using the SIDL _create function, e.g.
00035 * . TSTTB::Mesh mesh = IMPLEMENTATION_CLASS._create();
00036 * (we put the definition of IMPLEMENTATION_CLASS at the top of this file so that
00037 * you don't have to understand the rest of the source code to use this test). See
00038 * note b) below.
00039 * 3. Include the file(s) needed which declare the implementation's namespace and
00040 * class
00041 * 4. Compile this test file to an object file:
00042 * g++ -fpic -I. -I${BABEL}/include -I${SERVER_DIR} -c testcxx.cpp
00043 * 5. Link the application:
00044 * g++ -o testcxx testcxx.o -ltest -L${BABEL_LIBS} -lsidl
00045 *
00046 * Notes
00047 * -----
00048 * a) The files don't absolutely need to be arranged as described above. For
00049 * example, some projects put their custom implementation files somewhere besides
00050 * ${SERVER_DIR}, to keep them separate from Babel-generated files.
00051 * b) This test assumes interface instances are created using a direct call to the
00052 * SIDL _create() function for that class. Another way to do this would be to
00053 * call a factory linked into the test. To change the method used to construct
00054 * the interface instance for this test, see the use of IMPLEMENTATION_CLASS towards
00055 * the end of this file.
00056 */
00057
00058 #include
00059 #include
00060 #include
00061 #include "iMesh.h"
00062 #include "iMesh_extensions.h"
00063 #include "moab/Types.hpp"
00064 #include "TestUtil.hpp"
00065 using namespace moab;
00066 extern enum iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE + 1];
00067
00068 #define FALSE 0
00069 #define TRUE 1
00070
00071 #define DEFAULT_TEST_FILE brick.vtk
00072
00073 // clang-format off
00074
00075 #ifdef SRCDIR
00076 #define DEFAULT_INPUT_FILE STRINGIFY( SRCDIR/DEFAULT_TEST_FILE )
00077 #else
00078 #define DEFAULT_INPUT_FILE STRINGIFY( DEFAULT_TEST_FILE )
00079 #endif
00080
00081 static bool assert_pass;
00082 #define ASSERT( COND ) \
00083 assert_pass = true; \
00084 if( !( COND ) ) \
00085 { \
00086 PRINT_ASSERT_FAILURE( #COND, __FILE__, __LINE__ ); \
00087 assert_pass = false; \
00088 }
00089
00090 void PRINT_ASSERT_FAILURE( const char* cond, const char* file, int line )
00091 {
00092 printf( "Condition: %s\n", cond );
00093 printf( " failed at %s line %d\n", file, line );
00094 }
00095
00096 #define CHK( err ) \
00097 if( (err) != iBase_SUCCESS ) do \
00098 { \
00099 printf( "%s:%d ITAPS error %d\n", __FILE__, __LINE__, err ); \
00100 return 0; \
00101 } while( 0 )
00102
00103 // clang-format on
00104
00105 static iBase_EntitySetHandle root_set;
00106
00107 /*!
00108 prints out a result string based on the value of error_code
00109 */
00110 void handle_error_code( const int result, int* number_failed, int* /*number_not_implemented*/, int* number_successful )
00111 {
00112 if( result )
00113 {
00114 printf( "Success\n" );
00115 ( *number_successful )++;
00116 }
00117 else
00118 {
00119 printf( "Failure\n" );
00120 ( *number_failed )++;
00121 }
00122 }
00123
00124 /*!
00125 @test
00126 Load Mesh
00127 @li Load a mesh file
00128 */
00129 int load_mesh_test( const char* filename, iMesh_Instance mesh )
00130 {
00131 /* load a mesh */
00132 int result;
00133 iMesh_load( mesh, root_set, filename, NULL, &result, strlen( filename ), 0 );
00134 if( iBase_SUCCESS != result )
00135 {
00136 printf( "ERROR : can not load a mesh from file %s\n", filename );
00137 return FALSE;
00138 }
00139
00140 return TRUE;
00141 }
00142
00143 #define TEST_ERROR_CODE( A, B ) \
00144 if( iBase_ERROR_MAP[( A )] != ( B ) ) \
00145 { \
00146 printf( "ERROR: Invalid mapping for MOAB error code %s\n", #A ); \
00147 printf( " Expected %d, actual is %d\n", (int)iBase_ERROR_MAP[( A )], (int)( B ) ); \
00148 return FALSE; \
00149 }
00150
00151 int error_code_test( iMesh_Instance /*mesh*/ )
00152 {
00153 TEST_ERROR_CODE( MB_SUCCESS, iBase_SUCCESS )
00154 TEST_ERROR_CODE( MB_TYPE_OUT_OF_RANGE, iBase_INVALID_ENTITY_TYPE )
00155 TEST_ERROR_CODE( MB_MEMORY_ALLOCATION_FAILED, iBase_MEMORY_ALLOCATION_FAILED )
00156 TEST_ERROR_CODE( MB_ENTITY_NOT_FOUND, iBase_INVALID_ENTITY_HANDLE )
00157 TEST_ERROR_CODE( MB_TAG_NOT_FOUND, iBase_TAG_NOT_FOUND )
00158 TEST_ERROR_CODE( MB_FILE_DOES_NOT_EXIST, iBase_FILE_NOT_FOUND )
00159 TEST_ERROR_CODE( MB_UNSUPPORTED_OPERATION, iBase_NOT_SUPPORTED )
00160 TEST_ERROR_CODE( MB_UNHANDLED_OPTION, iBase_INVALID_ARGUMENT )
00161 TEST_ERROR_CODE( MB_FAILURE, iBase_FAILURE )
00162 return TRUE;
00163 }
00164
00165 /*!
00166 @test
00167 TSTT topology dimension Test
00168 @li Check 2d topology dimensions
00169 */
00170 int topology_dimension_test( iMesh_Instance mesh )
00171 {
00172 iBase_EntityHandle* faces = NULL;
00173 int faces_alloc = 0, faces_size;
00174 int result, i;
00175 int* dimensions = NULL;
00176 int dimensions_alloc = 0, dimensions_size;
00177
00178 /* first get 2D entities */
00179 iMesh_getEntities( mesh, root_set, iBase_FACE, iMesh_ALL_TOPOLOGIES, &faces, &faces_alloc, &faces_size, &result );
00180 if( iBase_SUCCESS != result )
00181 {
00182 printf( "Failed to get faces in entity_sets_test.\n" );
00183 return FALSE;
00184 }
00185
00186 /* get dimensions of faces */
00187 iMesh_getEntArrType( mesh, faces, faces_size, &dimensions, &dimensions_alloc, &dimensions_size, &result );
00188 if( iBase_SUCCESS != result )
00189 {
00190 printf( "Failed to get dimensions of faces in topology_test.\n" );
00191 free( faces );
00192 return FALSE;
00193 }
00194
00195 if( dimensions_size != faces_size )
00196 {
00197 printf( "Didn't get the right number of types in topology_test.\n" );
00198 free( faces );
00199 free( dimensions );
00200 return FALSE;
00201 }
00202
00203 /* make sure all elements are 2D */
00204 for( i = 0; i < faces_size; i++ )
00205 {
00206 if( dimensions[i] != iBase_FACE )
00207 {
00208 free( faces );
00209 free( dimensions );
00210 return FALSE;
00211 }
00212 }
00213
00214 free( faces );
00215 free( dimensions );
00216
00217 return TRUE;
00218 }
00219
00220 /*!
00221 @test
00222 TSTT topology adjacency Test
00223 @li Check topology information
00224 @li Check adjacency
00225 @li Get interior and exterior elements
00226 */
00227 /* make each topological entity vectors, check their topology */
00228 /* types, get interior and exterior faces of hexes */
00229 int topology_adjacency_test( iMesh_Instance mesh )
00230 {
00231 int result, i, j, entities_alloc, entities_size, *topologies;
00232 int topologies_alloc, topologies_size;
00233 iBase_EntityHandle *entities, *entity_vectors[iMesh_ALL_TOPOLOGIES] = { NULL };
00234 int entity_vectors_sizes[iMesh_ALL_TOPOLOGIES] = { 0 };
00235 int top_j, num_tops, region_type, num_region;
00236 iBase_EntityHandle* adj_faces = NULL;
00237 int adj_faces_alloc = 0, adj_faces_size;
00238 int* face_offsets = NULL;
00239 int face_offsets_alloc = 0, face_offsets_size, face_loaded;
00240 iBase_EntityHandle* adj_regions = NULL;
00241 int adj_regions_alloc = 0, adj_regions_size;
00242 int* region_offsets = NULL;
00243 int region_offsets_alloc = 0, region_offsets_size;
00244 iBase_EntityHandle *interior, *exterior;
00245 int num_int = 0, num_ext = 0, found, next_offset, iter;
00246 int num_faces_per_region;
00247 ;
00248
00249 /* fill the vectors of each topology entities */
00250 /* like lines vector, polygon vector, triangle vector, */
00251 /* quadrilateral, polyhedrron, tet, hex, prism, pyramid, */
00252 /* septahedron vectors */
00253 for( i = 0; i < iMesh_ALL_TOPOLOGIES; i++ )
00254 {
00255 entities = NULL;
00256 entities_alloc = 0;
00257 iMesh_getEntities( mesh, root_set, iBase_ALL_TYPES, i, &entities, &entities_alloc, &entities_size, &result );
00258 if( iBase_SUCCESS != result )
00259 {
00260 printf( "Failed to get entities in adjacencies_test.\n" );
00261 return FALSE;
00262 }
00263
00264 if( entities_alloc > 0 )
00265 {
00266 topologies = NULL;
00267 topologies_alloc = 0;
00268 iMesh_getEntArrTopo( mesh, entities, entities_alloc, &topologies, &topologies_alloc, &topologies_size,
00269 &result );
00270 if( iBase_SUCCESS != result )
00271 {
00272 printf( "Failed to get topologies in adjacencies_test.\n" );
00273 return FALSE;
00274 }
00275
00276 if( topologies_size != entities_size )
00277 {
00278 printf( "Didn't get the right number of topologies "
00279 "in topology_adjacency_test.\n" );
00280 free( topologies );
00281 free( entities );
00282 return FALSE;
00283 }
00284
00285 /* put entities into vectors of each topology */
00286 entity_vectors[i] = (iBase_EntityHandle*)malloc( entities_size * sizeof( iBase_EntityHandle ) );
00287
00288 for( j = 0; j < entities_size; j++ )
00289 {
00290 if( topologies[j] < iMesh_POINT || topologies[j] >= iMesh_ALL_TOPOLOGIES )
00291 printf( "Didn't find entity type for this topology." );
00292 else
00293 {
00294 entity_vectors[i][entity_vectors_sizes[i]] = entities[j];
00295 entity_vectors_sizes[i]++;
00296 }
00297 }
00298
00299 free( topologies );
00300 }
00301
00302 free( entities );
00303 }
00304
00305 /* check number of entities for each topology */
00306 for( top_j = 0; top_j < iMesh_ALL_TOPOLOGIES; top_j++ )
00307 {
00308 num_tops = 0;
00309 iMesh_getNumOfTopo( mesh, root_set, top_j, &num_tops, &result );
00310 if( iBase_SUCCESS != result )
00311 {
00312 printf( "Failed to get number of topologies in adjacencies_test.\n" );
00313 for( i = 0; i < iMesh_ALL_TOPOLOGIES; i++ )
00314 free( entity_vectors[i] );
00315 return FALSE;
00316 }
00317
00318 if( entity_vectors_sizes[top_j] != num_tops )
00319 {
00320 printf( "Topology count mismatch.\n" );
00321 for( i = 0; i < iMesh_ALL_TOPOLOGIES; i++ )
00322 free( entity_vectors[i] );
00323 return FALSE;
00324 }
00325 }
00326
00327 /* change if 3d topology entities are added or removed */
00328 for( region_type = iMesh_TETRAHEDRON; region_type < iMesh_ALL_TOPOLOGIES; region_type++ )
00329 {
00330 /* get all adjacent faces of regions */
00331 iBase_EntityHandle* region_vector = entity_vectors[region_type];
00332
00333 num_region = entity_vectors_sizes[region_type];
00334
00335 if( num_region > 0 )
00336 {
00337 adj_faces = NULL;
00338 adj_faces_alloc = 0;
00339 face_offsets = NULL;
00340 face_offsets_alloc = 0;
00341
00342 iMesh_getEntArrAdj( mesh, region_vector, num_region, iBase_FACE, &adj_faces, &adj_faces_alloc,
00343 &adj_faces_size, &face_offsets, &face_offsets_alloc, &face_offsets_size, &result );
00344 if( iBase_SUCCESS != result )
00345 {
00346 printf( "Failed to get adjacent faces of regions in adjacencies_test.\n" );
00347 for( i = 0; i < iMesh_ALL_TOPOLOGIES; i++ )
00348 free( entity_vectors[i] );
00349 return FALSE;
00350 }
00351
00352 if( num_region + 1 != face_offsets_size )
00353 {
00354 printf( "Number of offsets didn't agree with number of "
00355 "regions in topology_adjacency_test.\n" );
00356 free( face_offsets );
00357 free( adj_faces );
00358 for( i = 0; i < iMesh_ALL_TOPOLOGIES; i++ )
00359 free( entity_vectors[i] );
00360 return FALSE;
00361 }
00362
00363 face_loaded = FALSE;
00364
00365 /* check # of faces really loaded */
00366 if( region_type == iMesh_TETRAHEDRON )
00367 {
00368 if( adj_faces_size == 4 * num_region ) face_loaded = TRUE;
00369 }
00370 else if( region_type == iMesh_HEXAHEDRON )
00371 {
00372 if( adj_faces_size == 6 * num_region ) face_loaded = TRUE;
00373 }
00374 else if( region_type == iMesh_PRISM )
00375 {
00376 if( adj_faces_size == 5 * num_region ) face_loaded = TRUE;
00377 }
00378 else if( region_type == iMesh_PYRAMID )
00379 {
00380 if( adj_faces_size == 5 * num_region ) face_loaded = TRUE;
00381 }
00382 else if( region_type == iMesh_SEPTAHEDRON )
00383 {
00384 if( adj_faces_size == 7 * num_region ) face_loaded = TRUE;
00385 }
00386 else
00387 face_loaded = FALSE;
00388
00389 /* get all adjacent regions of adjacent faces */
00390 adj_regions = NULL;
00391 adj_regions_alloc = 0;
00392 region_offsets = NULL;
00393 region_offsets_alloc = 0;
00394 iMesh_getEntArrAdj( mesh, adj_faces, adj_faces_size, iBase_REGION, &adj_regions, &adj_regions_alloc,
00395 &adj_regions_size, ®ion_offsets, ®ion_offsets_alloc, ®ion_offsets_size,
00396 &result );
00397 if( iBase_SUCCESS != result )
00398 {
00399 printf( "Failed to get regions from faces in adjacencies_test.\n" );
00400 free( face_offsets );
00401 free( adj_faces );
00402 for( i = 0; i < iMesh_ALL_TOPOLOGIES; i++ )
00403 free( entity_vectors[i] );
00404 return FALSE;
00405 }
00406
00407 if( adj_faces_size + 1 != region_offsets_size )
00408 {
00409 printf( "Number of offsets didn't agree with number of faces in "
00410 "topology_adjacency_test.\n" );
00411 free( face_offsets );
00412 free( region_offsets );
00413 free( adj_faces );
00414 free( adj_regions );
00415 for( i = 0; i < iMesh_ALL_TOPOLOGIES; i++ )
00416 free( entity_vectors[i] );
00417 return FALSE;
00418 }
00419
00420 interior = (iBase_EntityHandle*)malloc( adj_faces_size * sizeof( iBase_EntityHandle ) ),
00421 exterior = (iBase_EntityHandle*)malloc( adj_faces_size * sizeof( iBase_EntityHandle ) );
00422 num_int = 0;
00423 num_ext = 0;
00424
00425 /* find the interior faces having two adjacent regions */
00426 for( i = 0; i < adj_faces_size; i++ )
00427 {
00428 next_offset = 0;
00429 if( i == adj_faces_size - 1 )
00430 next_offset = adj_regions_size;
00431 else
00432 next_offset = region_offsets[i + 1];
00433
00434 if( next_offset - region_offsets[i] == 2 )
00435 {
00436 found = FALSE;
00437 for( iter = 0; iter < num_int; iter++ )
00438 {
00439 if( interior[iter] == adj_faces[i] )
00440 {
00441 found = TRUE;
00442 break;
00443 }
00444 }
00445 if( !found ) interior[num_int++] = adj_faces[i];
00446 }
00447 }
00448
00449 /* now remove any interior faces from the previous adjacent faces list */
00450 /* and we should be left with exterior faces */
00451 for( i = 0; i < adj_faces_size; i++ )
00452 {
00453 found = FALSE;
00454 for( iter = 0; iter < num_int; iter++ )
00455 {
00456 if( interior[iter] == adj_faces[i] )
00457 {
00458 found = TRUE;
00459 break;
00460 }
00461 }
00462 if( !found ) exterior[num_ext++] = adj_faces[i];
00463 }
00464
00465 num_faces_per_region = face_offsets[1] - face_offsets[0];
00466
00467 /* check # of exterior and interior faces */
00468 /* should be #exterior_faces + 2 * #interior_faces = #faces_per_region */
00469 /* * #regions */
00470 if( face_loaded )
00471 {
00472 if( num_ext + 2 * num_int != num_faces_per_region * num_region )
00473 {
00474 printf( "exterior/interior failure: %d ext, %d int, %d regions, %d faces per\n", num_ext, num_int,
00475 num_region, num_faces_per_region );
00476 free( face_offsets );
00477 free( region_offsets );
00478 free( adj_faces );
00479 free( adj_regions );
00480 free( interior );
00481 free( exterior );
00482 for( i = 0; i < iMesh_ALL_TOPOLOGIES; i++ )
00483 free( entity_vectors[i] );
00484 return FALSE;
00485 }
00486 }
00487
00488 free( face_offsets );
00489 free( region_offsets );
00490 free( adj_faces );
00491 free( adj_regions );
00492 free( interior );
00493 free( exterior );
00494 }
00495 }
00496
00497 for( i = 0; i < iMesh_ALL_TOPOLOGIES; i++ )
00498 free( entity_vectors[i] );
00499
00500 return TRUE;
00501 }
00502
00503 int qsort_comp_handles( const void* h1, const void* h2 )
00504 {
00505 return *(char**)h1 - *(char**)h2;
00506 }
00507
00508 /*!
00509 @test
00510 TSTT EntityType Connectivity Test
00511 @li Get coordinates for all type enities
00512 */
00513
00514 int entity_connectivity_test( iMesh_Instance mesh )
00515 {
00516 int type, result;
00517 int *offsets, offsets_alloc, offsets_size;
00518 int *indices, indices_alloc, indices_size;
00519 iBase_EntityHandle *entities, *adj_ents, *entities2, *sorted;
00520 int entities_alloc, entities_size, adj_ents_alloc, adj_ents_size;
00521 int entities2_alloc, entities2_size;
00522 iBase_EntityHandle adj_ents2[27], *adj_ents2_ptr = adj_ents2;
00523 int adj_ents2_alloc = 27, adj_ents2_size, i, size;
00524
00525 for( type = iBase_EDGE; type < iBase_ALL_TYPES; type++ )
00526 {
00527 entities = NULL;
00528 entities_alloc = 0;
00529 adj_ents = NULL;
00530 adj_ents_alloc = 0;
00531 indices = NULL;
00532 indices_alloc = 0;
00533 offsets = NULL;
00534 offsets_alloc = 0;
00535 iMesh_getAdjEntIndices( mesh, root_set, type, iMesh_ALL_TOPOLOGIES, iBase_VERTEX, &entities, &entities_alloc,
00536 &entities_size, &adj_ents, &adj_ents_alloc, &adj_ents_size, &indices, &indices_alloc,
00537 &indices_size, &offsets, &offsets_alloc, &offsets_size, &result );
00538 if( iBase_SUCCESS != result )
00539 {
00540 printf( "Failed to get indices of vertices in connectivity_test, type=%d.\n", type );
00541 return FALSE;
00542 }
00543
00544 if( entities_alloc != entities_size )
00545 {
00546 printf( "Number of entities didn't agree with array size in connectivity_test.\n" );
00547 free( entities );
00548 free( adj_ents );
00549 free( indices );
00550 free( offsets );
00551 return FALSE;
00552 }
00553
00554 if( offsets_alloc != offsets_size )
00555 {
00556 printf( "Number of offsets didn't agree with array size in connectivity_test.\n" );
00557 free( entities );
00558 free( adj_ents );
00559 free( indices );
00560 free( offsets );
00561 return FALSE;
00562 }
00563
00564 if( indices_alloc != indices_size )
00565 {
00566 printf( "Number of indices didn't agree with array size in connectivity_test.\n" );
00567 free( entities );
00568 free( adj_ents );
00569 free( indices );
00570 free( offsets );
00571 return FALSE;
00572 }
00573
00574 if( adj_ents_alloc != adj_ents_size )
00575 {
00576 printf( "Number of adjacent entities didn't agree with array size in "
00577 "connectivity_test.\n" );
00578 free( entities );
00579 free( adj_ents );
00580 free( indices );
00581 free( offsets );
00582 return FALSE;
00583 }
00584
00585 if( offsets_size != entities_size + 1 )
00586 {
00587 printf( "Invalid/inconsistent offset size from iMesh_getAdjEntIndices.\n" );
00588 free( entities );
00589 free( adj_ents );
00590 free( indices );
00591 free( offsets );
00592 return FALSE;
00593 }
00594
00595 /* check that results are valid */
00596 for( i = 0; i < entities_size; ++i )
00597 {
00598 ASSERT( offsets[i] < offsets[i + 1] && offsets[i] < indices_size );
00599 if( !assert_pass )
00600 {
00601 free( entities );
00602 free( adj_ents );
00603 free( indices );
00604 free( offsets );
00605 return FALSE;
00606 }
00607 }
00608
00609 for( i = 0; i < indices_size; ++i )
00610 {
00611 ASSERT( indices[i] >= 0 && indices[i] < adj_ents_size );
00612 if( !assert_pass )
00613 {
00614 free( entities );
00615 free( adj_ents );
00616 free( indices );
00617 free( offsets );
00618 return FALSE;
00619 }
00620 }
00621
00622 /* compare initial entity list against result of iMesh_getEntities */
00623 entities2 = NULL;
00624 entities2_alloc = 0;
00625 iMesh_getEntities( mesh, root_set, type, iMesh_ALL_TOPOLOGIES, &entities2, &entities2_alloc, &entities2_size,
00626 &result );
00627 ASSERT( iBase_SUCCESS == result );
00628 if( !assert_pass )
00629 {
00630 free( entities );
00631 free( adj_ents );
00632 free( indices );
00633 free( offsets );
00634 return FALSE;
00635 }
00636
00637 size = sizeof( iBase_EntityHandle ) * entities_size;
00638 sorted = (iBase_EntityHandle*)malloc( size );
00639 memcpy( sorted, entities, size );
00640 qsort( sorted, entities_size, sizeof( iBase_EntityHandle ), &qsort_comp_handles );
00641 qsort( entities2, entities2_size, sizeof( iBase_EntityHandle ), &qsort_comp_handles );
00642
00643 ASSERT( entities_size == entities2_size && !memcmp( sorted, entities2, size ) );
00644 if( !assert_pass )
00645 {
00646 free( entities );
00647 free( adj_ents );
00648 free( indices );
00649 free( offsets );
00650 free( entities2 );
00651 free( sorted );
00652 return FALSE;
00653 }
00654
00655 free( entities2 );
00656 free( sorted );
00657
00658 /* compare results against output of iMesh_getEntAdj */
00659 for( i = 0; i < entities_size; ++i )
00660 {
00661 iMesh_getEntAdj( mesh, entities[i], iBase_VERTEX, &adj_ents2_ptr, &adj_ents2_alloc, &adj_ents2_size,
00662 &result );
00663 ASSERT( iBase_SUCCESS == result );
00664 if( !assert_pass )
00665 {
00666 free( entities );
00667 free( adj_ents );
00668 free( indices );
00669 free( offsets );
00670 return FALSE;
00671 }
00672
00673 ASSERT( adj_ents2_ptr == adj_ents2 ); /* shouldn't change */
00674 if( !assert_pass )
00675 {
00676 free( entities );
00677 free( adj_ents );
00678 free( indices );
00679 free( offsets );
00680 return FALSE;
00681 }
00682
00683 ASSERT( adj_ents2_alloc == 27 ); /* shouldn't change */
00684 if( !assert_pass )
00685 {
00686 free( entities );
00687 free( adj_ents );
00688 free( indices );
00689 free( offsets );
00690 return FALSE;
00691 }
00692
00693 /* compare results */
00694 size = offsets[i + 1] - offsets[i];
00695 ASSERT( size == adj_ents2_size );
00696 while( --size >= 0 )
00697 {
00698 ASSERT( adj_ents2[size] == adj_ents[indices[offsets[i] + size]] );
00699 if( !assert_pass )
00700 {
00701 free( entities );
00702 free( adj_ents );
00703 free( indices );
00704 free( offsets );
00705 return FALSE;
00706 }
00707 }
00708 }
00709
00710 free( entities );
00711 free( adj_ents );
00712 free( indices );
00713 free( offsets );
00714
00715 /*
00716 offsets = NULL;
00717 offsets_alloc = 0;
00718 entities = NULL;
00719 entities_alloc = 0;
00720
00721 iMesh_getAdjEntities(mesh, root_set, type,
00722 iMesh_ALL_TOPOLOGIES, iBase_VERTEX,
00723 &entities, &entities_alloc, &entities_size,
00724 &offsets, &offsets_alloc, &offsets_size,
00725 &result);
00726 if (iBase_SUCCESS != result) {
00727 printf("Failed to get indices of adjacent entity vertices in connectivity_test.\n");
00728 return FALSE;
00729 }
00730
00731 if (entities_alloc != entities_size ||
00732 offsets_alloc != offsets_size) {
00733 printf("Number of elements didn't agree with array size for an array in
00734 connectivity_test.\n"); return FALSE;
00735 }
00736
00737 free(offsets);
00738 free(entities);
00739 */
00740 }
00741
00742 return TRUE;
00743 }
00744
00745 /*!
00746 @test
00747 TSTT entity sets sub test
00748 @li Check entity sets
00749 */
00750
00751 /* helper function used to report errors in # sets */
00752 int check_esets( iMesh_Instance mesh, const int num_sets );
00753
00754 int entity_sets_subtest( iMesh_Instance mesh, int is_list, int /*num_iter*/ )
00755 {
00756 int i, num_type = iBase_ALL_TYPES - iBase_VERTEX;
00757 // int num_all_entities_super = 0;
00758 iBase_EntitySetHandle es_array[iBase_ALL_TYPES - iBase_VERTEX];
00759 int number_array[iBase_ALL_TYPES - iBase_VERTEX];
00760 int ent_type = iBase_VERTEX;
00761 iBase_EntityHandle* entities = NULL;
00762 int entities_alloc = 0, entities_size;
00763 iBase_EntitySetHandle parent_child, super_set = NULL;
00764 iBase_EntitySetHandle temp_es1, temp_es2, temp_es3;
00765 iBase_EntityHandle *edges = NULL, *faces = NULL, *temp_entities1 = NULL, *temp_entities2 = NULL;
00766 int edges_alloc = 0, faces_alloc = 0, temp_entities1_alloc = 0, temp_entities2_alloc = 0;
00767 int edges_size, faces_size, temp_entities1_size, temp_entities2_size;
00768 int* types = NULL;
00769 int types_alloc = 0, types_size;
00770 int num_rest, num_regions;
00771 iBase_EntityHandle* regions = NULL;
00772 int regions_alloc = 0, regions_size;
00773 iBase_EntitySetHandle* parents = NULL;
00774 int parents_alloc = 0, parents_size, temp_numb, is_child;
00775 iBase_EntitySetHandle* es_array1 = NULL;
00776 int es_array1_alloc = 0, es_array1_size, num_super;
00777 iBase_EntityHandle* all_entities = NULL;
00778 int all_entities_alloc = 0, all_entities_size, k, l;
00779 iBase_EntityHandle* adj_faces = NULL;
00780 int adj_faces_alloc = 0, adj_faces_size;
00781 int* face_offsets = NULL;
00782 int face_offsets_alloc = 0, face_offsets_size;
00783 iBase_EntityHandle* hexes = NULL;
00784 int hexes_alloc = 0, hexes_size;
00785 iBase_EntitySetHandle hex_set;
00786
00787 /* get the number of whole mesh */
00788 int n_whole_mesh = 0;
00789 int result;
00790 iMesh_getNumEntSets( mesh, root_set, 1, &n_whole_mesh, &result );
00791 if( iBase_SUCCESS != result )
00792 {
00793 printf( "Problem to get the number of all entity sets in whole mesh.\n" );
00794 return FALSE;
00795 }
00796
00797 /* add entities to entitysets by type */
00798 for( ; ent_type < num_type; ent_type++ )
00799 {
00800 /* initialize the entityset */
00801 iMesh_createEntSet( mesh, is_list, &es_array[ent_type], &result );
00802 if( iBase_SUCCESS != result )
00803 {
00804 printf( "Problem creating entityset.\n" );
00805 return FALSE;
00806 }
00807
00808 /* get entities by type in total "mesh" */
00809 entities = NULL;
00810 entities_alloc = 0;
00811 iMesh_getEntities( mesh, root_set, ent_type, iMesh_ALL_TOPOLOGIES, &entities, &entities_alloc, &entities_size,
00812 &result );
00813 if( iBase_SUCCESS != result )
00814 {
00815 printf( "Failed to get entities by type in entity_sets_test.\n" );
00816 return FALSE;
00817 }
00818
00819 if( entities_alloc != entities_size )
00820 {
00821 printf( "Number of entities didn't agree with array size in entity_sets_subtest.\n" );
00822 free( entities );
00823 return FALSE;
00824 }
00825
00826 /* add entities into entity set */
00827 if( 0 != entities_size )
00828 {
00829 iMesh_addEntArrToSet( mesh, entities, entities_size, es_array[ent_type], &result );
00830 if( iBase_SUCCESS != result )
00831 {
00832 printf( "Failed to add entities in entity_sets_test.\n" );
00833 free( entities );
00834 return FALSE;
00835 }
00836 }
00837
00838 /* Check to make sure entity set really has correct number of entities in it */
00839 iMesh_getNumOfType( mesh, es_array[ent_type], ent_type, number_array + ent_type, &result );
00840
00841 if( iBase_SUCCESS != result )
00842 {
00843 printf( "Failed to get number of entities by type in entity_sets_test.\n" );
00844 free( entities );
00845 return FALSE;
00846 }
00847
00848 /* compare the number of entities by type */
00849 if( number_array[ent_type] != entities_size )
00850 {
00851 printf( "Number of entities by type is not correct\n" );
00852 free( entities );
00853 return FALSE;
00854 }
00855
00856 /* add to number of all entities in super set */
00857 // num_all_entities_super += entities_size;
00858
00859 free( entities );
00860 }
00861
00862 if( !check_esets( mesh, n_whole_mesh + num_type ) ) return FALSE;
00863
00864 /* make a super set having all entitysets */
00865 super_set = NULL;
00866 iMesh_createEntSet( mesh, is_list, &super_set, &result );
00867 if( iBase_SUCCESS != result )
00868 {
00869 printf( "Failed to create a super set in entity_sets_test.\n" );
00870 return FALSE;
00871 }
00872
00873 for( i = 0; i < num_type; i++ )
00874 {
00875 iMesh_addEntSet( mesh, es_array[i], super_set, &result );
00876 if( iBase_SUCCESS != result )
00877 {
00878 printf( "Failed to add a set to a super set in entity_sets_test.\n" );
00879 return FALSE;
00880 }
00881 }
00882
00883 if( !check_esets( mesh, n_whole_mesh + num_type + 1 ) ) return FALSE;
00884
00885 /*----------TEST intEAN OPERATIONS----------------*/
00886
00887 iMesh_createEntSet( mesh, is_list, &temp_es1, &result );
00888 if( iBase_SUCCESS != result )
00889 {
00890 printf( "Failed to create a super set in entity_sets_test.\n" );
00891 return FALSE;
00892 }
00893
00894 if( !check_esets( mesh, n_whole_mesh + num_type + 2 ) )
00895 {
00896 return FALSE;
00897 }
00898
00899 /* Subtract */
00900 /* add all EDGEs and FACEs to temp_es1 */
00901 /* get all EDGE entities */
00902 edges = NULL;
00903 edges_alloc = 0;
00904 iMesh_getEntities( mesh, es_array[iBase_EDGE], iBase_EDGE, iMesh_ALL_TOPOLOGIES, &edges, &edges_alloc, &edges_size,
00905 &result );
00906
00907 if( iBase_SUCCESS != result )
00908 {
00909 printf( "Failed to get edge entities in entity_sets_test.\n" );
00910 return FALSE;
00911 }
00912
00913 /* add EDGEs to es1 */
00914 iMesh_addEntArrToSet( mesh, edges, edges_size, temp_es1, &result );
00915 if( iBase_SUCCESS != result )
00916 {
00917 printf( "Failed to add edge entities in entity_sets_test.\n" );
00918 free( edges );
00919 return FALSE;
00920 }
00921
00922 /* get all FACE entities */
00923 faces = NULL;
00924 faces_alloc = 0;
00925 iMesh_getEntities( mesh, es_array[iBase_FACE], iBase_FACE, iMesh_ALL_TOPOLOGIES, &faces, &faces_alloc, &faces_size,
00926 &result );
00927 if( iBase_SUCCESS != result )
00928 {
00929 printf( "Failed to get face entities in entity_sets_test.\n" );
00930 free( edges );
00931 return FALSE;
00932 }
00933
00934 /* add FACEs to es1 */
00935 iMesh_addEntArrToSet( mesh, faces, faces_size, temp_es1, &result );
00936 if( iBase_SUCCESS != result )
00937 {
00938 printf( "Failed to add face entities in entity_sets_test.\n" );
00939 free( edges );
00940 free( faces );
00941 return FALSE;
00942 }
00943
00944 /* subtract EDGEs */
00945
00946 iMesh_subtract( mesh, temp_es1, es_array[iBase_EDGE], &temp_es2, &result );
00947 if( iBase_SUCCESS != result )
00948 {
00949 printf( "Failed to subtract entitysets in entity_sets_test.\n" );
00950 free( edges );
00951 free( faces );
00952 return FALSE;
00953 }
00954
00955 temp_entities1 = NULL;
00956 temp_entities1_alloc = 0;
00957 iMesh_getEntities( mesh, temp_es2, iBase_FACE, iMesh_ALL_TOPOLOGIES, &temp_entities1, &temp_entities1_alloc,
00958 &temp_entities1_size, &result );
00959 if( iBase_SUCCESS != result )
00960 {
00961 printf( "Failed to get face entities in entity_sets_test.\n" );
00962 free( edges );
00963 free( faces );
00964 return FALSE;
00965 }
00966
00967 if( faces_size != temp_entities1_size )
00968 {
00969 printf( "not match number of entitysets after subtraction "
00970 "in entity_sets_test.\n" );
00971 free( edges );
00972 free( faces );
00973 free( temp_entities1 );
00974 return FALSE;
00975 }
00976
00977 /* check there's nothing but faces in face_es */
00978 types = NULL;
00979 types_alloc = 0;
00980 iMesh_getEntArrType( mesh, temp_entities1, temp_entities1_size, &types, &types_alloc, &types_size, &result );
00981 if( iBase_SUCCESS != result )
00982 {
00983 printf( "Failed to get types of entities in entity_sets_test.\n" );
00984 free( edges );
00985 free( faces );
00986 free( temp_entities1 );
00987 return FALSE;
00988 }
00989 for( i = 0; i < types_size; i++ )
00990 {
00991 if( types[i] != iBase_FACE )
00992 {
00993 printf( "wrong entity type for face test in entity_sets_test.\n" );
00994 free( edges );
00995 free( faces );
00996 free( temp_entities1 );
00997 free( types );
00998 return FALSE;
00999 }
01000 }
01001
01002 iMesh_destroyEntSet( mesh, temp_es2, &result );
01003 if( iBase_SUCCESS != result )
01004 {
01005 printf( "Failed to destroy temp es2.\n" );
01006 free( edges );
01007 free( faces );
01008 free( temp_entities1 );
01009 free( types );
01010 return FALSE;
01011 }
01012
01013 if( !check_esets( mesh, n_whole_mesh + num_type + 2 ) )
01014 {
01015 free( edges );
01016 free( faces );
01017 free( temp_entities1 );
01018 free( types );
01019 return FALSE;
01020 }
01021
01022 /*------------Intersect------------ */
01023
01024 /* clean out the temp_ms1 */
01025 iMesh_rmvEntArrFromSet( mesh, faces, faces_size, temp_es1, &result );
01026 if( iBase_SUCCESS != result )
01027 {
01028 printf( "Failed to remove face entities in entity_sets_test.\n" );
01029 free( edges );
01030 free( faces );
01031 free( temp_entities1 );
01032 free( types );
01033 return FALSE;
01034 }
01035
01036 /* check if it is really cleaned out */
01037 iMesh_getNumOfType( mesh, temp_es1, iBase_FACE, &num_rest, &result );
01038 if( iBase_SUCCESS != result )
01039 {
01040 printf( "Failed to get number of entities by type in entity_sets_test.\n" );
01041 free( edges );
01042 free( faces );
01043 free( temp_entities1 );
01044 free( types );
01045 return FALSE;
01046 }
01047
01048 if( num_rest != 0 )
01049 {
01050 printf( "failed to remove correctly.\n" );
01051 free( edges );
01052 free( faces );
01053 free( temp_entities1 );
01054 free( types );
01055 return FALSE;
01056 }
01057
01058 /* add EDGEs to temp es1 */
01059 iMesh_addEntArrToSet( mesh, edges, edges_size, temp_es1, &result );
01060 if( iBase_SUCCESS != result )
01061 {
01062 printf( "Failed to add edge entities in entity_sets_test.\n" );
01063 free( edges );
01064 free( faces );
01065 free( temp_entities1 );
01066 free( types );
01067 return FALSE;
01068 }
01069
01070 /* add FACEs to temp es1 */
01071 iMesh_addEntArrToSet( mesh, faces, faces_size, temp_es1, &result );
01072 if( iBase_SUCCESS != result )
01073 {
01074 printf( "Failed to add edge entities in entity_sets_test.\n" );
01075 free( edges );
01076 free( faces );
01077 free( temp_entities1 );
01078 free( types );
01079 return FALSE;
01080 }
01081
01082 /* intersect temp_es1 with edges meshset */
01083 /* temp_ms1 entityset is altered */
01084 iMesh_intersect( mesh, temp_es1, es_array[iBase_EDGE], &temp_es2, &result );
01085 if( iBase_SUCCESS != result )
01086 {
01087 printf( "Failed to intersect in entity_sets_test.\n" );
01088 free( edges );
01089 free( faces );
01090 free( temp_entities1 );
01091 free( types );
01092 return FALSE;
01093 }
01094
01095 temp_entities2 = NULL;
01096 temp_entities2_alloc = 0;
01097 iMesh_getEntities( mesh, temp_es2, iBase_FACE, iMesh_ALL_TOPOLOGIES, &temp_entities2, &temp_entities2_alloc,
01098 &temp_entities2_size, &result );
01099 if( iBase_SUCCESS != result )
01100 {
01101 printf( "Failed to get face entities in entity_sets_test.\n" );
01102 free( edges );
01103 free( faces );
01104 free( temp_entities1 );
01105 free( types );
01106 return FALSE;
01107 }
01108
01109 if( temp_entities2_size != 0 )
01110 {
01111 printf( "wrong number of faces.\n" );
01112 free( edges );
01113 free( faces );
01114 free( temp_entities1 );
01115 free( temp_entities2 );
01116 free( types );
01117 return FALSE;
01118 }
01119
01120 iMesh_destroyEntSet( mesh, temp_es2, &result );
01121 if( iBase_SUCCESS != result )
01122 {
01123 printf( "Failed to destroy temp es2.\n" );
01124 free( edges );
01125 free( faces );
01126 free( temp_entities1 );
01127 free( temp_entities2 );
01128 free( types );
01129 return FALSE;
01130 }
01131
01132 if( !check_esets( mesh, n_whole_mesh + num_type + 2 ) )
01133 {
01134 free( edges );
01135 free( faces );
01136 free( temp_entities1 );
01137 free( temp_entities2 );
01138 free( types );
01139 return FALSE;
01140 }
01141
01142 /*-------------Unite-------------- */
01143
01144 iMesh_createEntSet( mesh, is_list, &temp_es2, &result );
01145 if( iBase_SUCCESS != result )
01146 {
01147 printf( "Failed to create a temp entityset in entity_sets_test.\n" );
01148 free( edges );
01149 free( faces );
01150 free( temp_entities1 );
01151 free( temp_entities2 );
01152 free( types );
01153 return FALSE;
01154 }
01155
01156 /* get all regions */
01157 regions = NULL;
01158 regions_alloc = 0;
01159 iMesh_getEntities( mesh, es_array[iBase_REGION], iBase_REGION, iMesh_ALL_TOPOLOGIES, ®ions, ®ions_alloc,
01160 ®ions_size, &result );
01161 if( iBase_SUCCESS != result )
01162 {
01163 printf( "Failed to get region entities in entity_sets_test.\n" );
01164 free( edges );
01165 free( faces );
01166 free( temp_entities1 );
01167 free( temp_entities2 );
01168 free( types );
01169 return FALSE;
01170 }
01171
01172 /* add REGIONs to temp es2 */
01173 iMesh_addEntArrToSet( mesh, regions, regions_size, temp_es2, &result );
01174 if( iBase_SUCCESS != result )
01175 {
01176 printf( "Failed to add region entities in entity_sets_test.\n" );
01177 free( edges );
01178 free( faces );
01179 free( temp_entities1 );
01180 free( temp_entities2 );
01181 free( types );
01182 free( regions );
01183 return FALSE;
01184 }
01185
01186 /* unite temp_es1 and temp_es2 */
01187 iMesh_unite( mesh, temp_es1, temp_es2, &temp_es3, &result );
01188 if( iBase_SUCCESS != result )
01189 {
01190 printf( "Failed to unite in entity_sets_test.\n" );
01191 free( edges );
01192 free( faces );
01193 free( temp_entities1 );
01194 free( temp_entities2 );
01195 free( types );
01196 free( regions );
01197 return FALSE;
01198 }
01199
01200 /* perform the check */
01201 iMesh_getNumOfType( mesh, temp_es3, iBase_REGION, &num_regions, &result );
01202 if( iBase_SUCCESS != result )
01203 {
01204 printf( "Failed to get number of region entities by type in entity_sets_test.\n" );
01205 free( edges );
01206 free( faces );
01207 free( temp_entities1 );
01208 free( temp_entities2 );
01209 free( types );
01210 free( regions );
01211 return FALSE;
01212 }
01213
01214 if( num_regions != number_array[iBase_REGION] )
01215 {
01216 printf( "different number of regions in entity_sets_test.\n" );
01217 free( edges );
01218 free( faces );
01219 free( temp_entities1 );
01220 free( temp_entities2 );
01221 free( types );
01222 free( regions );
01223 return FALSE;
01224 }
01225
01226 if( !check_esets( mesh, n_whole_mesh + num_type + 4 ) )
01227 {
01228 free( edges );
01229 free( faces );
01230 free( temp_entities1 );
01231 free( temp_entities2 );
01232 free( types );
01233 free( regions );
01234 return FALSE;
01235 }
01236
01237 /*--------Test parent/child stuff in entiysets----------- */
01238
01239 /* Add 2 meshsets as children to another */
01240 iMesh_createEntSet( mesh, is_list, &parent_child, &result );
01241 if( iBase_SUCCESS != result )
01242 {
01243 printf( "Problem creating entityset in entity_sets_test.\n" );
01244 free( edges );
01245 free( faces );
01246 free( temp_entities1 );
01247 free( temp_entities2 );
01248 free( types );
01249 free( regions );
01250 return FALSE;
01251 }
01252
01253 iMesh_addPrntChld( mesh, es_array[iBase_VERTEX], parent_child, &result );
01254 if( iBase_SUCCESS != result )
01255 {
01256 printf( "Problem add parent in entity_sets_test.\n" );
01257 free( edges );
01258 free( faces );
01259 free( temp_entities1 );
01260 free( temp_entities2 );
01261 free( types );
01262 free( regions );
01263 return FALSE;
01264 }
01265
01266 /* check if parent is really added */
01267 parents = NULL;
01268 parents_alloc = 0;
01269 iMesh_getPrnts( mesh, parent_child, 0, &parents, &parents_alloc, &parents_size, &result );
01270 if( iBase_SUCCESS != result )
01271 {
01272 printf( "Problem getting parents in entity_sets_test.\n" );
01273 free( edges );
01274 free( faces );
01275 free( temp_entities1 );
01276 free( temp_entities2 );
01277 free( types );
01278 free( regions );
01279 return FALSE;
01280 }
01281
01282 if( parents_size != 1 )
01283 {
01284 printf( "number of parents is not correct in entity_sets_test.\n" );
01285 free( edges );
01286 free( faces );
01287 free( temp_entities1 );
01288 free( temp_entities2 );
01289 free( types );
01290 free( regions );
01291 free( parents );
01292 return FALSE;
01293 }
01294
01295 /* get the number of child entitysets */
01296 iMesh_getNumChld( mesh, es_array[iBase_VERTEX], 0, &temp_numb, &result );
01297 if( iBase_SUCCESS != result )
01298 {
01299 printf( "Problem getting number of children in entity_sets_test.\n" );
01300 free( edges );
01301 free( faces );
01302 free( temp_entities1 );
01303 free( temp_entities2 );
01304 free( types );
01305 free( regions );
01306 free( parents );
01307 return FALSE;
01308 }
01309
01310 if( temp_numb != 1 )
01311 {
01312 printf( "number of children is not correct in entity_sets_test.\n" );
01313 free( edges );
01314 free( faces );
01315 free( temp_entities1 );
01316 free( temp_entities2 );
01317 free( types );
01318 free( regions );
01319 free( parents );
01320 return FALSE;
01321 }
01322
01323 /* parent_child and es_array[iBase_VERTEX] should be related */
01324 is_child = 0;
01325 iMesh_isChildOf( mesh, es_array[iBase_VERTEX], parent_child, &is_child, &result );
01326 if( iBase_SUCCESS != result )
01327 {
01328 printf( "Problem checking relation in entity_sets_test.\n" );
01329 free( edges );
01330 free( faces );
01331 free( temp_entities1 );
01332 free( temp_entities2 );
01333 free( types );
01334 free( regions );
01335 free( parents );
01336 return FALSE;
01337 }
01338 if( !is_child )
01339 {
01340 printf( "parent_child and es_array[iBase_VERTEX] should be related\n" );
01341 free( edges );
01342 free( faces );
01343 free( temp_entities1 );
01344 free( temp_entities2 );
01345 free( types );
01346 free( regions );
01347 free( parents );
01348 return FALSE;
01349 }
01350
01351 /* es_array[iBase_FACE] and es_array[iBase_REGION] are not related */
01352 is_child = FALSE;
01353 iMesh_isChildOf( mesh, es_array[iBase_FACE], es_array[iBase_REGION], &is_child, &result );
01354 if( iBase_SUCCESS != result )
01355 {
01356 printf( "Problem checking relation in entity_sets_test.\n" );
01357 free( edges );
01358 free( faces );
01359 free( temp_entities1 );
01360 free( temp_entities2 );
01361 free( types );
01362 free( regions );
01363 free( parents );
01364 return FALSE;
01365 }
01366 if( is_child )
01367 {
01368 printf( "es_array[iBase_REGION] and es_array[iBase_FACE] should not be related\n" );
01369 free( edges );
01370 free( faces );
01371 free( temp_entities1 );
01372 free( temp_entities2 );
01373 free( types );
01374 free( regions );
01375 free( parents );
01376 return FALSE;
01377 }
01378
01379 if( !check_esets( mesh, n_whole_mesh + num_type + 5 ) )
01380 {
01381 free( edges );
01382 free( faces );
01383 free( temp_entities1 );
01384 free( temp_entities2 );
01385 free( types );
01386 free( regions );
01387 free( parents );
01388 return FALSE;
01389 }
01390
01391 /*--------test modify and query functions----------------------------- */
01392
01393 /* get all entity sets in super set */
01394 es_array1 = NULL;
01395 es_array1_alloc = 0;
01396 iMesh_getEntSets( mesh, super_set, 0, &es_array1, &es_array1_alloc, &es_array1_size, &result );
01397 if( iBase_SUCCESS != result )
01398 {
01399 printf( "Problem to get entity sets in super set.\n" );
01400 free( edges );
01401 free( faces );
01402 free( temp_entities1 );
01403 free( temp_entities2 );
01404 free( types );
01405 free( regions );
01406 free( parents );
01407 return FALSE;
01408 }
01409
01410 /* get the number of entity sets in super set */
01411 iMesh_getNumEntSets( mesh, super_set, 0, &num_super, &result );
01412 if( iBase_SUCCESS != result )
01413 {
01414 printf( "Problem to get the number of all entity sets in super set.\n" );
01415 free( edges );
01416 free( faces );
01417 free( temp_entities1 );
01418 free( temp_entities2 );
01419 free( types );
01420 free( regions );
01421 free( parents );
01422 free( es_array1 );
01423 return FALSE;
01424 }
01425
01426 /* the number of entity sets in super set should be same */
01427 if( num_super != es_array1_size )
01428 {
01429 printf( "the number of entity sets in super set should be same.\n" );
01430 return FALSE;
01431 }
01432
01433 /* get all entities in super set */
01434 all_entities = NULL;
01435 all_entities_alloc = 0;
01436 iMesh_getEntities( mesh, super_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, &all_entities, &all_entities_alloc,
01437 &all_entities_size, &result );
01438 if( iBase_SUCCESS != result )
01439 {
01440 printf( "Problem to get all entities in super set.\n" );
01441 free( edges );
01442 free( faces );
01443 free( temp_entities1 );
01444 free( temp_entities2 );
01445 free( types );
01446 free( regions );
01447 free( parents );
01448 free( es_array1 );
01449 return FALSE;
01450 }
01451
01452 /* compare the number of all entities in super set */
01453 /* NOTE: TEST COMMENTED OUT UNTIL RESOLUTION OF WHETHER GETENTITIES */
01454 /* SHOULD GET A NUM_HOPS ARGUMENT */
01455 /* if (num_all_entities_super != all_entities_size) { */
01456 /* printf("number of all entities in super set should be same.\n"); */
01457 /* return FALSE; */
01458 /* } */
01459
01460 /* test add, remove and get all entity sets using super set */
01461 /* check GetAllEntitySets works recursively and dosen't return */
01462 /* multi sets */
01463 for( k = 0; k < num_super; k++ )
01464 {
01465 /* add entity sets of super set to each entity set of super set */
01466 /* make multiple child super sets */
01467 iBase_EntitySetHandle es_k = es_array1[k];
01468 for( l = 0; l < es_array1_size; l++ )
01469 {
01470 iMesh_addEntSet( mesh, es_array1[l], es_k, &result );
01471 if( iBase_SUCCESS != result )
01472 {
01473 printf( "Problem to add entity set to entityset.\n" );
01474 free( edges );
01475 free( faces );
01476 free( temp_entities1 );
01477 free( temp_entities2 );
01478 free( types );
01479 free( regions );
01480 free( parents );
01481 free( es_array1 );
01482 free( all_entities );
01483 return FALSE;
01484 }
01485 }
01486
01487 /* add super set to each entity set */
01488 iMesh_addEntSet( mesh, super_set, es_k, &result );
01489 if( iBase_SUCCESS != result )
01490 {
01491 printf( "Problem to add super set to entitysets.\n" );
01492 free( edges );
01493 free( faces );
01494 free( temp_entities1 );
01495 free( temp_entities2 );
01496 free( types );
01497 free( regions );
01498 free( parents );
01499 free( es_array1 );
01500 free( all_entities );
01501 return FALSE;
01502 }
01503
01504 /* add one entity sets multiple times */
01505 for( l = 0; l < 3; l++ )
01506 {
01507 iMesh_addEntSet( mesh, temp_es1, es_k, &result );
01508 if( iBase_SUCCESS != result )
01509 {
01510 printf( "Problem to add temp set to entitysets.\n" );
01511 free( edges );
01512 free( faces );
01513 free( temp_entities1 );
01514 free( temp_entities2 );
01515 free( types );
01516 free( regions );
01517 free( parents );
01518 free( es_array1 );
01519 free( all_entities );
01520 return FALSE;
01521 }
01522 }
01523 }
01524
01525 /* get all hexes and get faces of that hexes */
01526 hexes = NULL;
01527 hexes_alloc = 0;
01528
01529 iMesh_getEntities( mesh, root_set, iBase_ALL_TYPES, iMesh_HEXAHEDRON, &hexes, &hexes_alloc, &hexes_size, &result );
01530 if( iBase_SUCCESS != result )
01531 {
01532 printf( "Failed to get hexes in entity_sets_test.\n" );
01533 free( edges );
01534 free( faces );
01535 free( temp_entities1 );
01536 free( temp_entities2 );
01537 free( types );
01538 free( regions );
01539 free( parents );
01540 free( es_array1 );
01541 free( all_entities );
01542 return FALSE;
01543 }
01544
01545 /* get adjacent face of hexes */
01546 adj_faces = NULL;
01547 adj_faces_alloc = 0;
01548 face_offsets = NULL;
01549 face_offsets_alloc = 0;
01550
01551 iMesh_getEntArrAdj( mesh, hexes, hexes_size, iBase_FACE, &adj_faces, &adj_faces_alloc, &adj_faces_size,
01552 &face_offsets, &face_offsets_alloc, &face_offsets_size, &result );
01553 if( iBase_SUCCESS != result )
01554 {
01555 printf( "Problem to get adjacent entities in entitysets_test.\n" );
01556 free( edges );
01557 free( faces );
01558 free( temp_entities1 );
01559 free( temp_entities2 );
01560 free( types );
01561 free( regions );
01562 free( parents );
01563 free( es_array1 );
01564 free( all_entities );
01565 free( hexes );
01566 return FALSE;
01567 }
01568
01569 iMesh_createEntSet( mesh, FALSE, &hex_set, &result );
01570 if( iBase_SUCCESS != result )
01571 {
01572 printf( "Problem creating entityset in entity_sets_test.\n" );
01573 free( edges );
01574 free( faces );
01575 free( temp_entities1 );
01576 free( temp_entities2 );
01577 free( types );
01578 free( regions );
01579 free( parents );
01580 free( es_array1 );
01581 free( all_entities );
01582 free( hexes );
01583 free( adj_faces );
01584 free( face_offsets );
01585 return FALSE;
01586 }
01587
01588 iMesh_addEntArrToSet( mesh, hexes, hexes_size, hex_set, &result );
01589 if( iBase_SUCCESS != result )
01590 {
01591 printf( "Failed to add hexes in entity_sets_test.\n" );
01592 free( edges );
01593 free( faces );
01594 free( temp_entities1 );
01595 free( temp_entities2 );
01596 free( types );
01597 free( regions );
01598 free( parents );
01599 free( es_array1 );
01600 free( all_entities );
01601 free( hexes );
01602 free( adj_faces );
01603 free( face_offsets );
01604 return FALSE;
01605 }
01606
01607 free( edges );
01608 free( faces );
01609 free( temp_entities1 );
01610 free( temp_entities2 );
01611 free( types );
01612 free( regions );
01613 free( parents );
01614 free( es_array1 );
01615 free( all_entities );
01616 free( hexes );
01617 free( adj_faces );
01618 free( face_offsets );
01619
01620 return TRUE;
01621 }
01622
01623 int check_esets( iMesh_Instance mesh, const int num_sets )
01624 {
01625 int entity_sets_size;
01626
01627 int result;
01628 iMesh_getNumEntSets( mesh, root_set, 1, &entity_sets_size, &result );
01629 if( iBase_SUCCESS != result )
01630 {
01631 printf( "Problem to get all entity sets in mesh.\n" );
01632 return FALSE;
01633 }
01634 if( entity_sets_size != num_sets )
01635 {
01636 printf( "the number of entity sets in whole mesh should be %d"
01637 ", actual number is %d.\n",
01638 num_sets, entity_sets_size );
01639 return FALSE;
01640 }
01641
01642 return TRUE;
01643 }
01644
01645 /*!
01646 @test
01647 TSTT entity sets Test
01648 @li Check entity sets
01649 */
01650 int entity_sets_test( iMesh_Instance mesh )
01651 {
01652 int iter_num = 0, result;
01653 /* check */
01654 int i;
01655 for( i = 0; i < 2; i++ )
01656 {
01657 iter_num++;
01658
01659 result = entity_sets_subtest( mesh, i, iter_num );
01660 if( !result ) return result;
01661 }
01662
01663 return TRUE;
01664 }
01665
01666 /*!
01667 @test
01668 Vertex Coordinates
01669 @li Get coordinates of vertices by 2 different methods then compare them
01670 */
01671 int vertex_coordinates_test( iMesh_Instance mesh )
01672 {
01673 iBase_EntityHandle* verts = NULL;
01674 int verts_alloc = 0, verts_size;
01675 double* vert_coords = NULL;
01676 int vert_coords_alloc = 0, vert_coords_size;
01677
01678 /* check storage order */
01679 int result;
01680 int this_order;
01681 iMesh_getDfltStorage( mesh, &this_order, &result );
01682 if( iBase_SUCCESS != result )
01683 {
01684 printf( "failed to get preferred storage order in vertex_coordinates_test.\n" );
01685 return FALSE;
01686 }
01687
01688 /* now get the vertex coordinates from a vertex array */
01689 /* need to get the vertices in the model */
01690 verts = NULL;
01691 verts_alloc = 0;
01692 iMesh_getEntities( mesh, root_set, iBase_VERTEX, iMesh_POINT, &verts, &verts_alloc, &verts_size, &result );
01693 if( iBase_SUCCESS != result )
01694 {
01695 printf( "failed to get entities in vertex_coordinates_test.\n" );
01696 return FALSE;
01697 }
01698
01699 /* get the coordinates in one array */
01700 vert_coords = NULL;
01701 vert_coords_alloc = 0;
01702
01703 iMesh_getVtxArrCoords( mesh, verts, verts_size, iBase_INTERLEAVED, &vert_coords, &vert_coords_alloc,
01704 &vert_coords_size, &result );
01705 if( iBase_SUCCESS != result )
01706 {
01707 printf( "failed to get vertex cooridinate of entities in vertex_coordinates_test.\n" );
01708 free( verts );
01709 return FALSE;
01710 }
01711
01712 free( verts );
01713 free( vert_coords );
01714
01715 /* if we get here, this test was successful */
01716 return TRUE;
01717 }
01718
01719 /*!
01720 @test
01721 TSTT Tag Info test
01722 @li Tests tagCreate, tagDelete, tagGetName, tagGetSize, tagGetHandle
01723 */
01724 int tag_info_test( iMesh_Instance mesh )
01725 {
01726 char dum_name[120];
01727 int dum_name_size = 120;
01728 int dum_size;
01729 int error = FALSE;
01730 iBase_TagHandle dum_handle;
01731 /* Create a tag */
01732 int result;
01733 iBase_TagHandle tag_handle = NULL;
01734 const char* tag_name = "int_tag";
01735 int tag_name_size = 8;
01736 iMesh_createTag( mesh, tag_name, 1, iBase_INTEGER, &tag_handle, &result, tag_name_size );
01737 if( iBase_SUCCESS != result )
01738 {
01739 printf( "Failed to create tag int_tag in vertex_tag_test." );
01740 return FALSE;
01741 }
01742
01743 /* check tag info functions */
01744 iMesh_getTagName( mesh, tag_handle, dum_name, &result, dum_name_size );
01745 if( iBase_SUCCESS != result )
01746 {
01747 printf( "Couldn't get name of tag just created.\n" );
01748 return FALSE;
01749 }
01750 if( strcmp( dum_name, "int_tag" ) != 0 )
01751 {
01752 printf( "Tag names didn't match.\n" );
01753 return FALSE;
01754 }
01755
01756 iMesh_getTagSizeBytes( mesh, tag_handle, &dum_size, &result );
01757 if( iBase_SUCCESS != result )
01758 {
01759 printf( "Couldn't get size of tag just created.\n" );
01760 return FALSE;
01761 }
01762 if( dum_size != sizeof( int ) )
01763 {
01764 printf( "Tag sizes didn't match.\n" );
01765 return FALSE;
01766 }
01767
01768 iMesh_getTagHandle( mesh, tag_name, &dum_handle, &result, tag_name_size );
01769 if( iBase_SUCCESS != result )
01770 {
01771 printf( "Couldn't get handle of tag just created.\n" );
01772 return FALSE;
01773 }
01774 if( dum_handle != tag_handle )
01775 {
01776 printf( "Tag handles didn't match.\n" );
01777 return FALSE;
01778 }
01779
01780 /* test non-forced version of tagDelete; forced version tested later, */
01781 /* when we have entities around */
01782 iMesh_destroyTag( mesh, tag_handle, FALSE, &result );
01783 if( iBase_SUCCESS != result )
01784 {
01785 printf( "Couldn't delete tag just created.\n" );
01786 return FALSE;
01787 }
01788
01789 /* look for that tag, to make sure it got deleted */
01790 iMesh_getTagHandle( mesh, tag_name, &tag_handle, &result, tag_name_size );
01791 if( iBase_SUCCESS != result )
01792 {
01793 error = TRUE;
01794 }
01795 if( !error )
01796 {
01797 printf( "tagGetHandle was able to find handle for deleted tag.\n" );
01798 return FALSE;
01799 }
01800
01801 return TRUE;
01802 }
01803
01804 int vertex_int_tag_test( iMesh_Instance mesh, iBase_EntityHandle* verts, int /*verts_size*/, iBase_TagHandle* int_tag )
01805 {
01806 int result;
01807 iBase_EntityHandle dum_vert = verts[0];
01808
01809 int dum_val = 11, dum_val2;
01810 void* dum_val2_ptr = &dum_val2;
01811 int dum_val2_alloc = sizeof( int ), dum_val2_size;
01812
01813 /* create a tag */
01814 const char* tag_name = "int_tag";
01815 int tag_name_size = 8;
01816 iMesh_createTag( mesh, tag_name, 1, iBase_INTEGER, int_tag, &result, tag_name_size );
01817 if( iBase_SUCCESS != result )
01818 {
01819 printf( "Failed to create tag int_tag in vertex_int_tag_test.\n" );
01820 return FALSE;
01821 }
01822
01823 /* put a value in the first vertex and retrieve */
01824 iMesh_setArrData( mesh, &dum_vert, 1, *int_tag, (const char*)( &dum_val ), sizeof( int ), &result );
01825 if( iBase_SUCCESS != result )
01826 {
01827 printf( "Failed to set int tag (val=11) in vertex_int_tag_test.\n" );
01828 return FALSE;
01829 }
01830
01831 iMesh_getArrData( mesh, &dum_vert, 1, *int_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result );
01832 if( iBase_SUCCESS != result || dum_val2 != 11 )
01833 {
01834 printf( "Failed to get int tag (val=11) in vertex_int_tag_test.\n" );
01835 return FALSE;
01836 }
01837
01838 if( dum_val2 != 11 )
01839 {
01840
01841 printf( "Value of vertex tag (val=11) wrong.\n" );
01842 return FALSE;
01843 }
01844
01845 /* put a value in the last vertex and retrieve */
01846 dum_val = 12;
01847
01848 iMesh_setArrData( mesh, &dum_vert, 1, *int_tag, (char*)( &dum_val ), sizeof( int ), &result );
01849 if( iBase_SUCCESS != result )
01850 {
01851 printf( "Failed to set int tag (val=12) in vertex_int_tag_test.\n" );
01852 return FALSE;
01853 }
01854
01855 iMesh_getArrData( mesh, &dum_vert, 1, *int_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result );
01856 if( iBase_SUCCESS != result )
01857 {
01858 printf( "Failed to get int tag (val=12) in vertex_int_tag_test.\n" );
01859 return FALSE;
01860 }
01861
01862 if( dum_val2 != 12 )
01863 {
01864
01865 printf( "Value of vertex tag (val=12) wrong.\n" );
01866 return FALSE;
01867 }
01868
01869 /* ok, the int tag test worked */
01870 return TRUE;
01871 }
01872
01873 int vertex_double_tag_test( iMesh_Instance mesh,
01874 iBase_EntityHandle* verts,
01875 int /*verts_size*/,
01876 iBase_TagHandle* double_tag )
01877 {
01878 int result;
01879
01880 iBase_EntityHandle dum_vert = verts[0];
01881 double dum_val = 1.0e6, dum_val2;
01882 void* dum_val2_ptr = &dum_val2;
01883 int dum_val2_alloc = sizeof( double ), dum_val2_size;
01884
01885 /* create a tag */
01886 const char* tag_name = "double_tag";
01887 int tag_name_size = 11;
01888 iMesh_createTag( mesh, tag_name, 1, iBase_DOUBLE, double_tag, &result, tag_name_size );
01889 if( iBase_SUCCESS != result )
01890 {
01891 printf( "Failed to create tag double_tag in vertex_double_tag_test.\n" );
01892 return FALSE;
01893 }
01894
01895 /* put a value in the first vertex and retrieve */
01896 iMesh_setArrData( mesh, &dum_vert, 1, *double_tag, (char*)( &dum_val ), sizeof( double ), &result );
01897 if( iBase_SUCCESS != result )
01898 {
01899 printf( "Failed to set double tag (val=1.0e6) in vertex_double_tag_test.\n" );
01900 return FALSE;
01901 }
01902
01903 iMesh_getArrData( mesh, &dum_vert, 1, *double_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result );
01904 if( iBase_SUCCESS != result )
01905 {
01906 printf( "Failed to get double tag (val=1.0e6) in vertex_double_tag_test.\n" );
01907 return FALSE;
01908 }
01909
01910 if( dum_val2 != 1.0e6 )
01911 {
01912 printf( "Value of vertex tag (val=1.0e6) wrong.\n" );
01913 return FALSE;
01914 }
01915
01916 /* put a value in the last vertex and retrieve */
01917 dum_val = 2.0e9;
01918
01919 iMesh_setArrData( mesh, &dum_vert, 1, *double_tag, (char*)( &dum_val ), sizeof( double ), &result );
01920 if( iBase_SUCCESS != result )
01921 {
01922 printf( "Failed to set double tag (val=2.0e9) in vertex_double_tag_test.\n" );
01923 return FALSE;
01924 }
01925
01926 iMesh_getArrData( mesh, &dum_vert, 1, *double_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result );
01927 if( iBase_SUCCESS != result )
01928 {
01929 printf( "Failed to get double tag (val=2.0e9) in vertex_double_tag_test.\n" );
01930 return FALSE;
01931 }
01932
01933 if( dum_val2 != 2.0e9 )
01934 {
01935 printf( "Value of vertex tag (val=2.0e9) wrong.\n" );
01936 return FALSE;
01937 }
01938
01939 /* ok, the double tag test worked */
01940 return TRUE;
01941 }
01942
01943 /* Add a struct Vertex Tag to the database */
01944 struct TagStruct
01945 {
01946 double test_double;
01947 int test_int1, test_int2;
01948 };
01949
01950 int vertex_struct_tag_test( iMesh_Instance mesh,
01951 iBase_EntityHandle* verts,
01952 int /*verts_size*/,
01953 iBase_TagHandle* struct_tag )
01954 {
01955 int result;
01956 iBase_EntityHandle dum_vert = verts[0];
01957 struct TagStruct dum_struct = { 3.0e12, 2, 3 }, dum_struct2;
01958 void* dum_struct2_ptr = &dum_struct2;
01959 int dum_struct_alloc = sizeof( struct TagStruct ), dum_struct_size;
01960
01961 /* create a tag */
01962 const char* tag_name = "struct_tag";
01963 int tag_name_size = 11;
01964 iMesh_createTag( mesh, tag_name, sizeof( struct TagStruct ), iBase_BYTES, struct_tag, &result, tag_name_size );
01965 if( iBase_SUCCESS != result )
01966 {
01967 printf( "Failed to create tag struct_tag in vertex_struct_tag_test.\n" );
01968 return FALSE;
01969 }
01970
01971 /* put a value in the first vertex and retrieve */
01972
01973 /* careful setting the value, since tags are opaque */
01974 iMesh_setArrData( mesh, &dum_vert, 1, *struct_tag, (const char*)&dum_struct, sizeof( struct TagStruct ), &result );
01975 if( iBase_SUCCESS != result )
01976 {
01977 printf( "Failed to set struct tag in vertex_struct_tag_test.\n" );
01978 return FALSE;
01979 }
01980
01981 iMesh_getArrData( mesh, &dum_vert, 1, *struct_tag, &dum_struct2_ptr, &dum_struct_alloc, &dum_struct_size, &result );
01982 if( iBase_SUCCESS != result )
01983 {
01984 printf( "Failed to get struct tag in vertex_struct_tag_test.\n" );
01985 return FALSE;
01986 }
01987
01988 if( dum_struct_size != sizeof( struct TagStruct ) )
01989 {
01990 printf( "Size of vertex struct tag wrong.\n" );
01991 return FALSE;
01992 }
01993 if( dum_struct2.test_int1 != dum_struct.test_int1 || dum_struct2.test_int2 != dum_struct.test_int2 ||
01994 dum_struct2.test_double != dum_struct.test_double )
01995 {
01996 printf( "Value of vertex struct tag wrong.\n" );
01997 return FALSE;
01998 }
01999
02000 /* ok, the int tag test worked */
02001 return TRUE;
02002 }
02003
02004 int vertex_tag_delete_test( iMesh_Instance mesh, iBase_EntityHandle* verts, int /*verts_size*/ )
02005 {
02006 int result;
02007 int delete_err = FALSE;
02008
02009 /* test forced, unforced deletion of tags from entities */
02010
02011 /* test getAlliBase_TagHandles for first entity */
02012 iBase_TagHandle* all_tags = NULL;
02013 iBase_EntityHandle dum_entity = verts[0];
02014 int all_tags_alloc = 0, all_tags_size;
02015 iMesh_getAllTags( mesh, verts[0], &all_tags, &all_tags_alloc, &all_tags_size, &result );
02016 if( iBase_SUCCESS != result )
02017 {
02018 printf( "Couldn't get all tag handles from vertex.\n" );
02019 return FALSE;
02020 }
02021
02022 iMesh_rmvArrTag( mesh, &dum_entity, 1, all_tags[0], &result );
02023 if( iBase_SUCCESS != result )
02024 {
02025 printf( "Couldn't remove tag from vertex.\n" );
02026 free( all_tags );
02027 return FALSE;
02028 }
02029
02030 iMesh_destroyTag( mesh, all_tags[1], FALSE, &result );
02031 if( iBase_SUCCESS != result )
02032 {
02033 delete_err = TRUE;
02034 }
02035 if( !delete_err )
02036 {
02037 printf( "Error when unforced-deleting tag in use on a vertex.\n" );
02038 free( all_tags );
02039 return FALSE;
02040 }
02041
02042 iMesh_destroyTag( mesh, all_tags[1], TRUE, &result );
02043 if( iBase_SUCCESS != result )
02044 {
02045 printf( "Couldn't force-delete a tag in use on a vertex.\n" );
02046 free( all_tags );
02047 return FALSE;
02048 }
02049
02050 free( all_tags );
02051
02052 /* ok, we're done */
02053 return TRUE;
02054 }
02055
02056 int vertex_tag_test( iMesh_Instance mesh )
02057 {
02058 int result;
02059
02060 iBase_TagHandle int_tag, double_tag, struct_tag;
02061 int int_err, double_err, struct_err, tag_delete_err;
02062
02063 int info_err = tag_info_test( mesh );
02064
02065 /* get all the vertices */
02066 iBase_EntityHandle* verts = NULL;
02067 int verts_alloc = 0, verts_size;
02068 iMesh_getEntities( mesh, root_set, iBase_ALL_TYPES, iMesh_POINT, &verts, &verts_alloc, &verts_size, &result );
02069 if( iBase_SUCCESS != result )
02070 {
02071 printf( "entitysetGetEntities failed in vertex_tag_test.\n" );
02072 return FALSE;
02073 }
02074
02075 /* vertex int tag */
02076 int_err = vertex_int_tag_test( mesh, verts, verts_size, &int_tag );
02077
02078 /* vertex double tag */
02079 double_err = vertex_double_tag_test( mesh, verts, verts_size, &double_tag );
02080
02081 /* vertex struct tag */
02082 struct_err = vertex_struct_tag_test( mesh, verts, verts_size, &struct_tag );
02083
02084 tag_delete_err = vertex_tag_delete_test( mesh, verts, verts_size );
02085
02086 free( verts );
02087
02088 return ( info_err && int_err && double_err && struct_err && tag_delete_err );
02089 }
02090
02091 int entityset_int_tag_test( iMesh_Instance mesh, iBase_EntitySetHandle* sets, int sets_size, iBase_TagHandle* int_tag )
02092 {
02093 int result;
02094 int dum_val = 11, dum_val2;
02095 void* dum_val2_ptr = &dum_val2;
02096 int dum_val2_alloc = sizeof( int ), dum_val2_size;
02097
02098 /* create a tag */
02099 const char* tag_name = "set_int_tag";
02100 iMesh_createTag( mesh, tag_name, 1, iBase_INTEGER, int_tag, &result, 12 );
02101 if( iBase_SUCCESS != result )
02102 {
02103 printf( "Failed to create tag int_tag in entityset_int_tag_test.\n" );
02104 return FALSE;
02105 }
02106
02107 /* put a value in the first set and retrieve */
02108
02109 iMesh_setEntSetData( mesh, sets[0], *int_tag, (char*)( &dum_val ), sizeof( int ), &result );
02110 if( iBase_SUCCESS != result )
02111 {
02112 printf( "Failed to set int tag (val=11) in entityset_int_tag_test.\n" );
02113 return FALSE;
02114 }
02115
02116 dum_val2 = 0;
02117 iMesh_getEntSetData( mesh, sets[0], *int_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result );
02118 if( iBase_SUCCESS != result )
02119 {
02120 printf( "Failed to get int tag (val=11) in entityset_int_tag_test." );
02121 return FALSE;
02122 }
02123
02124 if( dum_val2 != 11 )
02125 {
02126 printf( "Value of entityset tag (val=11) wrong.\n" );
02127 return FALSE;
02128 }
02129
02130 /* put a value in the last faces and retrieve */
02131 dum_val = 12;
02132 iMesh_setEntSetData( mesh, sets[sets_size - 1], *int_tag, (char*)( &dum_val ), sizeof( int ), &result );
02133 if( iBase_SUCCESS != result )
02134 {
02135 printf( "Failed to set int tag (val=12) in entityset_int_tag_test." );
02136 return FALSE;
02137 }
02138
02139 iMesh_getEntSetData( mesh, sets[sets_size - 1], *int_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result );
02140 if( iBase_SUCCESS != result )
02141 {
02142 printf( "Failed to get int tag (val=12) in entityset_int_tag_test." );
02143 return FALSE;
02144 }
02145
02146 if( dum_val2 != 12 )
02147 {
02148 printf( "Value of entityset tag (val=12) wrong.\n" );
02149 return FALSE;
02150 }
02151
02152 /* ok, the int tag test worked */
02153 return TRUE;
02154 }
02155
02156 int entityset_double_tag_test( iMesh_Instance mesh,
02157 iBase_EntitySetHandle* sets,
02158 int sets_size,
02159 iBase_TagHandle* double_tag )
02160 {
02161 int result;
02162 double dum_val = 1.0e6, dum_val2;
02163 void* dum_val2_ptr = &dum_val2;
02164 int dum_val2_alloc = sizeof( double ), dum_val2_size;
02165
02166 /* create a tag */
02167 const char* tag_name = "set_double_tag";
02168 iMesh_createTag( mesh, tag_name, 1, iBase_DOUBLE, double_tag, &result, 15 );
02169 if( iBase_SUCCESS != result )
02170 {
02171 printf( "Failed to create tag double_tag in entityset_double_tag_test.\n" );
02172 return FALSE;
02173 }
02174
02175 /* put a value in the first set and retrieve */
02176
02177 iMesh_setEntSetData( mesh, sets[0], *double_tag, (char*)( &dum_val ), sizeof( double ), &result );
02178 if( iBase_SUCCESS != result )
02179 {
02180 printf( "Failed to set double tag (val=11) in entityset_double_tag_test.\n" );
02181 return FALSE;
02182 }
02183
02184 dum_val2 = 0;
02185 iMesh_getEntSetData( mesh, sets[0], *double_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result );
02186 if( iBase_SUCCESS != result )
02187 {
02188 printf( "Failed to get double tag (val=1.0e6) in entityset_double_tag_test." );
02189 return FALSE;
02190 }
02191
02192 if( dum_val2 != 1.0e6 )
02193 {
02194 printf( "Value of entityset tag (val=11) wrong.\n" );
02195 return FALSE;
02196 }
02197
02198 /* put a value in the last faces and retrieve */
02199 dum_val = 2.0e9;
02200 iMesh_setEntSetData( mesh, sets[sets_size - 1], *double_tag, (char*)( &dum_val ), sizeof( double ), &result );
02201 if( iBase_SUCCESS != result )
02202 {
02203 printf( "Failed to set double tag (val=2.0e9) in entityset_double_tag_test." );
02204 return FALSE;
02205 }
02206
02207 iMesh_getEntSetData( mesh, sets[sets_size - 1], *double_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size,
02208 &result );
02209 if( iBase_SUCCESS != result )
02210 {
02211 printf( "Failed to get double tag (val=2.0e9) in entityset_double_tag_test." );
02212 return FALSE;
02213 }
02214
02215 if( dum_val2 != 2.0e9 )
02216 {
02217 printf( "Value of entityset tag (val=2.0e9) wrong.\n" );
02218 return FALSE;
02219 }
02220
02221 /* ok, the double tag test worked */
02222 return TRUE;
02223 }
02224
02225 int entityset_struct_tag_test( iMesh_Instance mesh,
02226 iBase_EntitySetHandle* /*sets*/,
02227 int /*sets_size*/,
02228 iBase_TagHandle* struct_tag )
02229 {
02230 int result;
02231 struct TagStruct dum_struct = { 3.0e12, 2, 3 }, dum_struct2;
02232 void* dum_struct2_ptr = &dum_struct2;
02233 int dum_struct_alloc = sizeof( struct TagStruct ), dum_struct_size;
02234
02235 /* create a tag */
02236 const char* tag_name = "set_struct_tag";
02237 iMesh_createTag( mesh, tag_name, sizeof( struct TagStruct ), iBase_BYTES, struct_tag, &result, 11 );
02238 if( iBase_SUCCESS != result )
02239 {
02240 printf( "Failed to create tag struct_tag in entityset_struct_tag_test.\n" );
02241 return FALSE;
02242 }
02243
02244 /* put a value in the first vertex and retrieve */
02245
02246 /* careful setting the value, since tags are opaque */
02247 iMesh_setEntSetData( mesh, root_set, *struct_tag, (const char*)&dum_struct, sizeof( struct TagStruct ), &result );
02248 if( iBase_SUCCESS != result )
02249 {
02250 printf( "Failed to set struct tag in entityset_struct_tag_test.\n" );
02251 return FALSE;
02252 }
02253
02254 iMesh_getEntSetData( mesh, root_set, *struct_tag, &dum_struct2_ptr, &dum_struct_alloc, &dum_struct_size, &result );
02255 if( iBase_SUCCESS != result )
02256 {
02257 printf( "Failed to get struct tag in entityset_struct_tag_test.\n" );
02258 return FALSE;
02259 }
02260
02261 if( dum_struct_size != sizeof( struct TagStruct ) )
02262 {
02263 printf( "Size of entityset struct tag wrong.\n" );
02264 return FALSE;
02265 }
02266 if( dum_struct2.test_int1 != dum_struct.test_int1 || dum_struct2.test_int2 != dum_struct.test_int2 ||
02267 dum_struct2.test_double != dum_struct.test_double )
02268 {
02269 printf( "Value of entityset struct tag wrong.\n" );
02270 return FALSE;
02271 }
02272
02273 /* ok, the int tag test worked */
02274 return TRUE;
02275 }
02276
02277 int entityset_tag_delete_test( iMesh_Instance mesh, iBase_EntitySetHandle* sets, int sets_size )
02278 {
02279 /* test forced, unforced deletion of tags from entities */
02280 int result;
02281 int delete_err = FALSE;
02282
02283 /* test getAlliBase_TagHandles for first entity */
02284 iBase_TagHandle* all_tags = NULL;
02285 if( sets_size < 1 )
02286 {
02287 printf( "no sets.\n" );
02288 return FALSE;
02289 }
02290 iBase_EntitySetHandle dum_entity = sets[0];
02291 int all_tags_alloc = 0, all_tags_size;
02292 iMesh_getAllEntSetTags( mesh, sets[0], &all_tags, &all_tags_alloc, &all_tags_size, &result );
02293 if( iBase_SUCCESS != result )
02294 {
02295 printf( "Couldn't get all tag handles from entityset.\n" );
02296 free( all_tags );
02297 return FALSE;
02298 }
02299
02300 iMesh_rmvEntSetTag( mesh, dum_entity, all_tags[0], &result );
02301 if( iBase_SUCCESS != result )
02302 {
02303 printf( "Couldn't remove tag from entityset.\n" );
02304 free( all_tags );
02305 return FALSE;
02306 }
02307
02308 iMesh_destroyTag( mesh, all_tags[1], FALSE, &result );
02309 if( iBase_SUCCESS != result )
02310 {
02311 delete_err = TRUE;
02312 }
02313 if( !delete_err )
02314 {
02315 printf( "Error when unforced-deleting tag in use on a entityset.\n" );
02316 free( all_tags );
02317 return FALSE;
02318 }
02319
02320 iMesh_destroyTag( mesh, all_tags[1], TRUE, &result );
02321 if( iBase_SUCCESS != result )
02322 {
02323 printf( "Couldn't force-delete a tag in use on a entityset.\n" );
02324 free( all_tags );
02325 return FALSE;
02326 }
02327
02328 free( all_tags );
02329
02330 /* ok, we're done */
02331 return TRUE;
02332 }
02333
02334 /*!
02335 @test
02336 TSTT entityset tag Test
02337 @li Check entityset tags
02338 */
02339 int entityset_tag_test( iMesh_Instance mesh )
02340 {
02341 int result;
02342 iBase_TagHandle int_tag, double_tag, struct_tag;
02343 int int_success, double_success, struct_success, tag_delete_success;
02344
02345 /* get the sets */
02346 iBase_EntitySetHandle* esets = NULL;
02347 int esets_alloc = 0, esets_size;
02348 iMesh_getEntSets( mesh, root_set, 1, &esets, &esets_alloc, &esets_size, &result );
02349 if( iBase_SUCCESS != result )
02350 {
02351 printf( "entitysetGetEntities failed in entityset_tag_test.\n" );
02352 free( esets );
02353 return FALSE;
02354 }
02355
02356 /* entityset int tag */
02357 int_success = entityset_int_tag_test( mesh, esets, esets_size, &int_tag );
02358
02359 /* entityeset double tag */
02360 double_success = entityset_double_tag_test( mesh, esets, esets_size, &double_tag );
02361
02362 /* entityset struct tag */
02363 struct_success = entityset_struct_tag_test( mesh, esets, esets_size, &struct_tag );
02364
02365 tag_delete_success = entityset_tag_delete_test( mesh, esets, esets_size );
02366
02367 free( esets );
02368
02369 return ( int_success && double_success && struct_success && tag_delete_success );
02370 }
02371
02372 int mesh_int_tag_test( iMesh_Instance mesh, iBase_TagHandle* int_tag )
02373 {
02374 int result;
02375 int dum_val = 11, dum_val2;
02376 void* dum_val2_ptr = &dum_val2;
02377 int dum_val2_alloc = sizeof( int ), dum_val2_size;
02378
02379 /* create a tag */
02380 const char* tag_name = "mesh_int_tag";
02381 iMesh_createTag( mesh, tag_name, 1, iBase_INTEGER, int_tag, &result, 12 );
02382 if( iBase_SUCCESS != result )
02383 {
02384 printf( "Failed to create tag int_tag in mesh_int_tag_test.\n" );
02385 return FALSE;
02386 }
02387
02388 /* put a value in the first set and retrieve */
02389
02390 iMesh_setEntSetData( mesh, root_set, *int_tag, (char*)( &dum_val ), sizeof( int ), &result );
02391 if( iBase_SUCCESS != result )
02392 {
02393 printf( "Failed to set int tag (val=11) in mesh_int_tag_test.\n" );
02394 return FALSE;
02395 }
02396
02397 dum_val2 = 0;
02398 iMesh_getEntSetData( mesh, root_set, *int_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result );
02399 if( iBase_SUCCESS != result )
02400 {
02401 printf( "Failed to get int tag (val=11) in mesh_int_tag_test." );
02402 return FALSE;
02403 }
02404
02405 if( dum_val2 != 11 )
02406 {
02407 printf( "Value of entityset tag (val=11) wrong.\n" );
02408 return FALSE;
02409 }
02410
02411 /* put a value in the last faces and retrieve */
02412 dum_val = 12;
02413 iMesh_setEntSetData( mesh, root_set, *int_tag, (char*)( &dum_val ), sizeof( int ), &result );
02414 if( iBase_SUCCESS != result )
02415 {
02416 printf( "Failed to set int tag (val=12) in mesh_int_tag_test." );
02417 return FALSE;
02418 }
02419
02420 iMesh_getEntSetData( mesh, root_set, *int_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result );
02421 if( iBase_SUCCESS != result )
02422 {
02423 printf( "Failed to get int tag (val=12) in mesh_int_tag_test." );
02424 return FALSE;
02425 }
02426
02427 if( dum_val2 != 12 )
02428 {
02429 printf( "Value of entityset tag (val=12) wrong.\n" );
02430 return FALSE;
02431 }
02432
02433 /* ok, the int tag test worked */
02434 return TRUE;
02435 }
02436
02437 int mesh_double_tag_test( iMesh_Instance mesh, iBase_TagHandle* double_tag )
02438 {
02439 int result;
02440 double dum_val = 1.0e6, dum_val2;
02441 void* dum_val2_ptr = &dum_val2;
02442 int dum_val2_alloc = sizeof( double ), dum_val2_size;
02443
02444 /* create a tag */
02445 const char* tag_name = "mesh_double_tag";
02446 iMesh_createTag( mesh, tag_name, 1, iBase_DOUBLE, double_tag, &result, 15 );
02447 if( iBase_SUCCESS != result )
02448 {
02449 printf( "Failed to create tag double_tag in mesh_double_tag_test.\n" );
02450 return FALSE;
02451 }
02452
02453 /* put a value in the first set and retrieve */
02454
02455 iMesh_setEntSetData( mesh, root_set, *double_tag, (char*)( &dum_val ), sizeof( double ), &result );
02456 if( iBase_SUCCESS != result )
02457 {
02458 printf( "Failed to set double tag (val=11) in mesh_double_tag_test.\n" );
02459 return FALSE;
02460 }
02461
02462 dum_val2 = 0;
02463 iMesh_getEntSetData( mesh, root_set, *double_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result );
02464 if( iBase_SUCCESS != result )
02465 {
02466 printf( "Failed to get double tag (val=1.0e6) in mesh_double_tag_test." );
02467 return FALSE;
02468 }
02469
02470 if( dum_val2 != 1.0e6 )
02471 {
02472 printf( "Value of entityset tag (val=11) wrong.\n" );
02473 return FALSE;
02474 }
02475
02476 /* put a value in the last faces and retrieve */
02477 dum_val = 2.0e9;
02478 iMesh_setEntSetData( mesh, root_set, *double_tag, (char*)( &dum_val ), sizeof( double ), &result );
02479 if( iBase_SUCCESS != result )
02480 {
02481 printf( "Failed to set double tag (val=2.0e9) in mesh_double_tag_test." );
02482 return FALSE;
02483 }
02484
02485 iMesh_getEntSetData( mesh, root_set, *double_tag, &dum_val2_ptr, &dum_val2_alloc, &dum_val2_size, &result );
02486 if( iBase_SUCCESS != result )
02487 {
02488 printf( "Failed to get double tag (val=2.0e9) in mesh_double_tag_test." );
02489 return FALSE;
02490 }
02491
02492 if( dum_val2 != 2.0e9 )
02493 {
02494 printf( "Value of entityset tag (val=2.0e9) wrong.\n" );
02495 return FALSE;
02496 }
02497
02498 /* ok, the double tag test worked */
02499 return TRUE;
02500 }
02501
02502 int mesh_struct_tag_test( iMesh_Instance mesh, iBase_TagHandle* struct_tag )
02503 {
02504 int result;
02505 struct TagStruct dum_struct = { 3.0e12, 2, 3 }, dum_struct2;
02506 void* dum_struct2_ptr = &dum_struct2;
02507 int dum_struct_alloc = sizeof( struct TagStruct ), dum_struct_size;
02508
02509 /* create a tag */
02510 const char* tag_name = "mesh_struct_tag";
02511 iMesh_createTag( mesh, tag_name, sizeof( struct TagStruct ), iBase_BYTES, struct_tag, &result, 11 );
02512 if( iBase_SUCCESS != result )
02513 {
02514 printf( "Failed to create tag struct_tag in vertex_struct_tag_test.\n" );
02515 return FALSE;
02516 }
02517
02518 /* put a value in the first vertex and retrieve */
02519
02520 /* careful setting the value, since tags are opaque */
02521 iMesh_setEntSetData( mesh, root_set, *struct_tag, (const char*)&dum_struct, sizeof( struct TagStruct ), &result );
02522 if( iBase_SUCCESS != result )
02523 {
02524 printf( "Failed to set struct tag in mesh_struct_tag_test.\n" );
02525 return FALSE;
02526 }
02527
02528 iMesh_getEntSetData( mesh, root_set, *struct_tag, &dum_struct2_ptr, &dum_struct_alloc, &dum_struct_size, &result );
02529 if( iBase_SUCCESS != result )
02530 {
02531 printf( "Failed to get struct tag in mesh_struct_tag_test.\n" );
02532 return FALSE;
02533 }
02534
02535 if( dum_struct_size != sizeof( struct TagStruct ) )
02536 {
02537 printf( "Size of entityset struct tag wrong.\n" );
02538 return FALSE;
02539 }
02540 if( dum_struct2.test_int1 != dum_struct.test_int1 || dum_struct2.test_int2 != dum_struct.test_int2 ||
02541 dum_struct2.test_double != dum_struct.test_double )
02542 {
02543 printf( "Value of entityset struct tag wrong.\n" );
02544 return FALSE;
02545 }
02546
02547 /* ok, the int tag test worked */
02548 return TRUE;
02549 }
02550
02551 int mesh_tag_delete_test( iMesh_Instance mesh )
02552 {
02553 /* test forced, unforced deletion of tags from entities */
02554 int result;
02555 int delete_err = FALSE;
02556
02557 /* test getAlliBase_TagHandles for first entity */
02558 iBase_TagHandle* all_tags = NULL;
02559 int all_tags_alloc = 0, all_tags_size;
02560 iMesh_getAllEntSetTags( mesh, root_set, &all_tags, &all_tags_alloc, &all_tags_size, &result );
02561 if( iBase_SUCCESS != result )
02562 {
02563 printf( "Couldn't get all tag handles from entityset.\n" );
02564 return FALSE;
02565 }
02566
02567 iMesh_rmvEntSetTag( mesh, root_set, all_tags[0], &result );
02568 if( iBase_SUCCESS != result )
02569 {
02570 printf( "Couldn't remove tag from entityset.\n" );
02571 free( all_tags );
02572 return FALSE;
02573 }
02574
02575 iMesh_destroyTag( mesh, all_tags[1], FALSE, &result );
02576 if( iBase_SUCCESS != result )
02577 {
02578 delete_err = TRUE;
02579 }
02580 if( !delete_err )
02581 {
02582 printf( "Error when unforced-deleting tag in use on a entityset.\n" );
02583 free( all_tags );
02584 return FALSE;
02585 }
02586
02587 iMesh_destroyTag( mesh, all_tags[1], TRUE, &result );
02588 if( iBase_SUCCESS != result )
02589 {
02590 printf( "Couldn't force-delete a tag in use on a entityset.\n" );
02591 free( all_tags );
02592 return FALSE;
02593 }
02594
02595 free( all_tags );
02596
02597 /* ok, we're done */
02598 return TRUE;
02599 }
02600
02601 /*!
02602 @test
02603 TSTT entityset tag Test
02604 @li Check entityset tags
02605 */
02606 int mesh_tag_test( iMesh_Instance mesh )
02607 {
02608 iBase_TagHandle int_tag, double_tag, struct_tag;
02609
02610 /* entityset int tag */
02611 int int_success = mesh_int_tag_test( mesh, &int_tag );
02612
02613 /* entityeset double tag */
02614 int double_success = mesh_double_tag_test( mesh, &double_tag );
02615
02616 /* entityset struct tag */
02617 int struct_success = mesh_struct_tag_test( mesh, &struct_tag );
02618
02619 int tag_delete_success = mesh_tag_delete_test( mesh );
02620
02621 return ( int_success && double_success && struct_success && tag_delete_success );
02622 }
02623
02624 int set_remove_contained_regression( iMesh_Instance mesh )
02625 {
02626 int err, contained;
02627 iBase_EntitySetHandle set, sub;
02628
02629 iMesh_createEntSet( mesh, 0, &set, &err );
02630 if( iBase_SUCCESS != err ) return 0;
02631 iMesh_createEntSet( mesh, 1, &sub, &err );
02632 if( iBase_SUCCESS != err ) return 0;
02633
02634 iMesh_addEntSet( mesh, sub, set, &err );
02635 if( iBase_SUCCESS != err ) return 0;
02636
02637 iMesh_isEntSetContained( mesh, set, sub, &contained, &err );
02638 if( iBase_SUCCESS != err ) return 0;
02639 if( !contained )
02640 {
02641 fprintf( stderr, "isEntSetContained returned false for contained set\n" );
02642 return 0;
02643 }
02644
02645 iMesh_rmvEntSet( mesh, sub, set, &err );
02646 if( iBase_SUCCESS != err ) return 0;
02647
02648 iMesh_isEntSetContained( mesh, set, sub, &contained, &err );
02649 if( iBase_SUCCESS != err ) return 0;
02650 if( contained )
02651 {
02652 fprintf( stderr, "isEntSetContained returned true for removed set\n" );
02653 return 0;
02654 }
02655
02656 return 1;
02657 }
02658
02659 int all_adjacency_regression( iMesh_Instance mesh )
02660 {
02661 int err;
02662
02663 double coords[] = { 0, 0, 0, 1, 1, 1 };
02664
02665 iBase_EntityHandle* verts = NULL;
02666 int verts_alloc = 0, verts_size;
02667
02668 iBase_EntityHandle line;
02669 int status;
02670
02671 iBase_EntityHandle* adj = NULL;
02672 int adj_alloc = 0, adj_size;
02673
02674 iMesh_newMesh( "", &mesh, &err, 0 );
02675 if( iBase_SUCCESS != err ) return 0;
02676
02677 iMesh_createVtxArr( mesh, 2, iBase_INTERLEAVED, coords, 6, &verts, &verts_alloc, &verts_size, &err );
02678 if( iBase_SUCCESS != err ) return 0;
02679
02680 iMesh_createEnt( mesh, iMesh_LINE_SEGMENT, verts, 2, &line, &status, &err );
02681 if( iBase_SUCCESS != err || status != iBase_NEW ) return 0;
02682
02683 iMesh_getEntAdj( mesh, verts[0], iBase_ALL_TYPES, &adj, &adj_alloc, &adj_size, &err );
02684 if( iBase_SUCCESS != err ) return 0;
02685 if( adj_size != 1 || adj[0] != line )
02686 {
02687 printf( "Bad: couldn't find adjacency for vertex\n" );
02688 return 0;
02689 }
02690 free( adj );
02691
02692 adj_alloc = 0;
02693 adj = NULL;
02694 iMesh_getEntAdj( mesh, line, iBase_ALL_TYPES, &adj, &adj_alloc, &adj_size, &err );
02695 if( iBase_SUCCESS != err ) return 0;
02696 if( adj_size != 2 ||
02697 ( ( adj[0] != verts[0] || adj[1] != verts[1] ) && ( adj[0] != verts[1] || adj[1] != verts[0] ) ) )
02698 {
02699 printf( "Bad: couldn't find adjacencies for line\n" );
02700 free( adj );
02701 free( verts );
02702 return 0;
02703 }
02704 free( adj );
02705 free( verts );
02706 iMesh_dtor( mesh, &err );
02707 if( iBase_SUCCESS != err ) return 0;
02708 return 1;
02709 }
02710
02711 static int ordered_set_regression( iMesh_Instance mesh )
02712 {
02713 double coords[] = { 0, 0, 0, 1, 1, 1 };
02714 iBase_EntityHandle line, *p, verts[2], ents_in[3], ents_out[3];
02715 iBase_EntitySetHandle set;
02716 int i, err, status, two = 2, three = 3;
02717
02718 iMesh_newMesh( "", &mesh, &err, 0 );
02719 CHK( err );
02720 p = verts;
02721 iMesh_createVtxArr( mesh, 2, iBase_INTERLEAVED, coords, 6, &p, &two, &two, &err );
02722 CHK( err );
02723 iMesh_createEnt( mesh, iMesh_LINE_SEGMENT, verts, 2, &line, &status, &err );
02724 CHK( err );
02725 if( status != iBase_NEW ) return 0;
02726 iMesh_createEntSet( mesh, 1, &set, &err );
02727 CHK( err );
02728 ents_in[0] = verts[1];
02729 ents_in[1] = line;
02730 ents_in[2] = verts[0];
02731 iMesh_addEntArrToSet( mesh, ents_in, three, set, &err );
02732 CHK( err );
02733 p = ents_out;
02734 iMesh_getEntities( mesh, set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, &p, &three, &three, &err );
02735 CHK( err );
02736 for( i = 0; i < three; i++ )
02737 {
02738 if( ents_in[i] != ents_out[i] )
02739 {
02740 printf( "Ordered set does not preserve order\n" );
02741 return 0;
02742 }
02743 }
02744 iMesh_dtor( mesh, &err );
02745 CHK( err );
02746 return 1;
02747 }
02748
02749 int array_allocation( iMesh_Instance mesh )
02750 {
02751 int err;
02752
02753 double coords[] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3 };
02754
02755 iBase_EntityHandle* verts = NULL;
02756 int verts_alloc = 0, verts_size;
02757
02758 iBase_EntityHandle* ents;
02759 int ents_alloc, ents_size;
02760
02761 iMesh_newMesh( "", &mesh, &err, 0 );
02762 if( iBase_SUCCESS != err ) return 0;
02763
02764 iMesh_getRootSet( mesh, &root_set, &err );
02765 if( iBase_SUCCESS != err )
02766 {
02767 printf( "Failed to return a root set.\n" );
02768 return 0;
02769 }
02770
02771 iMesh_createVtxArr( mesh, 4, iBase_INTERLEAVED, coords, 12, &verts, &verts_alloc, &verts_size, &err );
02772 if( iBase_SUCCESS != err ) return 0;
02773
02774 free( verts );
02775
02776 /* test for proper allocation when array pointer passed in null but alloc'd size not */
02777 ents_alloc = 3;
02778 ents = NULL;
02779 iMesh_getEntities( mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, &ents, &ents_alloc, &ents_size, &err );
02780 CHK( err );
02781
02782 free( ents );
02783
02784 /* test for proper allocation when array pointer passed in non-null but alloc'd size 0 */
02785 ents_alloc = 0;
02786 iMesh_getEntities( mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, &ents, &ents_alloc, &ents_size, &err );
02787 CHK( err );
02788
02789 free( ents );
02790
02791 /* test for failure when passed in alloc'd size is smaller than it should be */
02792 ents_alloc -= 1;
02793 iMesh_getEntities( mesh, root_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, &ents, &ents_alloc, &ents_size, &err );
02794 if( iBase_BAD_ARRAY_SIZE != err && iBase_BAD_ARRAY_DIMENSION != err )
02795 {
02796 err = iBase_FAILURE;
02797 CHK( err );
02798 }
02799
02800 iMesh_dtor( mesh, &err );
02801 CHK( err );
02802
02803 return 1;
02804 }
02805
02806 int compare_single_iter( const char* info,
02807 iMesh_Instance mesh,
02808 iBase_EntitySetHandle set,
02809 iBase_EntityHandle* contents,
02810 int contents_size,
02811 enum iBase_EntityType type,
02812 enum iMesh_EntityTopology topo )
02813 {
02814 iBase_EntityIterator iter = 0;
02815 int i, twice, has_data, result = iBase_SUCCESS, result2;
02816 iBase_EntityHandle value;
02817
02818 iMesh_initEntIter( mesh, set, type, topo, 0, &iter, &result );
02819 if( iBase_SUCCESS != result )
02820 {
02821 printf( "%s:%d: Error %d initializing %s iterator for type %d/topo %d\n", __FILE__, __LINE__, result, info,
02822 (int)type, (int)topo );
02823 return result;
02824 }
02825
02826 for( twice = 0; twice < 2; ++twice )
02827 {
02828
02829 for( i = 0; i < contents_size; ++i )
02830 {
02831 iMesh_getNextEntIter( mesh, iter, &value, &has_data, &result );
02832 if( iBase_SUCCESS != result )
02833 {
02834 printf( "%s:%d: Error %d stepping %s iterator for type %d/topo %d\n", __FILE__, __LINE__, result, info,
02835 (int)type, (int)topo );
02836 goto end_single_iter;
02837 }
02838
02839 if( !has_data )
02840 {
02841 printf( "%s:%d: %s iterator for type %d/topo %d ended prematurely at %d of %d\n", __FILE__, __LINE__,
02842 info, (int)type, (int)topo, i, contents_size );
02843 result = iBase_FAILURE;
02844 goto end_single_iter;
02845 }
02846
02847 if( value != contents[i] )
02848 {
02849 printf( "%s:%d: %s iterator for type %d/topo %d returned incorrect value at %d of %d\n", __FILE__,
02850 __LINE__, info, (int)type, (int)topo, i, contents_size );
02851 result = iBase_FAILURE;
02852 goto end_single_iter;
02853 }
02854 }
02855
02856 iMesh_getNextEntIter( mesh, iter, &value, &has_data, &result );
02857 if( iBase_SUCCESS != result )
02858 {
02859 printf( "%s:%d: Error %d stepping %s iterator for type %d/topo %d\n", __FILE__, __LINE__, result, info,
02860 (int)type, (int)topo );
02861 goto end_single_iter;
02862 }
02863
02864 if( has_data )
02865 {
02866 printf( "%s:%d: %s iterator for type %d/topo %d did not end after %d values\n", __FILE__, __LINE__, info,
02867 (int)type, (int)topo, contents_size );
02868 result = iBase_FAILURE;
02869 goto end_single_iter;
02870 }
02871
02872 iMesh_resetEntIter( mesh, iter, &result );
02873 if( iBase_SUCCESS != result )
02874 {
02875 printf( "%s:%d: Error %d resetting %s iterator for type %d/topo %d\n", __FILE__, __LINE__, result, info,
02876 (int)type, (int)topo );
02877 result = iBase_FAILURE;
02878 goto end_single_iter;
02879 }
02880 }
02881
02882 end_single_iter:
02883 iMesh_endEntIter( mesh, iter, &result2 );
02884 if( iBase_SUCCESS != result2 )
02885 {
02886 printf( "%s:%d: Error %d releasing %s iterator for type %d/topo %d\n", __FILE__, __LINE__, result, info,
02887 (int)type, (int)topo );
02888 if( iBase_SUCCESS == result ) result = result2;
02889 }
02890 return result;
02891 }
02892
02893 int compare_array_iter( const char* info,
02894 iMesh_Instance mesh,
02895 iBase_EntitySetHandle set,
02896 iBase_EntityHandle* contents,
02897 int contents_size,
02898 int array_size,
02899 enum iBase_EntityType type,
02900 enum iMesh_EntityTopology topo )
02901 {
02902 iBase_EntityArrIterator iter = 0;
02903 int i, j, twice, has_data, result = iBase_SUCCESS, result2;
02904 iBase_EntityHandle* values;
02905 int values_size, values_alloc = array_size;
02906 values = (iBase_EntityHandle*)malloc( array_size * sizeof( iBase_EntityHandle ) );
02907
02908 iMesh_initEntArrIter( mesh, set, type, topo, array_size, 0, &iter, &result );
02909 if( iBase_SUCCESS != result )
02910 {
02911 printf( "%s:%d: Error %d initializing %s array iterator for type %d/topo %d\n", __FILE__, __LINE__, result,
02912 info, (int)type, (int)topo );
02913 free( values );
02914 return result;
02915 }
02916
02917 for( twice = 0; twice < 2; ++twice )
02918 {
02919 i = 0;
02920 while( i < contents_size )
02921 {
02922
02923 iMesh_getNextEntArrIter( mesh, iter, &values, &values_alloc, &values_size, &has_data, &result );
02924 if( iBase_SUCCESS != result )
02925 {
02926 printf( "%s:%d: Error %d stepping %s array iterator for type %d/topo %d\n", __FILE__, __LINE__, result,
02927 info, (int)type, (int)topo );
02928 goto end_arr_iter;
02929 }
02930
02931 if( !has_data || !values_size )
02932 {
02933 printf( "%s:%d: %s array iterator for type %d/topo %d ended prematurely at %d of %d\n", __FILE__,
02934 __LINE__, info, (int)type, (int)topo, i, contents_size );
02935 result = iBase_FAILURE;
02936 goto end_arr_iter;
02937 }
02938
02939 if( i + values_size > contents_size )
02940 {
02941 printf( "%s:%d: %s array iterator for type %d/topo %d returned more than %d handles\n", __FILE__,
02942 __LINE__, info, (int)type, (int)topo, contents_size );
02943 result = iBase_FAILURE;
02944 goto end_arr_iter;
02945 }
02946
02947 if( contents_size - i >= array_size && values_size < array_size )
02948 {
02949 printf( "%s:%d: %s array iterator for type %d/topo %d returned fewer than %d handles\n", __FILE__,
02950 __LINE__, info, (int)type, (int)topo, array_size );
02951 result = iBase_FAILURE;
02952 goto end_arr_iter;
02953 }
02954
02955 for( j = 0; j < values_size; ++j, ++i )
02956 {
02957 if( values[j] != contents[i] )
02958 {
02959 printf( "%s:%d: %s array iterator for type %d/topo %d returned incorrect value "
02960 "at %d of %d\n",
02961 __FILE__, __LINE__, info, (int)type, (int)topo, i, contents_size );
02962 result = iBase_FAILURE;
02963 goto end_arr_iter;
02964 }
02965 }
02966 }
02967
02968 iMesh_getNextEntArrIter( mesh, iter, &values, &values_alloc, &values_size, &has_data, &result );
02969 if( iBase_SUCCESS != result )
02970 {
02971 printf( "%s:%d: Error %d stepping %s array iterator for type %d/topo %d\n", __FILE__, __LINE__, result,
02972 info, (int)type, (int)topo );
02973 goto end_arr_iter;
02974 }
02975
02976 if( has_data || values_size )
02977 {
02978 printf( "%s:%d: %s array iterator for type %d/topo %d did not end after %d values\n", __FILE__, __LINE__,
02979 info, (int)type, (int)topo, contents_size );
02980 result = iBase_FAILURE;
02981 goto end_arr_iter;
02982 }
02983
02984 iMesh_resetEntArrIter( mesh, iter, &result );
02985 if( iBase_SUCCESS != result )
02986 {
02987 printf( "%s:%d: Error %d resetting %s array iterator for type %d/topo %d\n", __FILE__, __LINE__, result,
02988 info, (int)type, (int)topo );
02989 result = iBase_FAILURE;
02990 goto end_arr_iter;
02991 }
02992 }
02993
02994 end_arr_iter:
02995 free( values );
02996 iMesh_endEntArrIter( mesh, iter, &result2 );
02997 if( iBase_SUCCESS != result2 )
02998 {
02999 printf( "%s:%d: Error %d releasing %s array iterator for type %d/topo %d\n", __FILE__, __LINE__, result, info,
03000 (int)type, (int)topo );
03001 if( iBase_SUCCESS == result ) result = result2;
03002 }
03003 return result;
03004 }
03005
03006 int test_iterator_common( const char* info,
03007 iMesh_Instance mesh,
03008 iBase_EntitySetHandle set,
03009 int array_size,
03010 enum iBase_EntityType type,
03011 enum iMesh_EntityTopology topo )
03012 {
03013 iBase_EntityHandle* contents = NULL;
03014 int content_size = 0, content_alloc = 0;
03015 int result;
03016
03017 iMesh_getEntities( mesh, set, type, topo, &contents, &content_alloc, &content_size, &result );
03018 CHK( result );
03019 if( array_size == 1 )
03020 result = compare_single_iter( info, mesh, set, contents, content_size, type, topo );
03021 else
03022 result = compare_array_iter( info, mesh, set, contents, content_size, array_size, type, topo );
03023 free( contents );
03024 return result;
03025 }
03026
03027 int test_iterator( iMesh_Instance mesh )
03028 {
03029 int result, i;
03030 iBase_EntitySetHandle root, list, set, *setptr;
03031 iBase_EntityHandle* array = NULL;
03032 int array_len = 0, array_size = 0;
03033
03034 iMesh_getRootSet( mesh, &root, &result );
03035 CHK( result );
03036
03037 /* create some sets containing every other handle */
03038 iMesh_getEntities( mesh, root, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, &array, &array_size, &array_len, &result );
03039 CHK( result );
03040 for( i = 1; i < array_size; i += 2 )
03041 array[i] = array[i - 1];
03042 for( i = 0; i < 2; ++i )
03043 {
03044 setptr = i ? &list : &set;
03045 iMesh_createEntSet( mesh, i, setptr, &result );
03046 if( iBase_SUCCESS != result ) free( array );
03047 CHK( result );
03048 iMesh_addEntArrToSet( mesh, array, array_size, *setptr, &result );
03049 if( iBase_SUCCESS != result ) free( array );
03050 CHK( result );
03051 }
03052 free( array );
03053
03054 /* test single iterator and array iterator for all types */
03055 for( i = 0; i < iBase_ALL_TYPES; ++i )
03056 {
03057 array_size = 2 * i + 2;
03058 result = test_iterator_common( "root", mesh, root, 1, (enum iBase_EntityType)i, iMesh_ALL_TOPOLOGIES );
03059 CHK( result );
03060 result = test_iterator_common( "root", mesh, root, array_size, (enum iBase_EntityType)i, iMesh_ALL_TOPOLOGIES );
03061 CHK( result );
03062 result = test_iterator_common( "list", mesh, list, 1, (enum iBase_EntityType)i, iMesh_ALL_TOPOLOGIES );
03063 CHK( result );
03064 result = test_iterator_common( "list", mesh, list, array_size, (enum iBase_EntityType)i, iMesh_ALL_TOPOLOGIES );
03065 CHK( result );
03066 result = test_iterator_common( "set", mesh, set, 1, (enum iBase_EntityType)i, iMesh_ALL_TOPOLOGIES );
03067 CHK( result );
03068 result = test_iterator_common( "set", mesh, set, array_size, (enum iBase_EntityType)i, iMesh_ALL_TOPOLOGIES );
03069 CHK( result );
03070 }
03071
03072 /* test single iterator and array iterator for all types */
03073 for( i = 0; i < iMesh_ALL_TOPOLOGIES; ++i )
03074 {
03075 array_size = 2 * i + 2;
03076 result = test_iterator_common( "root", mesh, root, 1, iBase_ALL_TYPES, (enum iMesh_EntityTopology)i );
03077 CHK( result );
03078 result = test_iterator_common( "root", mesh, root, array_size, iBase_ALL_TYPES, (enum iMesh_EntityTopology)i );
03079 CHK( result );
03080 result = test_iterator_common( "list", mesh, list, 1, iBase_ALL_TYPES, (enum iMesh_EntityTopology)i );
03081 CHK( result );
03082 result = test_iterator_common( "list", mesh, list, array_size, iBase_ALL_TYPES, (enum iMesh_EntityTopology)i );
03083 CHK( result );
03084 result = test_iterator_common( "set", mesh, set, 1, iBase_ALL_TYPES, (enum iMesh_EntityTopology)i );
03085 CHK( result );
03086 result = test_iterator_common( "set", mesh, set, array_size, iBase_ALL_TYPES, (enum iMesh_EntityTopology)i );
03087 CHK( result );
03088 }
03089
03090 return 1;
03091 }
03092
03093 int main( int argc, char* argv[] )
03094 {
03095 /* Check command line arg */
03096 const char* filename;
03097 int number_tests = 0;
03098 int number_tests_successful = 0;
03099 int number_tests_not_implemented = 0;
03100 int number_tests_failed = 0;
03101 int result;
03102 iMesh_Instance mesh = NULL;
03103
03104 if( argc == 2 )
03105 {
03106 filename = argv[1];
03107 }
03108 else
03109 {
03110 printf( "Usage: %s \n", argv[0] );
03111 if( argc != 1 ) return 1;
03112 printf( " No file specified. Defaulting to: %s\n", DEFAULT_INPUT_FILE );
03113 filename = DEFAULT_INPUT_FILE;
03114 }
03115
03116 /* initialize the Mesh */
03117 iMesh_newMesh( NULL, &mesh, &result, 0 );
03118 if( iBase_SUCCESS != result )
03119 {
03120 printf( "Failed to create a mesh instance.\n" );
03121 return 1;
03122 }
03123 iMesh_getRootSet( mesh, &root_set, &result );
03124 if( iBase_SUCCESS != result )
03125 {
03126 printf( "Failed to return a root set.\n" );
03127 return 1;
03128 }
03129
03130 /* Print out Header information */
03131 printf( "\n\nTSTT TEST PROGRAM:\n\n" );
03132
03133 /* load_mesh test */
03134 printf( " load_mesh: " );
03135 result = load_mesh_test( filename, mesh );
03136 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03137 number_tests++;
03138 printf( "\n" );
03139
03140 /* topology_adjacency_test */
03141 printf( " topology_adjacency_test: " );
03142 result = topology_adjacency_test( mesh );
03143 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03144 number_tests++;
03145 printf( "\n" );
03146
03147 /* entity connectivity test */
03148 printf( " entity_connectivity_test: " );
03149 result = entity_connectivity_test( mesh );
03150 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03151 number_tests++;
03152 printf( "\n" );
03153
03154 /* vertex_coordinates_test */
03155 printf( " vertex_coordinates_test: " );
03156 result = vertex_coordinates_test( mesh );
03157 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03158 number_tests++;
03159 printf( "\n" );
03160
03161 /* topology dimension test */
03162 printf( " topology_dimension_test: " );
03163 result = topology_dimension_test( mesh );
03164 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03165 number_tests++;
03166 printf( "\n" );
03167
03168 /* entity sets test */
03169 printf( " entity_sets_test: " );
03170 result = entity_sets_test( mesh );
03171 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03172 number_tests++;
03173 printf( "\n" );
03174
03175 /* vertex tag test */
03176 printf( " vertex_tag_test: " );
03177 result = vertex_tag_test( mesh );
03178 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03179 number_tests++;
03180 printf( "\n" );
03181
03182 /* entityset tag test */
03183 printf( " entityset_tag_test: " );
03184 result = entityset_tag_test( mesh );
03185 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03186 number_tests++;
03187 printf( "\n" );
03188
03189 /* mesh tag test */
03190 printf( " mesh_tag_test: " );
03191 result = mesh_tag_test( mesh );
03192 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03193 number_tests++;
03194 printf( "\n" );
03195
03196 /* iterator test */
03197 printf( " test_iterator: " );
03198 result = test_iterator( mesh );
03199 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03200 number_tests++;
03201 printf( "\n" );
03202
03203 /* regression test for remove/contained bug */
03204 printf( " set_remove_contained_regression: " );
03205 result = set_remove_contained_regression( mesh );
03206 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03207 number_tests++;
03208 printf( "\n" );
03209
03210 /* regression test for adjacencies with iBase_ALL_TYPES bug */
03211 printf( " all_adjacency_regression: " );
03212 result = all_adjacency_regression( mesh );
03213 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03214 number_tests++;
03215 printf( "\n" );
03216
03217 /* test for error codes */
03218 printf( " error_code_test: " );
03219 result = error_code_test( mesh );
03220 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03221 number_tests++;
03222 printf( "\n" );
03223
03224 /* regression test for ordered sets not preserving order */
03225 printf( " ordered_set_regression: " );
03226 result = ordered_set_regression( mesh );
03227 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03228 number_tests++;
03229 printf( "\n" );
03230
03231 /* test for array allocation behavior */
03232 printf( " array_allocation_regression: " );
03233 result = array_allocation( mesh );
03234 handle_error_code( result, &number_tests_failed, &number_tests_not_implemented, &number_tests_successful );
03235 number_tests++;
03236 printf( "\n" );
03237
03238 /* summary */
03239
03240 printf( "\nTSTT TEST SUMMARY: \n" );
03241
03242 printf( " Number Tests: %d\n", number_tests );
03243 printf( " Number Successful: %d\n", number_tests_successful );
03244 printf( " Number Not Implemented: %d\n", number_tests_not_implemented );
03245 printf( " Number Failed: %d\n", number_tests_failed );
03246 printf( "\n\n\n" );
03247
03248 /* delete the mesh */
03249 iMesh_dtor( mesh, &result );
03250 if( iBase_SUCCESS != result )
03251 {
03252 printf( "Failed to destruct the mesh instance.\n" );
03253 return 1;
03254 }
03255
03256 return number_tests_failed;
03257 }