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 ); }
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); } }
static void enkf_fs_fsync_state_map( enkf_fs_type * fs ) { char * filename = enkf_fs_alloc_case_filename( fs , STATE_MAP_FILE ); state_map_fwrite( fs->state_map , filename ); free( filename ); }