lasso
test_both.cpp
Go to the documentation of this file.
00001 #include "iGeom.h"
00002 #include "iMesh.h"
00003 #include "iRel.h"
00004 
00005 #include "TestUtil.hpp"
00006 
00007 #include <cstdlib>
00008 
00009 iGeom_Instance geom;
00010 iMesh_Instance mesh;
00011 iRel_Instance rel;
00012 
00013 iBase_EntityHandle geom_ent;
00014 iBase_EntityHandle mesh_ents[4];
00015 iBase_EntitySetHandle mesh_set;
00016 
00017 void test_both()
00018 {
00019   int err;
00020   iRel_PairHandle pair;
00021 
00022   iRel_createPair(rel, geom, iRel_ENTITY, iRel_IGEOM_IFACE, iRel_ACTIVE,
00023                        mesh, iRel_BOTH,   iRel_IMESH_IFACE, iRel_ACTIVE,
00024                   &pair, &err);
00025   CHECK_ERR(err);
00026 
00027   iRel_setEntSetRelation(rel, pair, geom_ent, mesh_set, &err);
00028   CHECK_ERR(err);
00029 
00030   iBase_EntityHandle *related_ents = NULL;
00031   int related_ents_alloc = 0, related_ents_size;
00032   iRel_getEntArrEntArrRelation(rel, pair, mesh_ents, 4, 1,
00033                                &related_ents, &related_ents_alloc,
00034                                &related_ents_size, &err);
00035   CHECK_ERR(err);
00036 
00037   for(int i = 0; i < related_ents_size; i++)
00038     CHECK_EQUAL(related_ents[i], geom_ent);
00039 
00040   free(related_ents);
00041 }
00042 
00043 void test_change_to_both()
00044 {
00045   int err;
00046   iRel_PairHandle pair;
00047 
00048   iRel_createPair(rel, geom, iRel_ENTITY, iRel_IGEOM_IFACE, iRel_ACTIVE,
00049                        mesh, iRel_SET,    iRel_IMESH_IFACE, iRel_ACTIVE,
00050                   &pair, &err);
00051   CHECK_ERR(err);
00052 
00053   iRel_setEntSetRelation(rel, pair, geom_ent, mesh_set, &err);
00054   CHECK_ERR(err);
00055 
00056   iRel_changePairType(rel, pair, iRel_ENTITY, iRel_BOTH, &err);
00057   CHECK_ERR(err);
00058 
00059   iBase_EntityHandle *related_ents = NULL;
00060   int related_ents_alloc = 0, related_ents_size;
00061   iRel_getEntArrEntArrRelation(rel, pair, mesh_ents, 4, 1,
00062                                &related_ents, &related_ents_alloc,
00063                                &related_ents_size, &err);
00064   CHECK_ERR(err);
00065 
00066   for(int i = 0; i < related_ents_size; i++)
00067     CHECK_EQUAL(related_ents[i], geom_ent);
00068 
00069   free(related_ents);
00070 }
00071 
00072 void test_change_to_set()
00073 {
00074   int err;
00075   iRel_PairHandle pair;
00076 
00077   iRel_createPair(rel, geom, iRel_ENTITY, iRel_IGEOM_IFACE, iRel_ACTIVE,
00078                        mesh, iRel_BOTH,   iRel_IMESH_IFACE, iRel_ACTIVE,
00079                   &pair, &err);
00080   CHECK_ERR(err);
00081 
00082   iRel_setEntSetRelation(rel, pair, geom_ent, mesh_set, &err);
00083   CHECK_ERR(err);
00084 
00085   iRel_changePairType(rel, pair, iRel_ENTITY, iRel_SET, &err);
00086   CHECK_ERR(err);
00087 
00088   for(int i = 0; i < 4; i++) {
00089     iBase_EntityHandle related_ent;
00090     iRel_getEntEntRelation(rel, pair, mesh_ents[i], 1, &related_ent, &err);
00091     CHECK(err != iBase_SUCCESS);
00092   }
00093 }
00094 
00095 int main()
00096 {
00097   int err;
00098   int num_fail = 0;
00099 
00100   iGeom_newGeom(0, &geom, &err, 0);
00101   iMesh_newMesh(0, &mesh, &err, 0);
00102   iRel_create(0, &rel, &err, 0);
00103 
00104   iGeom_createBrick(geom, 2, 2, 2, &geom_ent, &err);
00105 
00106   double coords[] = {
00107     0, 0, 0,
00108     0, 1, 0,
00109     1, 1, 0,
00110     1, 0, 0,
00111   };
00112 
00113   iBase_EntityHandle *mesh_ents_ptr = mesh_ents;
00114   int mesh_ents_alloc = 4, mesh_ents_size;
00115   iMesh_createVtxArr(mesh, 4, iBase_INTERLEAVED, coords, 12,
00116                      &mesh_ents_ptr, &mesh_ents_alloc, &mesh_ents_size, &err);
00117 
00118   iMesh_createEntSet(mesh, false, &mesh_set, &err);
00119   iMesh_addEntArrToSet(mesh, mesh_ents, mesh_ents_size, mesh_set, &err);
00120 
00121   num_fail += RUN_TEST(test_both);
00122   num_fail += RUN_TEST(test_change_to_both);
00123   num_fail += RUN_TEST(test_change_to_set);
00124 
00125   iRel_destroy(rel, &err);
00126   iMesh_dtor(mesh, &err);
00127   iGeom_dtor(geom, &err);
00128 
00129   return num_fail;
00130 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines