[MOAB-dev] r3355 - in MOAB/trunk: . tools/iMesh

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Mon Nov 16 16:49:48 CST 2009


Author: kraftche
Date: 2009-11-16 16:49:48 -0600 (Mon, 16 Nov 2009)
New Revision: 3355

Modified:
   MOAB/trunk/MBCore.cpp
   MOAB/trunk/MBCore.hpp
   MOAB/trunk/MBInterface.hpp
   MOAB/trunk/MBTest.cpp
   MOAB/trunk/MBTypes.h
   MOAB/trunk/TestUtil.hpp
   MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp
   MOAB/trunk/tools/iMesh/iMesh_MOAB.hpp
   MOAB/trunk/tools/iMesh/testc_cbind.c
Log:
o Add new error code: MB_UNHANDLED_OPTION

o Make MBCore::load_file and MBCore::write_file return MB_UNHANDLED_OPTION
   if the file read/write succeeded but there was an unrecognized name
   in the options strings.

o Change some declarations that depend on MBErrorCode values such that
   it is more likely to see a compiler error or warning if MBErrorCode
   is changed without updating the array.

o Add some unit tests that should catch a failure to update certain
   arrays after adding to the MBErrorCode values.





Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp	2009-11-16 21:37:43 UTC (rev 3354)
+++ MOAB/trunk/MBCore.cpp	2009-11-16 22:49:48 UTC (rev 3355)
@@ -77,24 +77,6 @@
 
 using namespace std;
 
-const char *MBCore::errorStrings[] = {
-  "MB_SUCCESS",
-  "MB_INDEX_OUT_OF_RANGE",
-  "MB_TYPE_OUT_OF_RANGE",
-  "MB_MEMORY_ALLOCATION_FAILED",
-  "MB_ENTITY_NOT_FOUND",
-  "MB_MULTIPLE_ENTITIES_FOUND",
-  "MB_TAG_NOT_FOUND",
-  "MB_FILE_DOES_NOT_EXIST",
-  "MB_FILE_WRITE_ERROR",
-  "MB_NOT_IMPLEMENTED",
-  "MB_ALREADY_ALLOCATED",
-  "MB_VARIABLE_DATA_LENGTH",
-  "MB_INVALID_SIZE",
-  "MB_UNSUPPORTED_OPERATION",
-  "MB_FAILURE",
-};
-
 static inline const MBMeshSet* get_mesh_set( const SequenceManager* sm,
                                              MBEntityHandle h )
 {
@@ -416,7 +398,7 @@
       mError->set_last_error( "Unrecognized option: \"%s\"", bad_opt.c_str() );
     else
       mError->set_last_error( "Unrecognized option." );
-    rval = MB_FAILURE;
+    rval = MB_UNHANDLED_OPTION;
   }
   
   return rval;
@@ -598,7 +580,7 @@
       mError->set_last_error( "Unrecognized option: \"%s\"", bad_opt.c_str() );
     else
       mError->set_last_error( "Unrecognized option." );
-    rval = MB_FAILURE;
+    rval = MB_UNHANDLED_OPTION;
   }
 
   return rval;
@@ -2941,6 +2923,25 @@
 
 std::string MBCore::get_error_string(const MBErrorCode code) const 
 {
+  static const char* errorStrings[MB_FAILURE+1] = {
+    "MB_SUCCESS",
+    "MB_INDEX_OUT_OF_RANGE",
+    "MB_TYPE_OUT_OF_RANGE",
+    "MB_MEMORY_ALLOCATION_FAILED",
+    "MB_ENTITY_NOT_FOUND",
+    "MB_MULTIPLE_ENTITIES_FOUND",
+    "MB_TAG_NOT_FOUND",
+    "MB_FILE_DOES_NOT_EXIST",
+    "MB_FILE_WRITE_ERROR",
+    "MB_NOT_IMPLEMENTED",
+    "MB_ALREADY_ALLOCATED",
+    "MB_VARIABLE_DATA_LENGTH",
+    "MB_INVALID_SIZE",
+    "MB_UNSUPPORTED_OPERATION",
+    "MB_UNHANDLED_OPTION",
+    "MB_FAILURE",
+  };
+
   return errorStrings[code];
 }
 

Modified: MOAB/trunk/MBCore.hpp
===================================================================
--- MOAB/trunk/MBCore.hpp	2009-11-16 21:37:43 UTC (rev 3354)
+++ MOAB/trunk/MBCore.hpp	2009-11-16 22:49:48 UTC (rev 3355)
@@ -1187,9 +1187,6 @@
   MBReaderWriterSet* readerWriterSet;
 
   MBError* mError;
-
-  static const char *errorStrings[];
-  
 };
 
   

