void test_kw_name() { ERT::EclKW< int > kw1( "short", 1 ); ERT::EclKW< int > kw2( "verylong", 1 ); test_assert_string_equal( kw1.name(), "short" ); test_assert_string_equal( kw2.name(), "verylong" ); }
void create_submit_script_script_according_to_input() { char ** args = util_calloc(2, sizeof * args); args[0] = "/tmp/jaja/"; args[1] = "number2arg"; char * script_filename = util_alloc_filename("/tmp/", "qsub_script", "sh"); torque_job_create_submit_script(script_filename, "job_program.py", 2, (const char **) args); printf("Create submit script OK\n"); 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); }
void test_filename() { runpath_list_type * list = runpath_list_alloc("DefaultFile"); test_assert_string_equal( "DefaultFile" , runpath_list_get_export_file(list)); runpath_list_set_export_file( list , "/tmp/file.txt"); test_assert_string_equal( "/tmp/file.txt" , runpath_list_get_export_file(list)); runpath_list_free( list ); }
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 ); }
void test_correct_time_vector() { ecl_sum_type * ecl_sum = test_alloc_ecl_sum(); time_t_vector_type * t = time_t_vector_alloc( 0 , 0 ); time_t_vector_append(t, util_make_date_utc( 2,1,2010 )); time_t_vector_append(t, util_make_date_utc( 4,1,2010 )); time_t_vector_append(t, util_make_date_utc( 6,1,2010 )); time_t_vector_append(t, util_make_date_utc( 8,1,2010 )); ecl_sum_type * ecl_sum_resampled = ecl_sum_alloc_resample(ecl_sum, "kk", t); test_assert_int_equal( ecl_sum_get_report_time(ecl_sum_resampled, 2) , util_make_date_utc( 6,1,2010 )); const ecl_smspec_type * smspec_resampled = ecl_sum_get_smspec(ecl_sum_resampled); const smspec_node_type * node1 = ecl_smspec_iget_node(smspec_resampled, 1); const smspec_node_type * node2 = ecl_smspec_iget_node(smspec_resampled, 2); const smspec_node_type * node3 = ecl_smspec_iget_node(smspec_resampled, 3); test_assert_string_equal( "BPR" , smspec_node_get_keyword(node2) ); test_assert_string_equal( "BARS" , smspec_node_get_unit(node2) ); test_assert_double_equal(3.33333, ecl_sum_get_from_sim_time( ecl_sum_resampled, util_make_date_utc( 6,1,2010 ), node1) ); test_assert_double_equal(3.33333, ecl_sum_get_from_sim_time( ecl_sum_resampled, util_make_date_utc( 2,1,2010 ), node2) ); test_assert_double_equal(10.0000, ecl_sum_get_from_sim_time( ecl_sum_resampled, util_make_date_utc( 4,1,2010 ), node3) ); ecl_sum_free(ecl_sum_resampled); time_t_vector_free(t); ecl_sum_free(ecl_sum); }
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 ); }
void test_front_back() { stringlist_type * s = stringlist_alloc_new(); stringlist_append_copy(s , "First"); test_assert_string_equal("First" , stringlist_front(s)); test_assert_string_equal("First" , stringlist_back(s)); stringlist_append_copy(s , "Last"); test_assert_string_equal("First" , stringlist_front(s)); test_assert_string_equal("Last" , stringlist_back(s)); stringlist_free( s ); }
void set_option_max_running_max_running_value_set() { queue_driver_type * driver_torque = queue_driver_alloc(TORQUE_DRIVER); test_assert_true(queue_driver_set_option(driver_torque, MAX_RUNNING, "42")); test_assert_string_equal("42", queue_driver_get_option(driver_torque, MAX_RUNNING)); queue_driver_free(driver_torque); queue_driver_type * driver_lsf = queue_driver_alloc(LSF_DRIVER); test_assert_true(queue_driver_set_option(driver_lsf, MAX_RUNNING, "72")); test_assert_string_equal("72", queue_driver_get_option(driver_lsf, MAX_RUNNING)); queue_driver_free(driver_lsf); }
void test_create() { char * cwd0 = util_alloc_cwd(); char * cwd1; { ERT::TestArea ta("test/area"); cwd1 = util_alloc_cwd(); test_assert_string_not_equal( cwd0 , cwd1 ); test_assert_string_equal( cwd1 , ta.getCwd().c_str()); test_assert_string_equal( cwd0 , ta.getOriginalCwd( ).c_str() ); } test_assert_false( util_is_directory(cwd1) ); free( cwd1 ); free( cwd0 ); }
void test_define(config_type * config , const char * config_file) { test_assert_true( config_parse( config , config_file , NULL , NULL , "DEFINE" , CONFIG_UNRECOGNIZED_IGNORE , true )); { const subst_list_type * define_list = config_get_define_list( config ); test_assert_true( subst_list_has_key( define_list , "VAR1")); test_assert_true( subst_list_has_key( define_list , "VAR2")); test_assert_true( subst_list_has_key( define_list , "VARX")); test_assert_false( subst_list_has_key( define_list , "VARY")); test_assert_string_equal( subst_list_get_value( define_list , "VAR1") , "100"); test_assert_string_equal( subst_list_get_value( define_list , "VAR2") , "10"); test_assert_string_equal( subst_list_get_value( define_list , "VARX") , "1"); } }
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 ); }
void test_dirname() { const char * src_file1 = "/some/very/long/path/file.txt"; const char * src_file2 = "relative/path/file.txt"; const char * src_file3 = "file.txt"; char * path1 = util_split_alloc_dirname( src_file1 ); char * path2 = util_split_alloc_dirname( src_file2 ); char * path3 = util_split_alloc_dirname( src_file3 ); test_assert_string_equal( "/some/very/long/path" , path1); test_assert_string_equal( "relative/path" , path2); test_assert_NULL( path3 ); free( path1 ); free( path2 ); }
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 ); }
void test_reverse() { const char *s0 = "AAA"; const char *s1 = "BBB"; const char *s2 = "CCC"; stringlist_type * s = stringlist_alloc_new(); stringlist_append_copy( s , s0 ); stringlist_append_copy( s , s1 ); stringlist_append_copy( s , s2 ); stringlist_reverse(s); test_assert_string_equal( s2 , stringlist_iget(s , 0 )); test_assert_string_equal( s1 , stringlist_iget(s , 1 )); test_assert_string_equal( s0 , stringlist_iget(s , 2 )); }
void test_filename() { const char * src_file1 = "/some/very/long/path/file1.txt"; const char * src_file2 = "relative/path/file2"; const char * src_file3 = "/tmp"; char * file1 = util_split_alloc_filename( src_file1 ); char * file2 = util_split_alloc_filename( src_file2 ); char * file3 = util_split_alloc_filename( src_file3 ); test_assert_string_equal( "file1.txt" , file1); test_assert_string_equal( "file2" , file2); test_assert_NULL( file3 ); free( file1 ); free( file2 ); }
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 ); }
void test_smspec_field() { std::string kw( "FOPT" ); ERT::smspec_node field( kw ); test_assert_string_equal( field.key1() , "FOPT" ); test_assert_true( field.keyword() == kw ); test_assert_true( field.type() == ECL_SMSPEC_FIELD_VAR ); }
int main(int argc , char ** argv) { test_assert_string_equal( NULL , util_alloc_sprintf_escape( NULL , 0)); test_assert_string_equal( "String", util_alloc_sprintf_escape( "String" , 0)); test_assert_string_equal( "String", util_alloc_sprintf_escape( "String" , 10)); test_assert_string_equal( "S%%tring%%", util_alloc_sprintf_escape( "S%tring%" , 0)); test_assert_string_equal( "S%%tring%%", util_alloc_sprintf_escape( "S%tring%" , 2)); test_assert_string_equal( "S%%tring%%", util_alloc_sprintf_escape( "S%tring%" , 10)); test_assert_string_equal( "S%%tring%" , util_alloc_sprintf_escape( "S%tring%" , 1)); test_assert_string_equal( "%%%%" , util_alloc_sprintf_escape( "%%" , 0)); test_assert_string_equal( "%%%%" , util_alloc_sprintf_escape( "%%%" , 1)); exit(0); }
void test_kw_vector_string() { std::vector< const char* > vec = { "short", "sweet", "padded ", "verylongkeyword" }; ERT::EclKW< const char* > kw( "XYZ", vec ); test_assert_size_t_equal( kw.size(), vec.size() ); test_assert_string_equal( kw.at( 0 ), "short " ); test_assert_string_equal( kw.at( 1 ), "sweet " ); test_assert_string_equal( kw.at( 2 ), vec.at( 2 ) ); test_assert_string_equal( kw.at( 3 ), "verylong" ); test_assert_string_not_equal( kw.at( 2 ), "verylongkeyword" ); }
void test_magic_strings( ert_test_context_type * test_context ) { enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); test_assert_true( ert_test_context_run_worklow( test_context , "MAGIC_PRINT") ); test_assert_true( util_file_exists( "magic-list.txt") ); { FILE * stream = util_fopen("magic-list.txt" , "r"); char string[128]; fscanf( stream , "%s" , string); test_assert_string_equal( string , enkf_fs_get_case_name( enkf_main_get_fs( enkf_main ))); fscanf( stream , "%s" , string); test_assert_string_equal( string , "MagicAllTheWayToWorkFlow"); fclose( stream ); } }
void test_util_addr2line() { const char * file = __FILE__; const char * func = __func__; int line; const int max_bt = 50; void *bt_addr[max_bt]; int size; char * func_name , * file_name; int line_nr; line = __LINE__ + 2; size = backtrace(bt_addr , max_bt); test_assert_int_equal( size , 4 ); test_assert_true( util_addr2line_lookup( bt_addr[0] , &func_name , &file_name , &line_nr)); test_assert_string_equal( func_name , func ); test_assert_int_equal( line , line_nr ); test_assert_string_equal( file_name , file ); }
void test_alloc_filename_empty_strings() { const char * path = ""; const char * filename = "file"; const char * extension = ""; char * alloc_filename = util_alloc_filename( path, filename , extension); test_assert_string_equal( alloc_filename , filename ); free( alloc_filename ); }
void test_smspec_wg() { std::string wkw( "WWCT" ); std::string gkw( "GWCT" ); std::string wg( "OP1" ); std::string gr( "WG1" ); ERT::smspec_node well( ECL_SMSPEC_WELL_VAR, wg, wkw ); ERT::smspec_node group( ECL_SMSPEC_GROUP_VAR, gr, gkw ); test_assert_string_equal(well.key1() , "WWCT:OP1"); test_assert_string_equal(well.keyword() , "WWCT"); test_assert_true(well.wgname() == wg); test_assert_true(well.type() == ECL_SMSPEC_WELL_VAR ); test_assert_string_equal(group.key1(), "GWCT:WG1"); test_assert_string_equal(group.keyword() , "GWCT"); test_assert_true(group.wgname() == gr); test_assert_true(group.type() == ECL_SMSPEC_GROUP_VAR ); }
int main( int argc , char ** argv) { const char * model_config = argv[1]; const char * site_config = NULL; ert_test_context_type * test_context = ert_test_context_alloc( "MAGIC-STRINGS" , model_config , site_config); enkf_main_type * enkf_main = ert_test_context_get_main( test_context ); { test_has_job( test_context ); enkf_main_select_fs(enkf_main , "default"); test_assert_string_equal( "default" , enkf_fs_get_case_name( enkf_main_get_fs( enkf_main ))); test_magic_strings( test_context ); enkf_main_select_fs(enkf_main , "extraCase"); test_assert_string_equal( "extraCase" , enkf_fs_get_case_name( enkf_main_get_fs( enkf_main ))); test_magic_strings( test_context ); } ert_test_context_free( test_context ); }
void test_wrapper() { local_obsdata_node_type * node = local_obsdata_node_alloc("KEY"); local_obsdata_type * data = local_obsdata_alloc_wrapper( node ); test_assert_true( local_obsdata_is_instance( data )); test_assert_int_equal( 1 , local_obsdata_get_size( data )); test_assert_ptr_equal( node , local_obsdata_iget( data , 0 )); test_assert_true( local_obsdata_has_node( data , "KEY" )); test_assert_false( local_obsdata_has_node( data , "KEYX" )); test_assert_string_equal( local_obsdata_node_get_key( node ) , local_obsdata_get_name( data )); local_obsdata_free( data ); }
int main(int argc , char ** argv) { hash_type * h = hash_alloc(); test_assert_bool_equal( hash_add_option( h , "Key" ) , false ); test_assert_false( hash_add_option( h , "Key" ) ); test_assert_true( hash_add_option( h , "Key1:Value" ) ); test_assert_true( hash_add_option( h , "Key2:Value1:Value2" ) ); test_assert_true( hash_add_option( h , "Key3:Value1:value2:Value3" ) ); test_assert_string_equal( (const char *) hash_get( h , "Key1" ) , "Value" ); test_assert_string_equal( (const char *) hash_get( h , "Key2" ) , "Value1:Value2" ); test_assert_string_equal( (const char *) hash_get( h , "Key3" ) , "Value1:value2:Value3" ); test_assert_false( hash_has_key( h , "Key" )); hash_free( h ); exit(0); }
void test_runpath() { model_config_type * model_config = model_config_alloc(); model_config_add_runpath(model_config , "KEY" , "RunPath%d"); model_config_add_runpath(model_config , "KEY2" , "2-RunPath%d"); test_assert_true( model_config_select_runpath(model_config , "KEY")); test_assert_false( model_config_select_runpath(model_config , "KEYX")); test_assert_string_equal("RunPath%d" , model_config_get_runpath_as_char(model_config)); model_config_set_runpath( model_config , "PATH%d"); test_assert_string_equal("PATH%d" , model_config_get_runpath_as_char(model_config)); test_assert_true( model_config_select_runpath(model_config , "KEY2")); test_assert_string_equal("2-RunPath%d" , model_config_get_runpath_as_char(model_config)); test_assert_true( model_config_select_runpath(model_config , "KEY")); test_assert_string_equal("PATH%d" , model_config_get_runpath_as_char(model_config)); test_assert_false( model_config_runpath_requires_iter( model_config )); model_config_set_runpath( model_config , "iens%d/iter%d" ); test_assert_true( model_config_runpath_requires_iter( model_config )); model_config_free( model_config ); }
void test_create_invalid(const char * config_file) { char * cwd0 = util_alloc_cwd(); ert_test_context_type * test_context = ert_test_context_alloc("CREATE_CONTEXT" , config_file , NULL ); test_assert_true( ert_test_context_is_instance( test_context )); test_assert_NULL( ert_test_context_get_main( test_context )); { char * cwd1 = util_alloc_cwd(); test_assert_string_equal(cwd1 , cwd0); free( cwd1 ); } free( cwd0 ); ert_test_context_free( test_context ); }
void test_init_case_job(ert_test_context_type * test_context, const char * job_name , const char * job_file) { stringlist_type * args = stringlist_alloc_new(); enkf_main_type * enkf_main = ert_test_context_get_main(test_context); test_assert_true( ert_test_context_install_workflow_job( test_context , "JOB" , job_file ) ); //Test init current case from existing { enkf_fs_type * cur_fs = enkf_main_mount_alt_fs( enkf_main , "new_current_case" , true ); enkf_main_select_fs(enkf_main, "new_current_case"); test_assert_ptr_not_equal(cur_fs , enkf_main_get_fs( enkf_main )); stringlist_append_copy( args, "default"); //case to init from test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) ); enkf_fs_decref(cur_fs); } { const char * current_case = enkf_main_get_current_fs( enkf_main ); test_assert_string_equal(current_case, "new_current_case"); test_assert_true(enkf_fs_has_node(enkf_main_get_fs(enkf_main), "PERMZ", PARAMETER, 0, 0, ANALYZED)); enkf_fs_type * default_fs = enkf_main_mount_alt_fs( enkf_main , "default" , true ); state_map_type * default_state_map = enkf_fs_get_state_map(default_fs); state_map_type * current_state_map = enkf_fs_get_state_map(enkf_main_get_fs(enkf_main)); test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(current_state_map)); enkf_fs_decref(default_fs); } //Test init case from existing case: stringlist_clear(args); stringlist_append_copy(args, "default"); //case to init from stringlist_append_copy(args, "new_not_current_case"); test_assert_true( ert_test_context_run_worklow_job( test_context , "JOB" , args) ); { enkf_fs_type * fs = enkf_main_mount_alt_fs(enkf_main, "new_not_current_case", true); test_assert_not_NULL( fs ); test_assert_true( enkf_fs_has_node(fs, "PERMZ", PARAMETER, 0, 0, ANALYZED )); enkf_fs_type * default_fs = enkf_main_mount_alt_fs( enkf_main , "default" , true ); state_map_type * default_state_map = enkf_fs_get_state_map(default_fs); state_map_type * new_state_map = enkf_fs_get_state_map(fs); test_assert_int_equal(state_map_get_size(default_state_map), state_map_get_size(new_state_map)); enkf_fs_decref(fs); } stringlist_free( args ); }
void test_join() { const char * elt0 = "AAA"; const char * elt1 = "BBB"; const char * elt2 = "CCC"; const char * elt3 = "DDD"; const char * elt4 = "EEE"; const char * elt5 = "FFF"; stringlist_type * s = stringlist_alloc_new(); { // empty join const char* empty_join = stringlist_alloc_joined_string(s, "!!!"); test_assert_not_NULL(empty_join); test_assert_string_equal("", empty_join); } stringlist_append_copy( s , elt0 ); stringlist_append_copy( s , elt1 ); stringlist_append_copy( s , elt2 ); const char * sep0 = ""; const char * sep1 = "!!!"; const char * sep2 = " abc "; const char * j0 = stringlist_alloc_joined_string( s, sep0); const char * j1 = stringlist_alloc_joined_string( s, sep1); const char * j2 = stringlist_alloc_joined_string( s, sep2); test_assert_string_equal( j0, "AAABBBCCC"); test_assert_string_equal( j1, "AAA!!!BBB!!!CCC"); test_assert_string_equal( j2, "AAA abc BBB abc CCC"); stringlist_type * s1 = stringlist_alloc_new(); stringlist_append_copy( s1 , elt0 ); test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep0)); test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep1)); test_assert_string_equal( "AAA", stringlist_alloc_joined_string( s1, sep2)); stringlist_type * sub = stringlist_alloc_new(); stringlist_append_copy( sub , elt0 ); stringlist_append_copy( sub , elt1 ); stringlist_append_copy( sub , elt2 ); stringlist_append_copy( sub , elt3 ); stringlist_append_copy( sub , elt4 ); stringlist_append_copy( sub , elt5 ); test_assert_string_equal( "CCC:DDD:EEE", stringlist_alloc_joined_substring( sub, 2, 5, ":")); }