Exemplo n.º 1
0
void test_deselect_matching( ) {
  state_map_type * map = state_map_alloc( );
  bool_vector_type * mask1 = bool_vector_alloc(0 , false);
  bool_vector_type * mask2 = bool_vector_alloc(1000 , true);

  state_map_iset( map , 10 , STATE_INITIALIZED );
  state_map_iset( map , 10 , STATE_HAS_DATA );
  state_map_iset( map , 20 , STATE_INITIALIZED );
  state_map_deselect_matching( map , mask1 , STATE_HAS_DATA | STATE_INITIALIZED );
  state_map_deselect_matching( map , mask2 , STATE_HAS_DATA | STATE_INITIALIZED );
  
  test_assert_int_equal( state_map_get_size( map ) , bool_vector_size( mask1 ));
  
  for (int i=0; i < bool_vector_size( mask1 ); i++) {
    if (i==10)
      test_assert_false( bool_vector_iget( mask1 , i ));
    else if (i== 20)
      test_assert_false( bool_vector_iget( mask2 , i ));
    else {
      test_assert_false( bool_vector_iget( mask1 , i ));
      test_assert_true( bool_vector_iget( mask2 , i ));
    }
  }
    
  bool_vector_free( mask1 );
  bool_vector_free( mask2 );
  state_map_free( map );
}
void test_approx_equal() {
  double_vector_type * d1 = double_vector_alloc(0,0);
  double_vector_type * d2 = double_vector_alloc(0,0);
  double_vector_type * d3 = double_vector_alloc(0,0);

  double_vector_append( d1 , 1.0 );
  double_vector_append( d1 , 2.0 );
  double_vector_append( d1 , 3.0 );


  double_vector_append( d2 , 1.0 );
  double_vector_append( d2 , 2.0 );

  test_assert_false( double_vector_approx_equal( d1 , d2 ,1e-6));

  double_vector_append( d2 , 3.0 );
  test_assert_true( double_vector_approx_equal( d1 , d2 ,1e-6));
  
  double_vector_append( d3 , 1.0 );
  double_vector_append( d3 , 2.0 );
  double_vector_append( d3 , 3.0 );

  double_vector_scale( d3 , 1 + 1e-6 );
  test_assert_true( double_vector_approx_equal( d1 , d3 ,1e-4));
  test_assert_false( double_vector_approx_equal( d1 , d3 ,1e-8));


  double_vector_free(d1);
  double_vector_free(d2);
  double_vector_free(d3);
}
Exemplo n.º 3
0
void test_equal( ) {

  int lgr_nr = 1;
  nnc_info_type * nnc_info1 = nnc_info_alloc(lgr_nr);   
  nnc_info_type * nnc_info2 = nnc_info_alloc(lgr_nr);   

  test_assert_false( nnc_info_equal( NULL , nnc_info1 ));
  test_assert_false( nnc_info_equal( nnc_info1, NULL ));
  
  test_assert_true( nnc_info_equal( nnc_info1 , nnc_info2 ));

  
  nnc_info_add_nnc(nnc_info1, lgr_nr, 3 , 0);
  test_assert_false( nnc_info_equal( nnc_info1 , nnc_info2 ));

  nnc_info_add_nnc(nnc_info2, lgr_nr, 3 , 0);
  test_assert_true( nnc_info_equal( nnc_info1 , nnc_info2 ));
  
  nnc_info_add_nnc( nnc_info1 , lgr_nr + 1 , 10 , 10 );
  nnc_info_add_nnc( nnc_info2 , lgr_nr + 2 , 11 , 11 );
  test_assert_false( nnc_info_equal( nnc_info1 , nnc_info2 ));
  
  nnc_info_add_nnc( nnc_info1 , lgr_nr + 2 , 11 , 11 );
  nnc_info_add_nnc( nnc_info2 , lgr_nr + 1 , 10 , 10 );
  test_assert_true( nnc_info_equal( nnc_info1 , nnc_info2 ));
}
Exemplo n.º 4
0
void test_run_workflow(const char * config_file , const char * job_file) {
  ert_test_context_type * test_context = ert_test_context_alloc("INSTALL_WORKFLOW" , config_file , NULL );
  test_assert_false( ert_test_context_run_worklow( test_context , "No-does.not.exist"));
  
  ert_test_context_install_workflow_job( test_context , "JOB" , job_file );
  {
    FILE * stream1 = util_fopen( "WFLOW1", "w");
    FILE * stream2 = util_fopen( "WFLOW2", "w");
    stringlist_type * args = stringlist_alloc_new( );
    ert_test_context_fwrite_workflow_job( stream1 , "JOB" , args);
    stringlist_append_ref( args , "NewCase");
    ert_test_context_fwrite_workflow_job( stream2 , "JOB" , args);
        
    stringlist_free( args );
    fclose( stream1 );
    fclose( stream2 );
  }
  test_assert_true( ert_test_context_install_workflow( test_context , "WFLOW1" , "WFLOW1"));
  test_assert_true( ert_test_context_install_workflow( test_context , "WFLOW2" , "WFLOW2"));
  
  test_assert_true( ert_test_context_run_worklow( test_context , "WFLOW2"));
  test_assert_false( ert_test_context_run_worklow( test_context , "WFLOW1"));

  ert_test_context_free( test_context );
}
Exemplo n.º 5
0
void test_export( const ecl_grid_type * grid) {
  fault_block_layer_type * layer = fault_block_layer_alloc( grid , 0 );
  ecl_kw_type * ecl_kw1 = ecl_kw_alloc("FAULTBLK" , ecl_grid_get_global_size( grid )     , ECL_INT_TYPE );
  ecl_kw_type * ecl_kw2 = ecl_kw_alloc("FAULTBLK" , ecl_grid_get_global_size( grid ) + 1 , ECL_INT_TYPE );
  ecl_kw_type * ecl_kw3 = ecl_kw_alloc("FAULTBLK" , ecl_grid_get_global_size( grid )     , ECL_FLOAT_TYPE );
  fault_block_type * block = fault_block_layer_add_block( layer , 10 );
  
  fault_block_add_cell( block , 0 , 0 );
  fault_block_add_cell( block , 1 , 0 );
  fault_block_add_cell( block , 1 , 1 );
  fault_block_add_cell( block , 0 , 1 );


  test_assert_true( fault_block_layer_export( layer , ecl_kw1 ));
  test_assert_false( fault_block_layer_export( layer , ecl_kw2 ));
  test_assert_false( fault_block_layer_export( layer , ecl_kw3 ));

  {
    int nx = ecl_grid_get_nx( grid );
   
    test_assert_int_equal( ecl_kw_iget_int( ecl_kw1 , 0 ) , 10 );
    test_assert_int_equal( ecl_kw_iget_int( ecl_kw1 , 1 ) , 10 );
    test_assert_int_equal( ecl_kw_iget_int( ecl_kw1 , nx ) , 10 );
    test_assert_int_equal( ecl_kw_iget_int( ecl_kw1 , nx + 1 ) , 10 );
  }
  test_assert_int_equal( 40 , ecl_kw_element_sum_int( ecl_kw1 ));

  fault_block_layer_free( layer );
  ecl_kw_free( ecl_kw1 );
  ecl_kw_free( ecl_kw2 );
  ecl_kw_free( ecl_kw3 );
}
Exemplo n.º 6
0
void test_update_store() {
  {
    test_work_area_type * work_area = test_work_area_alloc( "update-store1" );
    char * work_cwd = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
    test_work_area_set_store( work_area , true );
    test_work_area_free( work_area );
    test_assert_true( util_entry_exists( work_cwd ));
  }

  {
    test_work_area_type * work_area = test_work_area_alloc( "update-store2" );
    char * work_cwd = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
    test_work_area_free( work_area );
    test_assert_false( util_entry_exists( work_cwd ));
  }

  {
    test_work_area_type * work_area = test_work_area_alloc( "update-store3" );
    char * work_cwd = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
    test_work_area_set_store( work_area , false );
    test_work_area_free( work_area );
    test_assert_false( util_entry_exists( work_cwd ));
  }

  {
    test_work_area_type * work_area = test_work_area_alloc( "update-store4" );
    char * work_cwd = util_alloc_string_copy( test_work_area_get_cwd( work_area ));
    test_work_area_set_store( work_area , true);
    test_work_area_free( work_area );
    test_assert_true( util_entry_exists( work_cwd ));
  }
}
Exemplo n.º 7
0
void test_fseek() {
  test_work_area_type * work_area = test_work_area_alloc("fortio_fseek" );
  {
    fortio_type * fortio = fortio_open_writer("PRESSURE" , false , true);
    void * buffer = util_malloc( 100 );

    fortio_fwrite_record( fortio , buffer , 100);
    free( buffer );

    fortio_fclose( fortio );
  }
  {
    fortio_type * fortio = fortio_open_reader("PRESSURE" , false , true);


    printf("Starting fssek test \n");
    test_assert_true( fortio_fseek( fortio , 0 , SEEK_SET ));
    test_assert_true( fortio_fseek( fortio , 0 , SEEK_END ));
    test_assert_false( fortio_fseek( fortio , 100000 , SEEK_END));
    test_assert_false( fortio_fseek( fortio , 100000 , SEEK_SET));

    fortio_fclose( fortio );
  }

  test_work_area_free( work_area );
}
Exemplo n.º 8
0
void simple_test() {
  time_map_type * time_map = time_map_alloc( );
  test_work_area_type * work_area = test_work_area_alloc("enkf_time_map" , true);
  const char * mapfile = "map";
  
  test_assert_true( time_map_update( time_map , 0 , 100 )   );
  test_assert_true( time_map_update( time_map , 1 , 200 )   );
  test_assert_true( time_map_update( time_map , 1 , 200 )   );
  test_assert_false( time_map_update( time_map , 1 , 250 )  );

  test_assert_true( time_map_equal( time_map , time_map ) );
  time_map_fwrite( time_map , mapfile);
  {
    time_map_type * time_map2 = time_map_alloc( );

    test_assert_false( time_map_equal( time_map , time_map2 ) );
    time_map_fread( time_map2 , mapfile );
    test_assert_true( time_map_equal( time_map , time_map2 )  );
    time_map_free( time_map2 );
  }
  {
    time_t mtime1 = util_file_mtime( mapfile );
    sleep(2);
    time_map_fwrite( time_map , mapfile);
    
    test_assert_time_t_equal( mtime1 , util_file_mtime( mapfile ) );
    time_map_update( time_map , 2 , 300 );
    time_map_fwrite( time_map , mapfile);
    test_assert_time_t_not_equal( mtime1 , util_file_mtime( mapfile ) );
  }
  test_work_area_free( work_area );
}
Exemplo n.º 9
0
int main(int argc , char ** argv) {
  const char * config_file = argv[1];
  config_parser_type * config = config_alloc();

  config_add_schema_item( config , "SET" , true );
  config_add_schema_item( config , "NOTSET" , false );

  {
    config_content_type * content = config_parse( config , config_file , "--" , "INCLUDE" , NULL , CONFIG_UNRECOGNIZED_IGNORE , true );
    test_assert_true( config_content_is_instance( content ));
    test_assert_true(config_content_is_valid( content ));

    test_assert_true( config_content_has_item( content , "SET" ));
    test_assert_false( config_content_has_item( content , "NOTSET" ) );
    test_assert_false( config_content_has_item( content , "UNKNOWN" ) );

    test_assert_true( config_has_schema_item( config , "SET" ));
    test_assert_true( config_has_schema_item( config , "NOTSET" ));
    test_assert_false( config_has_schema_item( config , "UNKNOWN" ));

    config_content_free( content );
  }

  exit(0);
}
Exemplo n.º 10
0
/** Unit test to check that the Membag allocates small and large chunks of
 *  memory correctly, and fails when a chunk that is too large is requested.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_membag_alloc_test(const struct test_case *test)
{
    void *data;

    /* Initialize membag system. */
    membag_init();

    /* Try to allocate a small chunk, should succeed. */
    data = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

    test_assert_false(test, data == NULL,
                      "Unable to allocate a small chunk!");

    /* Re-initialize the membag system. */
    membag_init();

    /* Try to allocate a large chunk, should succeed. */
    data = membag_alloc(CONF_TEST_ALLOC_SIZE_LARGE);

    test_assert_false(test, data == NULL,
                      "Unable to allocate a large chunk!");

    /* Try to allocate a massive (too large) chunk, should fail. */
    data = membag_alloc(CONF_TEST_ALLOC_SIZE_TOO_LARGE);

    test_assert_true(test, data == NULL,
                     "Should not be able to allocate a too-large chunk!");
}
Exemplo n.º 11
0
/** Unit test to check that the Membag re-allocates previously allocated and
 *  subsequently freed blocks of memory correctly.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_membag_realloc_test(const struct test_case *test)
{
    void *data;

    /* Initialize membag system. */
    membag_init();

    /* Allocate as many small chunks as there are sufficiently sized blocks. */
    while (membag_get_largest_free_block_size() >=
            CONF_TEST_ALLOC_SIZE_SMALL) {
        data = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

        test_assert_false(test, data == NULL,
                          "Unable to allocate a small chunk!");
    }

    /* Free last allocated chunk of memory */
    membag_free(data);

    /* Re-allocate a small chunk, should succeed by re-using the last freed
     * block of memory. */
    data = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

    test_assert_false(test, data == NULL,
                      "Unable to re-allocate a small chunk!");
}
Exemplo n.º 12
0
/** Unit test to check that the Membag frees previously allocated memory
 *  correctly.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_membag_free_test(const struct test_case *test)
{
    void *data1, *data2, *data3;

    /* Initialize membag system. */
    membag_init();

    /* Allocate three small chunks of data. */
    data1 = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);
    data2 = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);
    data3 = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

    /* Check that all three membag allocations completed successfully. */
    test_assert_false(test, (data1 == NULL) || (data2 == NULL) ||
                      (data3 == NULL),
                      "Less than three small chunks were allocated!");

    /* Check that all three membag allocations actually reserved sufficient
     *memory. */
    test_assert_false(test,
                      (membag_get_total() - membag_get_total_free()) <
                      (CONF_TEST_ALLOC_SIZE_SMALL * 3),
                      "Not enough memory was allocated!");

    membag_free(data1);
    membag_free(data2);
    membag_free(data3);

    /* Check that all memory has been returned to the membag. */
    test_assert_true(test, membag_get_total() == membag_get_total_free(),
                     "Not all memory is free!");
}
Exemplo n.º 13
0
int main(int argc , char ** argv) {
    enkf_main_install_SIGNALS();

    const char * config_file             = argv[1];
    ert_test_context_type * test_context = ert_test_context_alloc("VerifyJobsFileTest" , config_file);
    enkf_main_type * enkf_main           = ert_test_context_get_main(test_context);

    {
        const int ens_size         = enkf_main_get_ensemble_size( enkf_main );
        bool_vector_type * iactive = bool_vector_alloc(0, false);
        bool_vector_iset( iactive , ens_size - 1 , true );

        enkf_main_create_run_path(enkf_main , iactive , 0);
        bool_vector_free(iactive);
    }

    const char * filename = util_alloc_filename(ert_test_context_get_cwd(test_context),
                            "simulations/run0/jobs.py", NULL);
    const char * jobs_file_content = util_fread_alloc_file_content(filename, NULL);

    test_assert_true  (strstr(jobs_file_content, "umask = 0022") != NULL);
    test_assert_false (strstr(jobs_file_content, "umask = 0023") != NULL);
    test_assert_false (strstr(jobs_file_content, "umask = 0032") != NULL);
    test_assert_false (strstr(jobs_file_content, "umask = 0122") != NULL);
    test_assert_false (strstr(jobs_file_content, "umask = 1022") != NULL);

    ert_test_context_free(test_context);
    exit(0);
}
Exemplo n.º 14
0
void test_at_eof() {
  test_work_area_type * work_area = test_work_area_alloc("fortio_truncated2" );
  {
    fortio_type * fortio = fortio_open_writer("PRESSURE" , false , true);
    void * buffer = util_malloc( 100 );

    fortio_fwrite_record( fortio , buffer , 100);
    free( buffer );

    fortio_fclose( fortio );
  }
  {
    fortio_type * fortio = fortio_open_reader("PRESSURE" , false , true);

    test_assert_false( fortio_read_at_eof( fortio ));
    fortio_fseek( fortio , 50 , SEEK_SET );
    test_assert_false( fortio_read_at_eof( fortio ));
    fortio_fseek( fortio , 0 , SEEK_END );
    test_assert_true( fortio_read_at_eof( fortio ));

    fortio_fclose( fortio );
  }

  test_work_area_free( work_area );
}
Exemplo n.º 15
0
int main(int argc , char ** argv) {
  test_install_SIGNALS();

  double * rseg_data = util_calloc( 100 , sizeof * rseg_data );
  well_segment_collection_type * sc = well_segment_collection_alloc();
  test_assert_not_NULL( sc );
  test_assert_int_equal( well_segment_collection_get_size( sc ) , 0 );

  {
    int outlet_segment_id = ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE;
    int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE;
    well_segment_type * ws = well_segment_alloc(89 , outlet_segment_id , branch_nr, rseg_data);
    
    well_segment_collection_add( sc , ws );
    test_assert_int_equal( well_segment_collection_get_size( sc ) , 1);
    test_assert_ptr_equal( well_segment_collection_iget( sc , 0 ) , ws );
    
    test_assert_false( well_segment_collection_has_segment( sc , 451 ));
    test_assert_true( well_segment_collection_has_segment( sc , 89 ));
    test_assert_ptr_equal( well_segment_collection_get( sc , 89 ) , ws );
  }

  {
    int outlet_segment_id = ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE;
    int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE;
    well_segment_type * ws = well_segment_alloc(90 , outlet_segment_id , branch_nr , rseg_data);
    
    well_segment_collection_add( sc , ws );
    test_assert_int_equal( well_segment_collection_get_size( sc ) , 2);
    test_assert_ptr_equal( well_segment_collection_iget( sc , 1 ) , ws );
    
    test_assert_false( well_segment_collection_has_segment( sc , 451 ));
    test_assert_true( well_segment_collection_has_segment( sc , 89 ));
    test_assert_true( well_segment_collection_has_segment( sc , 90 ));
    test_assert_ptr_equal( well_segment_collection_get( sc , 90 ) , ws );
    test_assert_NULL( well_segment_collection_get( sc , 76 ));
  }

  {
    int outlet_segment_id = ECLIPSE_WELL_SEGMENT_OUTLET_END_VALUE;
    int branch_nr = ECLIPSE_WELL_SEGMENT_BRANCH_INACTIVE_VALUE;
    well_segment_type * ws = well_segment_alloc(89 , outlet_segment_id , branch_nr, rseg_data);
    
    well_segment_collection_add( sc , ws );
    test_assert_int_equal( well_segment_collection_get_size( sc ) , 2);
    test_assert_ptr_equal( well_segment_collection_iget( sc , 0 ) , ws );
    
    test_assert_false( well_segment_collection_has_segment( sc , 451 ));
    test_assert_true( well_segment_collection_has_segment( sc , 89 ));
    test_assert_ptr_equal( well_segment_collection_get( sc , 89 ) , ws );
  }
  
  free( rseg_data );
  well_segment_collection_free( sc );
  
  exit(0);
}
Exemplo n.º 16
0
void test_install_job( const char * config_file, const char * job_file_OK , const char * job_file_ERROR) {
  ert_test_context_type * test_context = ert_test_context_alloc("CREATE_CONTEXT_JOB" , config_file , NULL );

  test_assert_false( ert_test_context_install_workflow_job( test_context , "JOB" , "File/does/not/exist"));
  test_assert_false( ert_test_context_install_workflow_job( test_context , "ERROR" , job_file_ERROR));
  test_assert_true( ert_test_context_install_workflow_job( test_context , "OK" , job_file_OK));
  
  ert_test_context_free( test_context );
}
Exemplo n.º 17
0
void test_wrapper( const char * filename ) {
  FILE * stream = util_fopen( filename , "r");
  fortio_type * fortio = fortio_alloc_FILE_wrapper( filename , false , false , stream );
  test_assert_not_NULL( fortio );
  test_assert_false( fortio_fclose_stream( fortio ));
  test_assert_false( fortio_fopen_stream( fortio ));
  test_assert_true( fortio_stream_is_open( fortio ));
  fortio_free_FILE_wrapper( fortio );
  fclose( stream );
}
Exemplo n.º 18
0
void test_dims() {
  const int rows = 10;
  const int columns = 13;
  matrix_type * m = matrix_alloc(rows , columns);

  test_assert_true(  matrix_check_dims(m , rows , columns));
  test_assert_false( matrix_check_dims(m , rows + 1 , columns));
  test_assert_false( matrix_check_dims(m , rows , columns + 1));

  matrix_free( m );
}
Exemplo n.º 19
0
void test_chdir() {
  test_work_area_type * work_area = test_work_area_alloc("test-area");
  const char * cwd = test_work_area_get_cwd( work_area );

  test_assert_false( util_chdir_file( "/file/does/not/exist"));
  test_assert_false( util_chdir_file( cwd ));
  {
    FILE * stream = util_mkdir_fopen("path/FILE","w");
    fclose( stream );
  }
  test_assert_true( util_chdir_file( "path/FILE" ));
  test_assert_string_equal( util_alloc_cwd() , util_alloc_filename( cwd, "path", NULL));
  test_work_area_free( work_area );
}
Exemplo n.º 20
0
void test_current_module_options() {
  analysis_config_type * ac = create_analysis_config( );
  test_assert_NULL( analysis_config_get_active_module( ac ));
  analysis_config_load_internal_module(ac , "STD_ENKF" , "std_enkf_symbol_table");

  test_assert_false( analysis_config_get_module_option( ac , ANALYSIS_SCALE_DATA));
  test_assert_true(analysis_config_select_module(ac , "STD_ENKF"));
  test_assert_false( analysis_config_select_module(ac , "DOES_NOT_EXIST"));

  test_assert_true( analysis_module_is_instance( analysis_config_get_active_module( ac )));
  test_assert_true( analysis_config_get_module_option( ac , ANALYSIS_SCALE_DATA));
  test_assert_false( analysis_config_get_module_option( ac , ANALYSIS_ITERABLE));
  analysis_config_free( ac );
}
Exemplo n.º 21
0
void test_open_close_read( const char * filename ) {
  fortio_type * fortio = fortio_open_reader( filename , false , ECL_ENDIAN_FLIP);
  test_assert_not_NULL( fortio );

  test_assert_true( fortio_stream_is_open( fortio ));
  test_assert_true( fortio_fclose_stream( fortio ));
  test_assert_false( fortio_stream_is_open( fortio ));
  test_assert_false( fortio_fclose_stream( fortio ));
  test_assert_true( fortio_fopen_stream( fortio ));
  test_assert_true( fortio_stream_is_open( fortio ));
  test_assert_false( fortio_fopen_stream( fortio ));

  fortio_fclose( fortio );
}
Exemplo n.º 22
0
void test_contains_sorted() {
  int_vector_type * int_vector = int_vector_alloc( 0 , 100);
  
  int_vector_append( int_vector , 99 );
  int_vector_append( int_vector , 89 );
  int_vector_append( int_vector , 79 );
  int_vector_append( int_vector , 109 );

  int_vector_sort( int_vector );

  test_assert_false( int_vector_contains( int_vector , 0 ));
  test_assert_false( int_vector_contains( int_vector , 100 ));
  test_assert_true( int_vector_contains( int_vector , 89 ));
  test_assert_true( int_vector_contains( int_vector , 109 ));
}
Exemplo n.º 23
0
void test_contains() {
  int_vector_type * int_vector = int_vector_alloc( 0 , 100);
  
  test_assert_false( int_vector_contains( int_vector , 100 ));
  int_vector_iset( int_vector , 0 , 77 );
  test_assert_false( int_vector_contains( int_vector , 100 ));
  test_assert_true( int_vector_contains( int_vector , 77 ));

  int_vector_iset( int_vector , 10 , 33 );
  test_assert_true( int_vector_contains( int_vector , 100 ));
  test_assert_true( int_vector_contains( int_vector , 77 ));
  test_assert_true( int_vector_contains( int_vector , 33 ));

  int_vector_free( int_vector );
}
Exemplo n.º 24
0
void test_cmp_string() {
  ecl_kw_type * ecl_kw = ecl_kw_alloc( "HEADER" , 1 , ECL_CHAR);

  ecl_kw_iset_string8( ecl_kw , 0 , "ABCD");

  test_assert_int_equal( 0 , strcmp( ecl_kw_iget_char_ptr( ecl_kw , 0 ) , "ABCD    "));
  test_assert_true(ecl_kw_icmp_string( ecl_kw , 0 , "ABCD"));
  test_assert_true(ecl_kw_icmp_string( ecl_kw , 0 , "ABCD    "));
  test_assert_true(ecl_kw_icmp_string( ecl_kw , 0 , "ABCD "));

  test_assert_false( ecl_kw_icmp_string( ecl_kw , 0 , "Different"));
  test_assert_false( ecl_kw_icmp_string( ecl_kw , 0 , ""));
  test_assert_false( ecl_kw_icmp_string( ecl_kw , 0 , ""));

}
Exemplo n.º 25
0
int main(int argc , char ** argv) {
  test_install_SIGNALS();
  {
    const char * grid_file = argv[1];
    const char * rst_file_name = argv[2];

    ecl_grid_type * grid = ecl_grid_alloc( grid_file );
    ecl_file_type * rst_file = ecl_file_open( rst_file_name , 0);
    ecl_rsthead_type * header = ecl_rsthead_alloc( ecl_file_get_global_view( rst_file ) , ecl_util_filename_report_nr(rst_file_name) );
    const char * well_name = "WELL";
    int report_nr = 100;
    time_t valid_from = -1;
    bool open = false;
    well_type_enum type = ERT_GAS_INJECTOR;
    int global_well_nr = 0;
    bool load_segment_information = true;
    ecl_file_view_type * rst_view = ecl_file_get_global_view( rst_file );

    for (global_well_nr = 0; global_well_nr < header->nwells; global_well_nr++) {
      well_state_type * well_state = well_state_alloc(well_name , global_well_nr , open , type , report_nr , valid_from);
      test_assert_true( well_state_is_instance( well_state) );
      well_state_add_connections2( well_state , grid , rst_view , 0 );

      test_assert_true( well_state_has_grid_connections( well_state , ECL_GRID_GLOBAL_GRID ));
      test_assert_false( well_state_has_grid_connections( well_state , "???" ));
      test_assert_true( well_state_has_global_connections( well_state ));

      well_state_add_MSW2( well_state , rst_view , global_well_nr , load_segment_information );
      {
        const well_segment_collection_type * segments = well_state_get_segments( well_state );
        const well_branch_collection_type * branches = well_state_get_branches( well_state );

        if (well_state_is_MSW( well_state )) {
          test_assert_true( ecl_file_has_kw( rst_file , ISEG_KW ));
          test_assert_int_not_equal( well_segment_collection_get_size( segments ) , 0);
          test_assert_int_not_equal( well_branch_collection_get_size( branches ) , 0);
        } else {
          test_assert_int_equal( well_segment_collection_get_size( segments ) , 0);
          test_assert_int_equal( well_branch_collection_get_size( branches ) , 0);
          test_assert_false( well_state_is_MSW( well_state ));
        }
      }
      well_state_free( well_state );
    }
  }

  exit(0);
}
Exemplo n.º 26
0
void create_test() {
  state_map_type * state_map = state_map_alloc();
  test_assert_true( state_map_is_instance( state_map ));
  test_assert_int_equal( 0 , state_map_get_size( state_map ));
  test_assert_false( state_map_is_readonly( state_map ));
  state_map_free( state_map );
}
Exemplo n.º 27
0
/** Unit test to check that the Membag is initialized and re-initialized
 *  correctly.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_membag_init_test(const struct test_case *test)
{
    /* Initialize membag system. */
    membag_init();

    /* Check that no memory is currently allocated */
    test_assert_true(test, membag_get_total() == membag_get_total_free(),
                     "Initialized membag should contain no allocated memory!");

    /* Allocate a small chunk of memory */
    membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

    /* Check that sufficient memory was allocated */
    test_assert_false(test,
                      (membag_get_total() - membag_get_total_free()) < CONF_TEST_ALLOC_SIZE_SMALL,
                      "Not enough memory was allocated!");

    /* Re-Initialize membag system. */
    membag_init();

    /* Check that no memory is now allocated */
    test_assert_true(test,
                     membag_get_total() == membag_get_total_free(),
                     "Re-Initialized membag should contain no allocated memory!");
}
Exemplo n.º 28
0
/** Unit test to check that the Membag functions to determine memory status work
 *  correctly.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_membag_get_test(const struct test_case *test)
{
    void *data;
    size_t prev_total_free, chunk_size;

    /* Initialize membag system. */
    membag_init();

    prev_total_free = membag_get_total_free();

    /* Keep allocating chunks until all memory allocated */
    while (membag_get_total_free() > 0) {
        /* Keep track of how much memory we have left and the largest
         * block size */
        prev_total_free = membag_get_total_free();
        chunk_size = membag_get_largest_free_block_size();

        /* Allocate the next largest block sized chunk of memory */
        data = membag_alloc(chunk_size);
        test_assert_false(test, data == NULL,
                          "Unable to allocate a block sized chunk!");

        /* Check that the new memory usage was calculated correctly */
        test_assert_true(test, membag_get_total_free() ==
                         (prev_total_free - chunk_size),
                         "Failed to calculate correct memory usage!");
    }
}
Exemplo n.º 29
0
void test_fread_truncated_tail() {
  test_work_area_type * work_area = test_work_area_alloc("fortio_truncated2" );
  {
    const size_t buffer_size = 1000;
    void * buffer = util_malloc( buffer_size );
    {
      fortio_type * fortio = fortio_open_writer( "PRESSURE" , false , true );

      fortio_fwrite_record( fortio , buffer , buffer_size );
      fortio_fseek( fortio , 0 , SEEK_SET);
      util_ftruncate( fortio_get_FILE(fortio) , buffer_size + 4);
      fortio_fclose( fortio );
    }

    test_assert_long_equal( util_file_size( "PRESSURE") , buffer_size + 4);

    {
      fortio_type * fortio = fortio_open_reader( "PRESSURE" , false , true );
      test_assert_false( fortio_fread_buffer( fortio , buffer , buffer_size ));
      fortio_fclose( fortio );
    }
    free( buffer );
  }
  test_work_area_free( work_area );
}
Exemplo n.º 30
0
void test_fread_invalid_tail() {
  test_work_area_type * work_area = test_work_area_alloc("fortio_invalid" );
  int record_size = 10;
  void * buffer = util_malloc( record_size );
  {
    FILE * stream = util_fopen("PRESSURE" , "w");

    util_fwrite(&record_size , sizeof record_size , 1 , stream , __func__);
    util_fwrite(buffer       , 1                  , record_size , stream , __func__);
    util_fwrite(&record_size , sizeof record_size , 1 , stream , __func__);


    util_fwrite(&record_size , sizeof record_size , 1 , stream , __func__);
    util_fwrite(buffer       , 1 , record_size , stream , __func__);
    record_size += 1;
    util_fwrite(&record_size , sizeof record_size , 1 , stream , __func__);

    fclose(stream);
  }
  {
    fortio_type * fortio = fortio_open_reader( "PRESSURE" , false , false );
    record_size -= 1;
    test_assert_true( fortio_fread_buffer( fortio , buffer , record_size ));
    test_assert_false( fortio_fread_buffer( fortio , buffer , record_size ));
    fortio_fclose( fortio );
  }

  free( buffer );
  test_work_area_free( work_area );
}