Modified: MOAB/trunk/MBInterface.hpp
===================================================================
--- MOAB/trunk/MBInterface.hpp	2009-11-16 21:37:43 UTC (rev 3354)
+++ MOAB/trunk/MBInterface.hpp	2009-11-16 22:49:48 UTC (rev 3355)
@@ -198,9 +198,10 @@
    *\param file_set  Output: a handle to a new set containing all entities 
    *                        read or imported from the file.
    *\param options A list of string options, separated by semicolons (;).
-   *               See README.IO for more information.  Typical options
-   *               include the file type, parallel options, and options
-   *               specific to certain file formats.
+   *               See README.IO for more information.  Options are typically
+   *               format-specific options or parallel options.  If an
+   *               option value is unrecognized but the file read otherwise
+   *               succeeded, MB_UNHANDLED_OPTION will be returned.
    *\param set_tag_name The name of a tag used to designate the subset
    *               of the file to read.  The name must correspond to 
    *               data in the file that will be instantiated in MOAB

Modified: MOAB/trunk/MBTest.cpp
===================================================================
--- MOAB/trunk/MBTest.cpp	2009-11-16 21:37:43 UTC (rev 3354)
+++ MOAB/trunk/MBTest.cpp	2009-11-16 22:49:48 UTC (rev 3355)
@@ -6811,6 +6811,35 @@
   return MB_SUCCESS;
 }
 
+#define TEST_ERROR_CODE(E) \
+  if (mb->get_error_string(E) != #E) { \
+    std::cerr << "Invalid error string from get_error_string for " \
+              << #E << ": " << mb->get_error_string(E) << std::endl;\
+    return MB_FAILURE; \
+  } 
+
+MBErrorCode mb_enum_string_test( MBInterface* mb )
+{
+  TEST_ERROR_CODE( MB_SUCCESS );
+  TEST_ERROR_CODE( MB_INDEX_OUT_OF_RANGE );
+  TEST_ERROR_CODE( MB_TYPE_OUT_OF_RANGE );
+  TEST_ERROR_CODE( MB_MEMORY_ALLOCATION_FAILED );
+  TEST_ERROR_CODE( MB_ENTITY_NOT_FOUND );
+  TEST_ERROR_CODE( MB_MULTIPLE_ENTITIES_FOUND );
+  TEST_ERROR_CODE( MB_TAG_NOT_FOUND );
+  TEST_ERROR_CODE( MB_FILE_DOES_NOT_EXIST );
+  TEST_ERROR_CODE( MB_FILE_WRITE_ERROR );
+  TEST_ERROR_CODE( MB_NOT_IMPLEMENTED );
+  TEST_ERROR_CODE( MB_ALREADY_ALLOCATED );
+  TEST_ERROR_CODE( MB_VARIABLE_DATA_LENGTH );
+  TEST_ERROR_CODE( MB_INVALID_SIZE );
+  TEST_ERROR_CODE( MB_UNSUPPORTED_OPERATION );
+  TEST_ERROR_CODE( MB_UNHANDLED_OPTION );
+  TEST_ERROR_CODE( MB_FAILURE );
+  
+  return MB_SUCCESS;
+}
+
 int number_tests = 0;
 int number_tests_failed = 0;
 #define RUN_TEST( A ) _run_test( (A), #A )
@@ -6944,6 +6973,7 @@
   RUN_TEST( mb_skin_volume_test );
   RUN_TEST( mb_skin_volume_adj_test );
   RUN_TEST( mb_read_fail_test );
+  RUN_TEST( mb_enum_string_test );
   RUN_TEST( mb_merge_update_test );
   RUN_TEST( mb_merge_test );
   if (stress_test) RUN_TEST( mb_stress_test );

Modified: MOAB/trunk/MBTypes.h
===================================================================
--- MOAB/trunk/MBTypes.h	2009-11-16 21:37:43 UTC (rev 3354)
+++ MOAB/trunk/MBTypes.h	2009-11-16 22:49:48 UTC (rev 3355)
@@ -53,6 +53,7 @@
                    MB_VARIABLE_DATA_LENGTH,
                    MB_INVALID_SIZE,
                    MB_UNSUPPORTED_OPERATION,
+                   MB_UNHANDLED_OPTION,
                    MB_FAILURE};
 
 /** Misc. integer constants, declared in enum for portability */

Modified: MOAB/trunk/TestUtil.hpp
===================================================================
--- MOAB/trunk/TestUtil.hpp	2009-11-16 21:37:43 UTC (rev 3354)
+++ MOAB/trunk/TestUtil.hpp	2009-11-16 22:49:48 UTC (rev 3355)
@@ -373,6 +373,7 @@
     case MB_VARIABLE_DATA_LENGTH    : return "Variable Data Length";
     case MB_INVALID_SIZE            : return "Invalid Size";
     case MB_UNSUPPORTED_OPERATION   : return "Unsupported Operation";
