1 
2 #include <iostream>
3 #include "moab/Interface.hpp"
4 #ifndef IS_BUILDING_MB
5 #define IS_BUILDING_MB
6 #endif
7 #include "Internals.hpp"
8 #include "moab/ReadUtilIface.hpp"
9 #include "moab/Core.hpp"
10 #include "moab/Range.hpp"
11 
12 using namespace moab;
13 
14 #define CHKERR(A) do { if (MB_SUCCESS != (A)) { \
15   std::cerr << "Failure (error code " << (A) << ") at " __FILE__ ":" \
16             << __LINE__ << std::endl; \
17   return A; } } while(false)
18 
gather_related_test()19 ErrorCode gather_related_test()
20 {
21     // create an entityset structure and test related entities function
22     // sets: A
23     //       |
24     //       B  C
25     //       |/ |
26     //       D  E
27     // if D is passed in to gather_related_ents, A-D should be returned, and E should not be
28     //
29   EntityHandle A, B, C, D, E;
30   Core mb;
31   ErrorCode rval = mb.create_meshset( MESHSET_SET, A ); CHKERR(rval);
32   rval = mb.create_meshset( MESHSET_SET, B ); CHKERR(rval);
33   rval = mb.create_meshset( MESHSET_SET, C ); CHKERR(rval);
34   rval = mb.create_meshset( MESHSET_SET, D ); CHKERR(rval);
35   rval = mb.create_meshset( MESHSET_SET, E ); CHKERR(rval);
36 
37   rval = mb.add_parent_child(A, B); CHKERR(rval);
38   rval = mb.add_parent_child(B, D); CHKERR(rval);
39   rval = mb.add_parent_child(C, D); CHKERR(rval);
40   rval = mb.add_parent_child(C, E); CHKERR(rval);
41 
42     // now test it
43   ReadUtilIface* readMeshIface;
44   mb.Interface::query_interface(readMeshIface);
45 
46   Range init_range, set_range, all_sets(A, E);
47   init_range.insert(D);
48   rval = readMeshIface->gather_related_ents(init_range, set_range); CHKERR(rval);
49 
50   if (set_range.size() != 4) return MB_FAILURE;
51   all_sets -= set_range;
52   if (1 != all_sets.size() || *all_sets.begin() != E) return MB_FAILURE;
53 
54   return MB_SUCCESS;
55 }
56 
57 int number_tests = 0;
58 int number_tests_failed = 0;
59 #define RUN_TEST( A ) _run_test( (A), #A )
60 
61 
62 typedef ErrorCode (*TestFunc)();
_run_test(TestFunc func,const char * func_str)63 static void _run_test( TestFunc func, const char* func_str )
64 {
65   ++number_tests;
66   std::cout << "   " << func_str << ": ";
67   std::cout.flush();
68   ErrorCode error = func( );
69 
70   if (MB_SUCCESS == error)
71     std::cout << "Success" << std::endl;
72   else if (MB_FAILURE == error)
73     std::cout << "Failure" << std::endl;
74   else {
75     Core moab;
76     std::cout << "Failed: " << moab.get_error_string( error ) << std::endl;
77   }
78 
79   if (MB_SUCCESS != error) {
80     ++number_tests_failed;
81   }
82 }
83 
main(int,char **)84 int main(int /*argc*/, char** /*argv[]*/)
85 {
86   RUN_TEST( gather_related_test );
87 
88   std::cout << "\nMB TEST SUMMARY: \n"
89        << "   Number Tests:           " << number_tests << "\n"
90        << "   Number Successful:      " << number_tests - number_tests_failed << "\n"
91        << "   Number Failed:          " << number_tests_failed
92        << "\n\n";
93 
94   return number_tests_failed;
95 }
96