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