[cgma-dev] r3398 - in cgm/trunk: init test

Steve Jackson sjackson at cae.wisc.edu
Fri Dec 4 17:01:06 CST 2009


Anyone with a special interest in the InitCGMA interface may want to look over this ticket: https://trac.mcs.anl.gov/projects/ITAPS/ticket/143
~S

On Dec 4, 2009, at 16:31 , sjackson at cae.wisc.edu wrote:

> Author: sjackson
> Date: 2009-12-04 16:31:45 -0600 (Fri, 04 Dec 2009)
> New Revision: 3398
> 
> Added:
>   cgm/trunk/test/init.cpp
> Modified:
>   cgm/trunk/init/InitCGMA.cpp
>   cgm/trunk/test/Makefile.am
> Log:
> Make InitCGMA::initialize_cgma safe to call multiple times.  It will
> emit an error message if called with a default engine parameter that
> differs from one specified in the first call to the function.
> 
> Add a new test case to verify that this works as expected. 
> 
> 
> Modified: cgm/trunk/init/InitCGMA.cpp
> ===================================================================
> --- cgm/trunk/init/InitCGMA.cpp	2009-12-03 23:08:55 UTC (rev 3397)
> +++ cgm/trunk/init/InitCGMA.cpp	2009-12-04 22:31:45 UTC (rev 3398)
> @@ -5,6 +5,7 @@
> #include "FacetModifyEngine.hpp"
> #include "GeometryQueryTool.hpp"
> #include "GeometryModifyTool.hpp"
> +#include "CubitUtil.hpp"
> 
> #include <ctype.h>
> 
> @@ -49,9 +50,28 @@
>   return !*t;
> }
> 
> +static bool has_been_initialized = false;
> +static char* first_engine_name = NULL;
> 
> +
> CubitStatus InitCGMA::initialize_cgma( const char* default_engine_name )
> {
> +  if( has_been_initialized ){
> +    // CGM is already initialized.  Return success if previous initialization had
> +    // the same parameter, failure otherwise.
> +    if( default_engine_name == first_engine_name ){
> +      return CUBIT_SUCCESS;
> +    }
> +    else if( default_engine_name && first_engine_name && 
> +	     streq_nocase( default_engine_name, first_engine_name )){
> +      return CUBIT_SUCCESS;
> +    }
> +    else{
> +      PRINT_ERROR( "initialize_cgma() called again, but default engines differ.\n" );
> +      return CUBIT_FAILURE;
> +    }
> +  }
> +
>   CGMApp::instance()->startup( 0, NULL );
>   GeometryModifyEngine* default_engine = 0;
>   bool ignore_default = false;
> @@ -103,5 +123,12 @@
>       return rval;
>   }
> 
> +  // set has_been_initialized only if everything worked
> +  if( default_engine_name ){
> +    first_engine_name = CubitUtil::util_strdup(default_engine_name); 
> +  }
> +  has_been_initialized = true;
> +
>   return CUBIT_SUCCESS;
> }
> +
> 
> Modified: cgm/trunk/test/Makefile.am
> ===================================================================
> --- cgm/trunk/test/Makefile.am	2009-12-03 23:08:55 UTC (rev 3397)
> +++ cgm/trunk/test/Makefile.am	2009-12-04 22:31:45 UTC (rev 3398)
> @@ -12,7 +12,7 @@
> 	   -I$(srcdir) \
> 	   $(OCC_INC_FLAG)
> 
> -TESTS = sheet brick
> +TESTS = init sheet brick
> if build_ACIS
>   TESTS += webcut hollow_acis
> else
> @@ -49,7 +49,10 @@
> operation_LDFLAGS = $(LDFLAGS) $(LINK_FLAGS)
> brick_SOURCES = brick.cpp
> brick_LDFLAGS = $(LDFLAGS) $(LINK_FLAGS)
> +init_SOURCES = init.cpp
> +init_LDFLAGS= $(LDFLAGS) $(LINK_FLAGS)
> 
> +
> # Files that are used as input to tests, and therefore
> # must be included in tarball for tests to run.
> EXTRA_DIST = 62_shaver1.brep \
> 
> Added: cgm/trunk/test/init.cpp
> ===================================================================
> --- cgm/trunk/test/init.cpp	                        (rev 0)
> +++ cgm/trunk/test/init.cpp	2009-12-04 22:31:45 UTC (rev 3398)
> @@ -0,0 +1,32 @@
> +/**
> + * \file init.cpp
> + *
> + * \brief Tests of CGM initialization / shutdown features
> + */
> +#include "InitCGMA.hpp"
> +
> +#include <typeinfo>
> +#include <assert.h>
> +
> +
> +// main program - initialize, then send to proper function
> +int main (int argc, char **argv)
> +{
> +  // first initialization, which should succeed
> +  CubitStatus result = InitCGMA::initialize_cgma();
> +  if (CUBIT_SUCCESS != result) return 1;
> +
> +  // second initialization, which should also succeed
> +  result = InitCGMA::initialize_cgma();
> +  if(CUBIT_SUCCESS != result) return 1;
> +
> +  // now try again, with a different argument; should fail.
> +  result = InitCGMA::initialize_cgma( "facet" );
> +  if(CUBIT_FAILURE != result) return 1;
> +
> +  return 0;
> +  
> +}
> +
> +
> +    
> 



More information about the cgma-dev mailing list