|
|
|
@ -20,103 +20,159 @@
@@ -20,103 +20,159 @@
|
|
|
|
|
static void |
|
|
|
|
test_remove_unused (void) |
|
|
|
|
{ |
|
|
|
|
test_helper_zrythm_init (); |
|
|
|
|
|
|
|
|
|
/* create many audio tracks with region to push
|
|
|
|
|
* the first few off the undo stack */ |
|
|
|
|
char * filepath = g_build_filename ( |
|
|
|
|
TESTS_SRCDIR, "test_start_with_signal.mp3", |
|
|
|
|
NULL); |
|
|
|
|
SupportedFile * file = |
|
|
|
|
supported_file_new_from_path (filepath); |
|
|
|
|
int num_tracks_before = TRACKLIST->num_tracks; |
|
|
|
|
track_create_with_action ( |
|
|
|
|
TRACK_TYPE_AUDIO, NULL, file, PLAYHEAD, |
|
|
|
|
num_tracks_before, 1, NULL); |
|
|
|
|
|
|
|
|
|
/* delete the first track so that the clip for it
|
|
|
|
|
* will no longer exist (pushed off undo stack) */ |
|
|
|
|
track_select ( |
|
|
|
|
TRACKLIST->tracks[num_tracks_before], F_SELECT, |
|
|
|
|
F_NOT_EXCLUSIVE, F_NO_PUBLISH_EVENTS); |
|
|
|
|
tracklist_selections_action_perform_delete ( |
|
|
|
|
TRACKLIST_SELECTIONS, PORT_CONNECTIONS_MGR, |
|
|
|
|
NULL); |
|
|
|
|
|
|
|
|
|
/* create more tracks */ |
|
|
|
|
for (int i = 0; i < (ZRYTHM->undo_stack_len + 4); |
|
|
|
|
i++) |
|
|
|
|
/* on first iteration, run the whole logic
|
|
|
|
|
* on second iteration, just check that no files |
|
|
|
|
* in the main project are removed when saving |
|
|
|
|
* a backup */ |
|
|
|
|
for (int i = 0; i < 2; i++) |
|
|
|
|
{ |
|
|
|
|
test_helper_zrythm_init (); |
|
|
|
|
|
|
|
|
|
/* create many audio tracks with region to push
|
|
|
|
|
* the first few off the undo stack */ |
|
|
|
|
char * filepath = g_build_filename ( |
|
|
|
|
TESTS_SRCDIR, "test_start_with_signal.mp3", |
|
|
|
|
NULL); |
|
|
|
|
SupportedFile * file = |
|
|
|
|
supported_file_new_from_path (filepath); |
|
|
|
|
int num_tracks_before = TRACKLIST->num_tracks; |
|
|
|
|
track_create_with_action ( |
|
|
|
|
TRACK_TYPE_AUDIO, NULL, file, PLAYHEAD, |
|
|
|
|
TRACKLIST->num_tracks, 1, NULL); |
|
|
|
|
num_tracks_before, 1, NULL); |
|
|
|
|
|
|
|
|
|
/* save and reload the project */ |
|
|
|
|
test_project_save_and_reload (); |
|
|
|
|
|
|
|
|
|
/* delete the first track so that the clip for it
|
|
|
|
|
* will no longer exist (pushed off undo stack) */ |
|
|
|
|
track_select ( |
|
|
|
|
TRACKLIST->tracks[num_tracks_before], |
|
|
|
|
F_SELECT, F_NOT_EXCLUSIVE, |
|
|
|
|
F_NO_PUBLISH_EVENTS); |
|
|
|
|
tracklist_selections_action_perform_delete ( |
|
|
|
|
TRACKLIST_SELECTIONS, PORT_CONNECTIONS_MGR, |
|
|
|
|
NULL); |
|
|
|
|
|
|
|
|
|
/* if second iteration, clear undo stacks
|
|
|
|
|
* (happens e.g. when removing an |
|
|
|
|
* uninstantiated plugin), then attempt to |
|
|
|
|
* save a backup and then attempt to load the |
|
|
|
|
* main project again */ |
|
|
|
|
if (i == 1) |
|
|
|
|
{ |
|
|
|
|
char * dir = g_strdup (PROJECT->dir); |
|
|
|
|
int ret = project_save ( |
|
|
|
|
PROJECT, PROJECT->dir, F_NOT_BACKUP, 0, |
|
|
|
|
F_NO_ASYNC); |
|
|
|
|
g_assert_cmpint (ret, ==, 0); |
|
|
|
|
|
|
|
|
|
undo_manager_clear_stacks ( |
|
|
|
|
UNDO_MANAGER, F_FREE); |
|
|
|
|
|
|
|
|
|
ret = project_save ( |
|
|
|
|
PROJECT, PROJECT->dir, F_BACKUP, 0, |
|
|
|
|
F_NO_ASYNC); |
|
|
|
|
g_assert_cmpint (ret, ==, 0); |
|
|
|
|
g_assert_nonnull (PROJECT->backup_dir); |
|
|
|
|
|
|
|
|
|
/* free the project */ |
|
|
|
|
object_free_w_func_and_null ( |
|
|
|
|
project_free, PROJECT); |
|
|
|
|
|
|
|
|
|
/* load the original project */ |
|
|
|
|
char * prj_filepath = g_build_filename ( |
|
|
|
|
dir, PROJECT_FILE, NULL); |
|
|
|
|
g_free (dir); |
|
|
|
|
ret = project_load (prj_filepath, false); |
|
|
|
|
g_free (prj_filepath); |
|
|
|
|
g_assert_cmpint (ret, ==, 0); |
|
|
|
|
|
|
|
|
|
test_helper_zrythm_cleanup (); |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* create more tracks */ |
|
|
|
|
for (int j = 0; |
|
|
|
|
j < (ZRYTHM->undo_stack_len + 4); j++) |
|
|
|
|
{ |
|
|
|
|
track_create_with_action ( |
|
|
|
|
TRACK_TYPE_AUDIO, NULL, file, PLAYHEAD, |
|
|
|
|
TRACKLIST->num_tracks, 1, NULL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* assert all clips still exist */ |
|
|
|
|
g_assert_cmpint ( |
|
|
|
|
AUDIO_POOL->num_clips, ==, |
|
|
|
|
ZRYTHM->undo_stack_len + 5); |
|
|
|
|
AudioClip * clip = AUDIO_POOL->clips[0]; |
|
|
|
|
char * clip_path = |
|
|
|
|
audio_clip_get_path_in_pool ( |
|
|
|
|
clip, F_NOT_BACKUP); |
|
|
|
|
g_assert_true (g_file_test ( |
|
|
|
|
clip_path, G_FILE_TEST_EXISTS)); |
|
|
|
|
AudioClip * clip2 = AUDIO_POOL->clips[1]; |
|
|
|
|
char * clip_path2 = |
|
|
|
|
audio_clip_get_path_in_pool ( |
|
|
|
|
clip2, F_NOT_BACKUP); |
|
|
|
|
g_assert_true (g_file_test ( |
|
|
|
|
clip_path2, G_FILE_TEST_EXISTS)); |
|
|
|
|
AudioClip * last_clip = |
|
|
|
|
AUDIO_POOL |
|
|
|
|
->clips[ZRYTHM->undo_stack_len + 4]; |
|
|
|
|
char * last_clip_path = |
|
|
|
|
audio_clip_get_path_in_pool ( |
|
|
|
|
last_clip, F_NOT_BACKUP); |
|
|
|
|
g_assert_true (g_file_test ( |
|
|
|
|
last_clip_path, G_FILE_TEST_EXISTS)); |
|
|
|
|
|
|
|
|
|
char * undo_manager_yaml = yaml_serialize ( |
|
|
|
|
UNDO_MANAGER, &undo_manager_schema); |
|
|
|
|
g_message ("\n%s", undo_manager_yaml); |
|
|
|
|
|
|
|
|
|
/* undo and check that last file still exists */ |
|
|
|
|
undo_manager_undo (UNDO_MANAGER, NULL); |
|
|
|
|
g_assert_true (g_file_test ( |
|
|
|
|
last_clip_path, G_FILE_TEST_EXISTS)); |
|
|
|
|
g_assert_cmpint ( |
|
|
|
|
AUDIO_POOL->num_clips, ==, |
|
|
|
|
ZRYTHM->undo_stack_len + 5); |
|
|
|
|
g_assert_nonnull ( |
|
|
|
|
AUDIO_POOL |
|
|
|
|
->clips[ZRYTHM->undo_stack_len + 4]); |
|
|
|
|
|
|
|
|
|
/* do another action so that the undoable action
|
|
|
|
|
* for last file no longer exists */ |
|
|
|
|
track_create_with_action ( |
|
|
|
|
TRACK_TYPE_MIDI, NULL, NULL, PLAYHEAD, |
|
|
|
|
num_tracks_before, 1, NULL); |
|
|
|
|
|
|
|
|
|
/* save the project to remove unused files from
|
|
|
|
|
* pool */ |
|
|
|
|
test_project_save_and_reload (); |
|
|
|
|
|
|
|
|
|
/* assert first and previous last clip are
|
|
|
|
|
* removed */ |
|
|
|
|
g_assert_cmpint ( |
|
|
|
|
AUDIO_POOL->num_clips, ==, |
|
|
|
|
ZRYTHM->undo_stack_len + 5); |
|
|
|
|
g_assert_null (AUDIO_POOL->clips[0]); |
|
|
|
|
g_assert_false (g_file_test ( |
|
|
|
|
clip_path, G_FILE_TEST_EXISTS)); |
|
|
|
|
g_assert_nonnull (AUDIO_POOL->clips[1]); |
|
|
|
|
g_assert_null ( |
|
|
|
|
AUDIO_POOL |
|
|
|
|
->clips[ZRYTHM->undo_stack_len + 4]); |
|
|
|
|
g_assert_nonnull ( |
|
|
|
|
AUDIO_POOL |
|
|
|
|
->clips[ZRYTHM->undo_stack_len + 5]); |
|
|
|
|
g_assert_true (g_file_test ( |
|
|
|
|
clip_path2, G_FILE_TEST_EXISTS)); |
|
|
|
|
g_assert_false (g_file_test ( |
|
|
|
|
last_clip_path, G_FILE_TEST_EXISTS)); |
|
|
|
|
|
|
|
|
|
test_helper_zrythm_cleanup (); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* assert all clips still exist */ |
|
|
|
|
g_assert_cmpint ( |
|
|
|
|
AUDIO_POOL->num_clips, ==, |
|
|
|
|
ZRYTHM->undo_stack_len + 5); |
|
|
|
|
AudioClip * clip = AUDIO_POOL->clips[0]; |
|
|
|
|
char * clip_path = audio_clip_get_path_in_pool ( |
|
|
|
|
clip, F_NOT_BACKUP); |
|
|
|
|
g_assert_true ( |
|
|
|
|
g_file_test (clip_path, G_FILE_TEST_EXISTS)); |
|
|
|
|
AudioClip * clip2 = AUDIO_POOL->clips[1]; |
|
|
|
|
char * clip_path2 = audio_clip_get_path_in_pool ( |
|
|
|
|
clip2, F_NOT_BACKUP); |
|
|
|
|
g_assert_true ( |
|
|
|
|
g_file_test (clip_path2, G_FILE_TEST_EXISTS)); |
|
|
|
|
AudioClip * last_clip = |
|
|
|
|
AUDIO_POOL->clips[ZRYTHM->undo_stack_len + 4]; |
|
|
|
|
char * last_clip_path = |
|
|
|
|
audio_clip_get_path_in_pool ( |
|
|
|
|
last_clip, F_NOT_BACKUP); |
|
|
|
|
g_assert_true (g_file_test ( |
|
|
|
|
last_clip_path, G_FILE_TEST_EXISTS)); |
|
|
|
|
|
|
|
|
|
char * undo_manager_yaml = yaml_serialize ( |
|
|
|
|
UNDO_MANAGER, &undo_manager_schema); |
|
|
|
|
g_message ("\n%s", undo_manager_yaml); |
|
|
|
|
|
|
|
|
|
/* undo and check that last file still exists */ |
|
|
|
|
undo_manager_undo (UNDO_MANAGER, NULL); |
|
|
|
|
g_assert_true (g_file_test ( |
|
|
|
|
last_clip_path, G_FILE_TEST_EXISTS)); |
|
|
|
|
g_assert_cmpint ( |
|
|
|
|
AUDIO_POOL->num_clips, ==, |
|
|
|
|
ZRYTHM->undo_stack_len + 5); |
|
|
|
|
g_assert_nonnull ( |
|
|
|
|
AUDIO_POOL->clips[ZRYTHM->undo_stack_len + 4]); |
|
|
|
|
|
|
|
|
|
/* do another action so that the undoable action
|
|
|
|
|
* for last file no longer exists */ |
|
|
|
|
track_create_with_action ( |
|
|
|
|
TRACK_TYPE_MIDI, NULL, NULL, PLAYHEAD, |
|
|
|
|
num_tracks_before, 1, NULL); |
|
|
|
|
|
|
|
|
|
/* save the project to remove unused files from
|
|
|
|
|
* pool */ |
|
|
|
|
test_project_save_and_reload (); |
|
|
|
|
|
|
|
|
|
/* assert first and previous last clip are
|
|
|
|
|
* removed */ |
|
|
|
|
g_assert_cmpint ( |
|
|
|
|
AUDIO_POOL->num_clips, ==, |
|
|
|
|
ZRYTHM->undo_stack_len + 5); |
|
|
|
|
g_assert_null (AUDIO_POOL->clips[0]); |
|
|
|
|
g_assert_false ( |
|
|
|
|
g_file_test (clip_path, G_FILE_TEST_EXISTS)); |
|
|
|
|
g_assert_nonnull (AUDIO_POOL->clips[1]); |
|
|
|
|
g_assert_null ( |
|
|
|
|
AUDIO_POOL->clips[ZRYTHM->undo_stack_len + 4]); |
|
|
|
|
g_assert_nonnull ( |
|
|
|
|
AUDIO_POOL->clips[ZRYTHM->undo_stack_len + 5]); |
|
|
|
|
g_assert_true ( |
|
|
|
|
g_file_test (clip_path2, G_FILE_TEST_EXISTS)); |
|
|
|
|
g_assert_false (g_file_test ( |
|
|
|
|
last_clip_path, G_FILE_TEST_EXISTS)); |
|
|
|
|
|
|
|
|
|
test_helper_zrythm_cleanup (); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int |
|
|
|
|