diff options
author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2014-09-24 10:02:15 (GMT) |
---|---|---|
committer | Magnus Lundborg <lundborg.magnus@gmail.com> | 2014-09-24 10:02:15 (GMT) |
commit | 90de14812a5898cfe2241429f6a1313957b75417 (patch) | |
tree | 2d5ccbe59f7ec76b75ba9014e5ad96c89970e825 /src | |
parent | ba787e5b528ecdf8ba1d073144fd995a7ea3606d (diff) |
Added new test (copy trajectory container and molsys)
Also fixed bugs in tng_trajectory_init_from_src.
Change-Id: Iaa44e79f388b7add79973165801ab3dba57b3dcf
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/tng_io.c | 43 | ||||
-rw-r--r-- | src/tests/tng_io_testing.c | 48 |
2 files changed, 76 insertions, 15 deletions
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 947df1d..ff8dd40 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -9219,24 +9219,38 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init_from_src(tng_trajector frame_set = &dest->current_trajectory_frame_set; - dest->input_file_path = malloc(strlen(src->input_file_path) + 1); - if(!dest->input_file_path) + if(src->input_file_path) { - fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", - (unsigned int)strlen(src->input_file_path) + 1, __FILE__, __LINE__); - return(TNG_CRITICAL); + dest->input_file_path = malloc(strlen(src->input_file_path) + 1); + if(!dest->input_file_path) + { + fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", + (unsigned int)strlen(src->input_file_path) + 1, __FILE__, __LINE__); + return(TNG_CRITICAL); + } + strcpy(dest->input_file_path, src->input_file_path); + dest->input_file_len = src->input_file_len; + } + else + { + dest->input_file_path = 0; } - strcpy(dest->input_file_path, src->input_file_path); dest->input_file = 0; - dest->input_file_len = src->input_file_len; - dest->output_file_path = malloc(strlen(src->output_file_path) + 1); - if(!dest->output_file_path) + if(src->output_file_path) { - fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", - (unsigned int)strlen(src->output_file_path) + 1, __FILE__, __LINE__); - return(TNG_CRITICAL); + dest->output_file_path = malloc(strlen(src->output_file_path) + 1); + if(!dest->output_file_path) + { + fprintf(stderr, "TNG library: Cannot allocate memory (%d bytes). %s: %d\n", + (unsigned int)strlen(src->output_file_path) + 1, __FILE__, __LINE__); + return(TNG_CRITICAL); + } + strcpy(dest->output_file_path, src->output_file_path); + } + else + { + dest->output_file_path = 0; } - strcpy(dest->output_file_path, src->output_file_path); dest->output_file = 0; dest->first_program_name = 0; @@ -9291,6 +9305,9 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init_from_src(tng_trajector frame_set->tr_particle_data = 0; frame_set->tr_data = 0; + frame_set->n_written_frames = 0; + frame_set->n_unwritten_frames = 0; + frame_set->next_frame_set_file_pos = -1; frame_set->prev_frame_set_file_pos = -1; frame_set->medium_stride_next_frame_set_file_pos = -1; diff --git a/src/tests/tng_io_testing.c b/src/tests/tng_io_testing.c index 5d5acaa..7f778c0 100644 --- a/src/tests/tng_io_testing.c +++ b/src/tests/tng_io_testing.c @@ -1205,7 +1205,7 @@ tng_function_status tng_test_append(tng_trajectory_t traj, const char hash_mode) velocities[i] = i; } - tng_util_vel_with_time_double_write(traj, n_frames, time, velocities); + stat = tng_util_vel_with_time_double_write(traj, n_frames, time, velocities); free(velocities); @@ -1214,6 +1214,41 @@ tng_function_status tng_test_append(tng_trajectory_t traj, const char hash_mode) return(stat); } +tng_function_status tng_test_copy_container(tng_trajectory_t traj, const char hash_mode) +{ + tng_trajectory_t dest; + tng_function_status stat; + + stat = tng_util_trajectory_open(TNG_EXAMPLE_FILES_DIR "tng_test.tng", 'r', &traj); + if(stat != TNG_SUCCESS) + { + printf("Cannot open trajectory. %s: %d\n", + __FILE__, __LINE__); + return(stat); + } + + stat = tng_trajectory_init_from_src(traj, &dest); + if(stat != TNG_SUCCESS) + { + return(stat); + } + + stat = tng_molecule_system_copy(traj, dest); + if(stat != TNG_SUCCESS) + { + return(stat); + } + + stat = tng_util_trajectory_close(&traj); + if(stat != TNG_SUCCESS) + { + return(stat); + } + stat = tng_util_trajectory_close(&dest); + + return(stat); +} + int main() { tng_trajectory_t traj; @@ -1329,7 +1364,16 @@ int main() if(tng_test_append(traj, hash_mode) != TNG_SUCCESS) { printf("Failed. %s: %d.\n", __FILE__, __LINE__); - exit(1); + } + else + { + printf("Succeeded.\n"); + } + + printf("Test Copy trajectory container:\t\t\t"); + if(tng_test_copy_container(traj, hash_mode) != TNG_SUCCESS) + { + printf("Failed. %s: %d.\n", __FILE__, __LINE__); } else { |