1 /*
2  * Copyright (C) 2019 Alexandros Theodotou <alex at zrythm dot org>
3  *
4  * This file is part of Zrythm
5  *
6  * Zrythm is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Zrythm is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with Zrythm.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "zrythm-test-config.h"
21 
22 #include "audio/track.h"
23 #include "project.h"
24 #include "utils/flags.h"
25 #include "zrythm.h"
26 
27 #include "tests/helpers/project.h"
28 
29 #include <glib.h>
30 #include <locale.h>
31 
32 static void
33 test_new_track ()
34 {
35   Track * track =
36     track_new (
37       TRACK_TYPE_INSTRUMENT,
38       TRACKLIST->num_tracks,
39       "Test Instrument Track 1",
40       F_WITH_LANE);
41   g_assert_true (IS_TRACK_AND_NONNULL (track));
42 
43   g_assert_nonnull (track->name);
44 
45   object_free_w_func_and_null (
46     track_free, track);
47 }
48 
49 static void
50 test_get_direct_folder_parent ()
51 {
52   test_helper_zrythm_init ();
53 
54   Track * audio_group =
55     track_create_empty_with_action (
56       TRACK_TYPE_AUDIO_GROUP, NULL);
57   g_assert_nonnull (audio_group);
58 
59   Track * audio_group2 =
60     track_create_empty_with_action (
61       TRACK_TYPE_AUDIO_GROUP, NULL);
62   g_assert_nonnull (audio_group2);
63   track_select (
64     audio_group2, F_SELECT, F_NOT_EXCLUSIVE,
65     F_NO_PUBLISH_EVENTS);
66   tracklist_handle_move_or_copy (
67     TRACKLIST, audio_group,
68     TRACK_WIDGET_HIGHLIGHT_INSIDE, GDK_ACTION_MOVE);
69 
70   Track * audio_group3 =
71     track_create_empty_with_action (
72       TRACK_TYPE_AUDIO_GROUP, NULL);
73   g_assert_nonnull (audio_group3);
74   track_select (
75     audio_group3, F_SELECT, F_NOT_EXCLUSIVE,
76     F_NO_PUBLISH_EVENTS);
77   tracklist_handle_move_or_copy (
78     TRACKLIST, audio_group2,
79     TRACK_WIDGET_HIGHLIGHT_INSIDE, GDK_ACTION_MOVE);
80 
81   g_assert_cmpint (audio_group->pos, ==, 5);
82   g_assert_cmpint (audio_group->size, ==, 3);
83   g_assert_cmpint (audio_group2->pos, ==, 6);
84   g_assert_cmpint (audio_group2->size, ==, 2);
85   g_assert_cmpint (audio_group3->pos, ==, 7);
86   g_assert_cmpint (audio_group3->size, ==, 1);
87 
88   Track * direct_folder_parent =
89     track_get_direct_folder_parent (audio_group3);
90   g_assert_true (
91     direct_folder_parent == audio_group2);
92 
93   test_helper_zrythm_cleanup ();
94 }
95 
96 int
97 main (int argc, char *argv[])
98 {
99   g_test_init (&argc, &argv, NULL);
100 
101   test_helper_zrythm_init ();
102 
103 #define TEST_PREFIX "/audio/track/"
104 
105   g_test_add_func (
106     TEST_PREFIX "test new track",
107     (GTestFunc) test_new_track);
108   g_test_add_func (
109     TEST_PREFIX "test get_direct folder parent",
110     (GTestFunc) test_get_direct_folder_parent);
111 
112   return g_test_run ();
113 }
114