Esempio n. 1
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 ));
  }
}
Esempio n. 2
0
void test_create_simple() {
  test_work_area_type * work_area = test_work_area_alloc("nnc-INIT");
  {
    int nx = 10;
    int ny = 10;
    int nz = 10;
    ecl_grid_type * grid0 = ecl_grid_alloc_rectangular(nx,ny,nz,1,1,1,NULL);

    ecl_grid_add_self_nnc(grid0, 0 ,nx*ny + 0, 0 );
    ecl_grid_add_self_nnc(grid0, 1 ,nx*ny + 1, 1 );
    ecl_grid_add_self_nnc(grid0, 2 ,nx*ny + 2, 2 );
    {
      ecl_nnc_geometry_type * nnc_geo = ecl_nnc_geometry_alloc( grid0 );
      test_assert_int_equal( ecl_nnc_geometry_size( nnc_geo ) , 3 );

      /*
        Create a dummy INIT file which *ony* contains a TRANNC keyword with the correct size.
      */
      {
        ecl_kw_type * trann_nnc = ecl_kw_alloc(TRANNNC_KW , ecl_nnc_geometry_size( nnc_geo ), ECL_FLOAT);
        fortio_type * f = fortio_open_writer( "TEST.INIT" , false, ECL_ENDIAN_FLIP );

        for (int i=0; i < ecl_kw_get_size( trann_nnc); i++)
          ecl_kw_iset_float( trann_nnc , i , i*1.0 );

        ecl_kw_fwrite( trann_nnc , f );
        fortio_fclose( f );
        ecl_kw_free( trann_nnc );
      }
    }
    ecl_grid_free( grid0 );
  }
  test_work_area_free( work_area );
}
Esempio n. 3
0
int main(int argc , char ** argv) {
  bool ok;
  const char * input_path = argv[1];
  const char  * tex_file = argv[2];
  test_work_area_type * work_area = test_work_area_alloc("latex-test");
  test_work_area_copy_parent_content(work_area , input_path );
  {
    bool in_place = false;
    latex_type * latex = latex_alloc( tex_file , in_place);
    ok = latex_compile( latex , true , true , true);
    test_assert_true( in_place == latex_compile_in_place( latex ));
    latex_free( latex );
    test_assert_true( ok );
  }

  {
    latex_type * latex = latex_alloc( tex_file , false );
    test_latex_link( latex );
    latex_free( latex );
  }

  {
    bool in_place = true;
    latex_type * latex = latex_alloc( tex_file , in_place);
    test_assert_true( in_place == latex_compile_in_place( latex ));
    test_latex_link( latex );
    latex_free( latex );
  }
  test_work_area_free(work_area);
  exit(0);
}
Esempio n. 4
0
void test_get_original_cwd() {
   char * cwd = util_alloc_cwd();
   test_work_area_type * work_area = test_work_area_alloc( "CWD-ORG-TEST");
   test_assert_string_equal( cwd , test_work_area_get_original_cwd( work_area ));
   free( cwd );
   test_work_area_free( work_area );
}
Esempio n. 5
0
void create_submit_script_script_according_to_input() {
  test_work_area_type * work_area = test_work_area_alloc("job_torque_test" , true);
  const char * script_filename = "qsub_script.sh";

  {
    char ** args = util_calloc(2, sizeof * args);
    args[0] = "/tmp/jaja/";
    args[1] = "number2arg";
    torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args);
    free( args );
  }
  
  {
    FILE* file_stream = util_fopen(script_filename, "r");
    bool at_eof = false;
    
    char * line = util_fscanf_alloc_line(file_stream, &at_eof);
    test_assert_string_equal("#!/bin/sh", line);
    free(line);

    line = util_fscanf_alloc_line(file_stream, &at_eof);
    test_assert_string_equal("job_program.py /tmp/jaja/ number2arg", line);
    free(line);

    line = util_fscanf_alloc_line(file_stream, &at_eof);
    free(line);
    test_assert_true(at_eof);

    fclose(file_stream);
  }
  test_work_area_free( work_area );
}
Esempio n. 6
0
int main( int argc , char ** argv) {
  util_install_signals();
  {
    const char * file = argv[1];

    test_fortio_is_instance( file );
    test_fortio_safe_cast( file );
    test_assert_util_abort("fortio_safe_cast", test_fortio_unsafe_cast, NULL);
    test_existing_read( file );
    test_not_existing_read( );
    test_open_close_read( file );
    test_wrapper( file );
    test_fread_truncated_head();
    test_fread_truncated_data();
    test_fread_truncated_tail();
    test_fread_invalid_tail();
    test_fseek();
    test_at_eof();

    test_write( "/tmp/path/does/not/exist" , false );
    {
      test_work_area_type * work_area = test_work_area_alloc("ecl_fortio.write" );
      util_make_path("path");
      test_write( "path/file.x" , true );
      test_work_area_free( work_area );
    }

    exit(0);
  }
}
Esempio n. 7
0
void test_fortio_kw() {
    test_work_area_type * work_area = test_work_area_alloc("fortio_kw");
    ERT::EclKW<int> kw("XYZ" , 1000);
    for (size_t i =0 ; i < kw.size(); i++)
        kw[i] = i;

    {
        ERT::FortIO fortio("new_file" , std::fstream::out );
        kw.fwrite( fortio );
        fortio.close();
    }

    {
        ERT::FortIO fortio("new_file" , std::fstream::in );
        ERT::EclKW<int> kw2 = ERT::EclKW<int>::load( fortio );
        fortio.close( );
        for (size_t i =0 ; i < kw.size(); i++)
            test_assert_int_equal( kw[i] , kw2[i]);


        fortio = ERT::FortIO("new_file" , std::fstream::in );
	test_assert_throw( ERT::EclKW<float>::load(fortio) , std::invalid_argument );
        fortio.close();
    }

    test_work_area_free( work_area );
}
Esempio n. 8
0
void test_copy_parent_content( const char * path ) {
  char * full_path = util_alloc_abs_path( path );
  char * parent_path = util_alloc_parent_path( full_path );
  test_work_area_type * work_area = test_work_area_alloc( "copy-parent-content" );

  test_assert_false( test_work_area_copy_parent_content( work_area , "Does/not/exist") );
  test_assert_true( test_work_area_copy_parent_content( work_area , path ) );

  {

    struct dirent ** src_namelist;
    struct dirent ** target_namelist;
    int src_size    = scandir( parent_path                         , &src_namelist    , NULL , alphasort);
    int target_size = scandir( test_work_area_get_cwd( work_area ) , &target_namelist , NULL , alphasort);

    test_assert_int_equal( src_size , target_size );
    for (int i=0; i < src_size; i++) {
      test_assert_string_equal( src_namelist[i]->d_name , target_namelist[i]->d_name);

      free( src_namelist[i] );
      free( target_namelist[i] );
    }

    free( src_namelist );
    free( target_namelist );
  }
  free( parent_path );
  free( full_path );

  test_work_area_free( work_area );
}
Esempio n. 9
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 );
}
Esempio n. 10
0
void test_fortio() {
    test_work_area_type * work_area = test_work_area_alloc("fortio");

    ERT::FortIO fortio("new_file" , std::fstream::out );
    {
        std::vector<int> data;
        for (size_t i=0; i < 1000; i++)
            data.push_back(i);

        fortio_fwrite_record( fortio.getPointer() , reinterpret_cast<char *>(data.data()) , 1000 * 4 );
    }
    fortio.close();

    fortio = ERT::FortIO("new_file" , std::fstream::in );
    {
        std::vector<int> data;
        for (size_t i=0; i < 1000; i++)
            data.push_back(99);

        test_assert_true( fortio_fread_buffer( fortio.getPointer() , reinterpret_cast<char *>(data.data()) , 1000 * 4 ) );
        for (size_t i =0; i < 1000; i++)
            test_assert_size_t_equal(data[i], i);

    }
    fortio.close();
    test_work_area_free( work_area );

    test_assert_throw( ERT::FortIO fortio("file/does/not/exists" , std::fstream::in) , std::invalid_argument );
}
Esempio n. 11
0
void test_filter_file1() {
  subst_list_type * subst_list = subst_list_alloc( NULL );
  test_work_area_type * work_area = test_work_area_alloc("subst_list/filter1");
  {
    FILE * stream = util_fopen("template" , "w");
    fprintf(stream , "<KEY1>\n<KEY2>\n<KEY3>\n<KEY4>\n");
    fclose(stream);
  }
  subst_list_append_copy( subst_list , "<KEY1>" , "Value1" , NULL);
  subst_list_append_copy( subst_list , "<KEY2>" , "Value2" , NULL);
  subst_list_append_copy( subst_list , "<KEY3>" , "Value3" , NULL);
  subst_list_append_copy( subst_list , "<KEY4>" , "Value4" , NULL);

  subst_list_filter_file( subst_list , "template" , "target");

  {
    FILE * stream = util_fopen("target" , "r");
    char s1[128],s2[128],s3[128],s4[128];

    test_assert_int_equal( 4 , fscanf( stream , "%s %s %s %s" , s1,s2,s3,s4));
    fclose(stream);

    test_assert_string_equal( s1 , "Value1");
    test_assert_string_equal( s2 , "Value2");
    test_assert_string_equal( s3 , "Value3");
    test_assert_string_equal( s4 , "Value4");
  }
  test_work_area_free( work_area );
  subst_list_free( subst_list );
}
Esempio n. 12
0
void test_get_cwd() {
   test_work_area_type * work_area = test_work_area_alloc( "CWD-TEST", false);
   char * cwd = util_alloc_cwd();
   test_assert_string_equal( cwd , test_work_area_get_cwd( work_area ));
   free( cwd );
   test_work_area_free( work_area );
}
Esempio n. 13
0
void test_min_realizations_percent(const char * num_realizations_str, const char * min_realizations_str, int min_realizations){
  test_work_area_type * work_area = test_work_area_alloc("test_min_realizations");

  {
    FILE * config_file_stream = util_mkdir_fopen("config_file", "w");
    test_assert_not_NULL(config_file_stream);
    fprintf(config_file_stream, num_realizations_str);
    fprintf(config_file_stream, min_realizations_str);
    fclose(config_file_stream);

    config_type * c = config_alloc();
    config_schema_item_type * item = config_add_schema_item(c , NUM_REALIZATIONS_KEY , true );
    config_schema_item_set_default_type(item, CONFIG_INT);
    config_schema_item_set_argc_minmax( item , 1 , 1);
    item = config_add_schema_item(c , MIN_REALIZATIONS_KEY , false );
    config_schema_item_set_argc_minmax( item , 1 , 2);
    test_assert_true(config_parse(c , "config_file" , "--" , NULL , NULL , false , true ));

    analysis_config_type * ac = create_analysis_config( );
    analysis_config_init(ac, c);

    test_assert_int_equal( min_realizations , analysis_config_get_min_realisations( ac ) );

    analysis_config_free( ac );
    config_free( c );
  }

  test_work_area_free(work_area);
}
Esempio n. 14
0
void test_truncated() {
  test_work_area_type * work_area = test_work_area_alloc("ecl_file_truncated" );
  {
    ecl_grid_type * grid = ecl_grid_alloc_rectangular(20,20,20,1,1,1,NULL);
    ecl_grid_fwrite_EGRID2( grid , "TEST.EGRID", ECL_METRIC_UNITS );
    ecl_grid_free( grid );
  }
  {
    ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 );
    test_assert_true( ecl_file_is_instance( ecl_file ) );
    ecl_file_close( ecl_file );
  }

  {
    offset_type file_size = util_file_size( "TEST.EGRID");
    FILE * stream = util_fopen("TEST.EGRID" , "r+");
    util_ftruncate( stream , file_size / 2 );
    fclose( stream );
  }
  {
    ecl_file_type * ecl_file = ecl_file_open("TEST.EGRID" , 0 );
    test_assert_NULL( ecl_file );
  }
  test_work_area_free( work_area );
}
Esempio n. 15
0
void test_fread_alloc() {
  test_work_area_type * work_area = test_work_area_alloc("ecl_kw_fread" );
  {
    ecl_kw_type * kw1 = ecl_kw_alloc( "INT" , 100 , ECL_INT );
    int i;
    for (i=0; i < 100; i++)
      ecl_kw_iset_int( kw1 , i , i );
    {
      fortio_type * fortio = fortio_open_writer("INT" , false , true );
      ecl_kw_fwrite( kw1 , fortio );
      fortio_fclose( fortio );
    }
    {
      fortio_type * fortio = fortio_open_reader("INT" , false , true );
      ecl_kw_type * kw2 = ecl_kw_fread_alloc( fortio );
      test_assert_true( ecl_kw_is_instance( kw2 ));
      test_assert_true( ecl_kw_equal( kw1 , kw2 ));
      ecl_kw_free( kw2 );
      fortio_fclose( fortio );
    }

    {
      offset_type file_size = util_file_size("INT");
      test_truncated("INT" , file_size - 4 );
      test_truncated("INT" , file_size - 25 );
      test_truncated("INT" , 5 );
      test_truncated("INT" , 0 );
    }
    ecl_kw_free( kw1 );
  }
  test_work_area_free( work_area );
}
Esempio n. 16
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 );
}
Esempio n. 17
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 );
}
Esempio n. 18
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 );
}
Esempio n. 19
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 );
}
Esempio n. 20
0
void test_readonly() {
  {
    state_map_type * map1 = state_map_fread_alloc_readonly("FileDoesNotExist");
    
    test_assert_true(state_map_is_instance(map1));
    test_assert_int_equal(0 , state_map_get_size( map1 ));
    test_assert_true( state_map_is_readonly( map1 ));
    state_map_free(map1);
  }
  {
    test_work_area_type * work_area = test_work_area_alloc("state-map");
    state_map_type * map1 = state_map_alloc();
    
    state_map_iset(map1 , 5 , STATE_INITIALIZED);
    state_map_iset(map1 , 9 , STATE_INITIALIZED);

    state_map_fwrite(map1 , "map1");
    {
      state_map_type * map2 = state_map_fread_alloc_readonly("map1");
      
      test_assert_true(state_map_equal(map1 , map2));
      state_map_free(map2);
    }
    test_work_area_free( work_area );
    state_map_free(map1);
  }
}
Esempio n. 21
0
void test_io( ) {
  test_work_area_type * work_area = test_work_area_alloc( "enkf-state-map" );
  {
    state_map_type * state_map = state_map_alloc();
    state_map_type * copy1 , *copy2;
    state_map_iset( state_map , 0 , STATE_INITIALIZED );
    state_map_iset( state_map , 100 , STATE_INITIALIZED );
    state_map_fwrite( state_map , "map");
    
    copy1 = state_map_fread_alloc( "map" );
    test_assert_true( state_map_equal( state_map , copy1 ));
    
    copy2 = state_map_alloc();
    state_map_fread( copy2 , "map" );
    test_assert_true( state_map_equal( state_map , copy2 ));

    state_map_iset( copy2 , 67 , STATE_INITIALIZED );
    test_assert_false(state_map_equal( state_map , copy2 ));
    
    state_map_fread( copy2 , "map");
    test_assert_true( state_map_equal( state_map , copy2 ));

    state_map_fread( copy2 , "DoesNotExis");
    test_assert_int_equal( 0 , state_map_get_size( copy2 ));
  }
  test_work_area_free( work_area );
}
Esempio n. 22
0
void test_install_file_exists(const char * filename ) {
  char * abs_input_path = util_alloc_abs_path( filename );
  test_work_area_type * work_area = test_work_area_alloc( "FILE-TEST" );

  test_work_area_install_file( work_area , filename );
  test_assert_true( util_files_equal( abs_input_path , filename ));
  test_work_area_free( work_area );
  free( abs_input_path );
}
Esempio n. 23
0
int main(int argc, char ** argv) {
  test_work_area_type * work_area = test_work_area_alloc( "bsub_parse_stdout");
  {
    test_empty_file();
    test_file_does_not_exist( );
    test_OK();
    test_parse_fail_abort();
  }
  test_work_area_free( work_area );
}
Esempio n. 24
0
void test_copy_file( const char * src_file ) {
  char * filename = util_split_alloc_filename( src_file );
  test_work_area_type * work_area = test_work_area_alloc( "copy-file" );
  test_work_area_copy_file( work_area , src_file );

  test_assert_true( util_file_exists( filename ));

  test_work_area_free( work_area );
  free( filename );
}
Esempio n. 25
0
void test_write_header() {
    int nx = 10;
    int ny = 10;
    int nz = 5;

    int_vector_type * actnum = int_vector_alloc( nx*ny*nz , 1 );
    test_work_area_type * test_area = test_work_area_alloc( "ecl_init_file" );
    time_t start_time = util_make_date(15 , 12 , 2010 );
    ecl_grid_type * ecl_grid;

    int_vector_iset( actnum , 10 , 0 );
    int_vector_iset( actnum , 100 , 0 );

    ecl_grid = ecl_grid_alloc_rectangular(nx, ny, nz, 1, 1, 1, int_vector_get_ptr( actnum ));

    // Write poro with global size.
    {
        fortio_type * f = fortio_open_writer( "FOO1.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE );
        ecl_kw_scalar_set_float( poro , 0.10 );
        ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time );
        ecl_kw_free( poro );
        fortio_fclose( f );
    }


    // Write poro with nactive size.
    {
        fortio_type * f = fortio_open_writer( "FOO2.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_kw_type * poro = ecl_kw_alloc( "PORO" , ecl_grid_get_global_size( ecl_grid ) , ECL_FLOAT_TYPE );
        ecl_kw_scalar_set_float( poro , 0.10 );
        ecl_init_file_fwrite_header( f , ecl_grid , poro , 7 , start_time );
        ecl_kw_free( poro );
        fortio_fclose( f );
    }
    {
        ecl_file_type * file1 = ecl_file_open( "FOO1.INIT" , 0 );
        ecl_file_type * file2 = ecl_file_open( "FOO2.INIT" , 0 );

        test_assert_true( ecl_kw_equal( ecl_file_iget_named_kw( file1 , "PORV" , 0 ) ,
                                        ecl_file_iget_named_kw( file2 , "PORV" , 0)));

        ecl_file_close( file2 );
        ecl_file_close( file1 );
    }


    // Poro == NULL
    {
        fortio_type * f = fortio_open_writer( "FOO3.INIT" , false , ECL_ENDIAN_FLIP );
        ecl_init_file_fwrite_header( f , ecl_grid , NULL , 7 , start_time );
        fortio_fclose( f );
    }
    test_work_area_free( test_area );
}
Esempio n. 26
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 );
}
Esempio n. 27
0
int main(int argc , char ** argv) {
  enkf_main_install_SIGNALS();
  const char * root_path   = argv[1];
  const char * config_file = argv[2];
  const char * init_file   = argv[3];
  const char * forward_init_string = argv[4];
  
  test_work_area_type * work_area = test_work_area_alloc(config_file );
  test_work_area_copy_directory_content( work_area , root_path );
  test_work_area_install_file( work_area , init_file );
  test_work_area_set_store(work_area, true); 
  
  bool strict = true;
  enkf_main_type * enkf_main = enkf_main_bootstrap( NULL , config_file , strict , true );
  enkf_fs_type * init_fs = enkf_main_get_fs(enkf_main);
  enkf_state_type * state = enkf_main_iget_state( enkf_main , 0 );
  run_arg_type * run_arg = run_arg_alloc_ENSEMBLE_EXPERIMENT( init_fs , 0 ,0 , "simulations/run0");
  enkf_node_type * field_node = enkf_state_get_node( state , "PORO" );
  
  bool forward_init;
  test_assert_true( util_sscanf_bool( forward_init_string , &forward_init));
  test_assert_bool_equal( enkf_node_use_forward_init( field_node ) , forward_init );
  test_assert_bool_equal( forward_init, ensemble_config_have_forward_init( enkf_main_get_ensemble_config( enkf_main )));
  
  util_clear_directory( "Storage" , true , true );
  
  create_runpath( enkf_main );
  test_assert_true( util_is_directory( "simulations/run0" ));

  if (forward_init)
    util_copy_file( init_file , "simulations/run0/petro.grdecl");

  {
    bool_vector_type * iactive = bool_vector_alloc( enkf_main_get_ensemble_size(enkf_main) , true);
    int error = 0;
    stringlist_type * msg_list = stringlist_alloc_new();  
    enkf_state_load_from_forward_model( state , run_arg ,  &error , false , msg_list );
    stringlist_free( msg_list );
    bool_vector_free( iactive );
    test_assert_int_equal(error, 0); 
  }

  test_assert_true(check_original_exported_data_equal(field_node));

  run_arg_free( run_arg );
  enkf_main_free(enkf_main);    
  test_work_area_free(work_area); 
}
Esempio n. 28
0
void test_with_prefix() {
  test_work_area_type * work_area = test_work_area_alloc( "with-prefix" );

  util_make_path( "PREFIX" );
  {
    test_work_area_type * sub_area = test_work_area_alloc_relative("PREFIX" , "sub-work" );
    test_assert_true( test_work_area_is_instance( sub_area ));
    test_work_area_free( sub_area );
    test_assert_true( util_entry_exists("PREFIX/sub-work"));
  }
  {
    test_work_area_type * sub_area = test_work_area_alloc_relative("DoesNotExist" , "sub-work" );
    test_assert_NULL( sub_area );
  }
  test_work_area_free( work_area );
}
Esempio n. 29
0
void test_case_initialized() {
  test_work_area_type * work_area = test_work_area_alloc("enkf_main_case_initialized" );
  {
    enkf_main_type * enkf_main = enkf_main_alloc_empty();
    model_config_type * model_config = enkf_main_get_model_config(enkf_main);
    const char * new_case = "fs/case";
    char * mount_point = util_alloc_sprintf("%s/%s" , model_config_get_enspath(model_config) , new_case);
    enkf_fs_create_fs(mount_point , BLOCK_FS_DRIVER_ID , NULL);

    test_assert_false(enkf_main_case_is_initialized(enkf_main , "does/not/exist" , NULL));
    test_assert_true(enkf_main_case_is_initialized(enkf_main , new_case , NULL));

    enkf_main_free(enkf_main);
  }
  test_work_area_free(work_area);
}
Esempio n. 30
0
int main(int argc , char ** argv) {  
  int i;
  ecl_kw_type * ecl_kw = ecl_kw_alloc("HEAD" , 10  , ECL_INT_TYPE);

  for (i=0; i < 10; i++) 
    ecl_kw_iset_int(ecl_kw , i , i );

  {
    test_work_area_type * work_area = test_work_area_alloc("ecl_kw_grdecl" , true);
    FILE * stream = util_fopen( "FILE.grdecl" , "w");

    ecl_kw_fprintf_grdecl(ecl_kw , stream );
    fclose(stream);
    
    stream = util_fopen( "FILE.grdecl" , "r");
    {
      ecl_kw_type * ecl_kw2 = ecl_kw_fscanf_alloc_grdecl( stream , "HEAD" , 10 , ECL_INT_TYPE);
      
      test_assert_not_NULL( ecl_kw2 );
      test_assert_true( ecl_kw_equal( ecl_kw , ecl_kw2));
      ecl_kw_free( ecl_kw2 );
    }
    fclose( stream );

    stream = util_fopen( "FILE.grdecl" , "w");
    ecl_kw_fprintf_grdecl__(ecl_kw , "HEAD1234" , stream );
    fclose( stream );

    stream = util_fopen( "FILE.grdecl" , "r");
    {
      ecl_kw_type * ecl_kw2 = ecl_kw_fscanf_alloc_grdecl( stream , "HEAD" , 10 , ECL_INT_TYPE);
      
      test_assert_NULL( ecl_kw2 );
      ecl_kw2 = ecl_kw_fscanf_alloc_grdecl( stream , "HEAD1234" , 10 , ECL_INT_TYPE);
      test_assert_not_NULL( ecl_kw2 );
      
      test_assert_string_equal( ecl_kw_get_header( ecl_kw2 ) , "HEAD1234" );
      test_assert_true( ecl_kw_content_equal( ecl_kw , ecl_kw2 ));
      ecl_kw_free( ecl_kw2 );
    }
    fclose( stream );
    test_work_area_free( work_area );
  }
  ecl_kw_free( ecl_kw );
  
  exit(0);
}