+    case MB_UNHANDLED_OPTION        : return "Unhandled Option";
     case MB_FAILURE                 : return "Failure";
     default                         : return "(unknown)";
   }

Modified: MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp
===================================================================
--- MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp	2009-11-16 21:37:43 UTC (rev 3354)
+++ MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp	2009-11-16 22:49:48 UTC (rev 3355)
@@ -161,7 +161,7 @@
   iBase_ENTITY_HANDLE
 };
 
-const iBase_ErrorType iBase_ERROR_MAP[] = 
+const iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE+1] = 
 {
   iBase_SUCCESS, // MB_SUCCESS = 0,
   iBase_INVALID_ENTITY_HANDLE, // MB_INDEX_OUT_OF_RANGE,
@@ -177,6 +177,7 @@
   iBase_FAILURE, // MB_VARIABLE_DATA_LENGTH,
   iBase_FAILURE, // MB_INVALID_SIZE,
   iBase_NOT_SUPPORTED, // MB_UNSUPPORTED_OPERATION,
+  iBase_INVALID_ARGUMENT, // MB_UNHANDLED_OPTION
   iBase_FAILURE // MB_FAILURE};
 };
 

Modified: MOAB/trunk/tools/iMesh/iMesh_MOAB.hpp
===================================================================
--- MOAB/trunk/tools/iMesh/iMesh_MOAB.hpp	2009-11-16 21:37:43 UTC (rev 3354)
+++ MOAB/trunk/tools/iMesh/iMesh_MOAB.hpp	2009-11-16 22:49:48 UTC (rev 3355)
@@ -20,7 +20,7 @@
 extern const iBase_TagValueType tstt_data_type_table[MB_MAX_DATA_TYPE+1];
 
 /* map from MOAB's MBErrorCode to tstt's */
-extern const iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE+1];
+extern "C" const iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE+1];
 
 /* Create ITAPS iterator */
 iMesh_EntityIterator create_itaps_iterator( MBRange& swap_range,

Modified: MOAB/trunk/tools/iMesh/testc_cbind.c
===================================================================
--- MOAB/trunk/tools/iMesh/testc_cbind.c	2009-11-16 21:37:43 UTC (rev 3354)
+++ MOAB/trunk/tools/iMesh/testc_cbind.c	2009-11-16 22:49:48 UTC (rev 3355)
@@ -60,7 +60,10 @@
 #include <string.h>
 #include <stdlib.h>
 #include "iMesh.h"
+#include "MBTypes.h"
+extern enum iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE+1];
 
+
 #define FALSE 0
 #define TRUE 1
 
@@ -121,6 +124,26 @@
   return TRUE;
 }
 
+#define TEST_ERROR_CODE( A, B ) \
+  if (iBase_ERROR_MAP[(A)] != (B)) { \
+    printf("ERROR: Invalid mapping for MOAB error code %s\n", #A); \
+    printf("       Expected %d, actual is %d\n", (int)iBase_ERROR_MAP[(A)], (int)(B) ); \
+    return FALSE; \
+  }
+
+int error_code_test(iMesh_Instance mesh) {
+  TEST_ERROR_CODE( MB_SUCCESS,                  iBase_SUCCESS )
+  TEST_ERROR_CODE( MB_TYPE_OUT_OF_RANGE,        iBase_INVALID_ENTITY_TYPE )
+  TEST_ERROR_CODE( MB_MEMORY_ALLOCATION_FAILED, iBase_MEMORY_ALLOCATION_FAILED )
+  TEST_ERROR_CODE( MB_ENTITY_NOT_FOUND,         iBase_INVALID_ENTITY_HANDLE )
+  TEST_ERROR_CODE( MB_TAG_NOT_FOUND,            iBase_TAG_NOT_FOUND )
+  TEST_ERROR_CODE( MB_FILE_DOES_NOT_EXIST,      iBase_FILE_NOT_FOUND )
+  TEST_ERROR_CODE( MB_UNSUPPORTED_OPERATION,    iBase_NOT_SUPPORTED )
+  TEST_ERROR_CODE( MB_UNHANDLED_OPTION,         iBase_INVALID_ARGUMENT )
+  TEST_ERROR_CODE( MB_FAILURE,                  iBase_FAILURE )
+  return TRUE;
+}
+
 /*!
   @test
   TSTT topology dimension Test
@@ -2283,6 +2306,14 @@
   number_tests++;
   printf("\n");
 
+  printf("   error_code_test: ");
+  result = error_code_test(mesh);
+  handle_error_code(result, &number_tests_failed,
+                    &number_tests_not_implemented,
+                    &number_tests_successful);
+  number_tests++;
+  printf("\n");
+
     /* summary */
 
   printf("\nTSTT TEST SUMMARY: \n");



More information about the moab-dev mailing list