MOAB: Mesh Oriented datABase  (version 5.4.1)
readutil_test.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include "moab/Interface.hpp"
00003 #ifndef IS_BUILDING_MB
00004 #define IS_BUILDING_MB
00005 #endif
00006 #include "Internals.hpp"
00007 #include "moab/ReadUtilIface.hpp"
00008 #include "moab/Core.hpp"
00009 #include "moab/Range.hpp"
00010 
00011 using namespace moab;
00012 
00013 #define CHKERR( A )                                                                                        \
00014     do                                                                                                     \
00015     {                                                                                                      \
00016         if( MB_SUCCESS != ( A ) )                                                                          \
00017         {                                                                                                  \
00018             std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \
00019             return A;                                                                                      \
00020         }                                                                                                  \
00021     } while( false )
00022 
00023 ErrorCode gather_related_test()
00024 {
00025     // create an entityset structure and test related entities function
00026     // sets: A
00027     //       |
00028     //       B  C
00029     //       |/ |
00030     //       D  E
00031     // if D is passed in to gather_related_ents, A-D should be returned, and E should not be
00032     //
00033     EntityHandle A, B, C, D, E;
00034     Core mb;
00035     ErrorCode rval = mb.create_meshset( MESHSET_SET, A );CHKERR( rval );
00036     rval = mb.create_meshset( MESHSET_SET, B );CHKERR( rval );
00037     rval = mb.create_meshset( MESHSET_SET, C );CHKERR( rval );
00038     rval = mb.create_meshset( MESHSET_SET, D );CHKERR( rval );
00039     rval = mb.create_meshset( MESHSET_SET, E );CHKERR( rval );
00040 
00041     rval = mb.add_parent_child( A, B );CHKERR( rval );
00042     rval = mb.add_parent_child( B, D );CHKERR( rval );
00043     rval = mb.add_parent_child( C, D );CHKERR( rval );
00044     rval = mb.add_parent_child( C, E );CHKERR( rval );
00045 
00046     // now test it
00047     ReadUtilIface* readMeshIface;
00048     mb.Interface::query_interface( readMeshIface );
00049 
00050     Range init_range, set_range, all_sets( A, E );
00051     init_range.insert( D );
00052     rval = readMeshIface->gather_related_ents( init_range, set_range );CHKERR( rval );
00053 
00054     if( set_range.size() != 4 ) return MB_FAILURE;
00055     all_sets -= set_range;
00056     if( 1 != all_sets.size() || *all_sets.begin() != E ) return MB_FAILURE;
00057 
00058     return MB_SUCCESS;
00059 }
00060 
00061 int number_tests        = 0;
00062 int number_tests_failed = 0;
00063 #define RUN_TEST( A ) _run_test( ( A ), #A )
00064 
00065 typedef ErrorCode ( *TestFunc )();
00066 static void _run_test( TestFunc func, const char* func_str )
00067 {
00068     ++number_tests;
00069     std::cout << "   " << func_str << ": ";
00070     std::cout.flush();
00071     ErrorCode error = func();
00072 
00073     if( MB_SUCCESS == error )
00074         std::cout << "Success" << std::endl;
00075     else if( MB_FAILURE == error )
00076         std::cout << "Failure" << std::endl;
00077     else
00078     {
00079         Core moab;
00080         std::cout << "Failed: " << moab.get_error_string( error ) << std::endl;
00081     }
00082 
00083     if( MB_SUCCESS != error )
00084     {
00085         ++number_tests_failed;
00086     }
00087 }
00088 
00089 int main( int /*argc*/, char** /*argv[]*/ )
00090 {
00091     RUN_TEST( gather_related_test );
00092 
00093     std::cout << "\nMB TEST SUMMARY: \n"
00094               << "   Number Tests:           " << number_tests << "\n"
00095               << "   Number Successful:      " << number_tests - number_tests_failed << "\n"
00096               << "   Number Failed:          " << number_tests_failed << "\n\n";
00097 
00098     return number_tests_failed;
00099 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines