1 /* GSequencer - Advanced GTK Sequencer
2 * Copyright (C) 2020 Joël Krähemann
3 *
4 * This file is part of GSequencer.
5 *
6 * GSequencer is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU 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 * GSequencer 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 General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GSequencer. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <glib.h>
21 #include <glib-object.h>
22
23 #include <CUnit/CUnit.h>
24 #include <CUnit/Basic.h>
25
26 #include <ags/libags.h>
27 #include <ags/libags-audio.h>
28
29 #include <ags/config.h>
30
31 #include <ags/gsequencer_main.h>
32
33 #include <ags/X/ags_ui_provider.h>
34 #include <ags/X/ags_xorg_application_context.h>
35 #include <ags/X/ags_window.h>
36
37 #include "gsequencer_setup_util.h"
38 #include "ags_functional_test_util.h"
39
40 void ags_functional_loop_004_xml_test_add_test();
41
42 int ags_functional_loop_004_xml_test_init_suite();
43 int ags_functional_loop_004_xml_test_clean_suite();
44
45 void ags_functional_loop_004_xml_test_file_setup();
46
47 #define AGS_FUNCTIONAL_LOOP_004_XML_TEST_FILE_SETUP_PLAYBACK_COUNT (1)
48 #define AGS_FUNCTIONAL_LOOP_004_XML_TEST_FILE_SETUP_PLAYBACK_DURATION (120)
49
50 #define AGS_FUNCTIONAL_LOOP_004_XML_TEST_FILE_SETUP_FILENAME SRCDIR "/" "ags/test/X/examples/ags-loop-000.xml"
51
52 #define AGS_FUNCTIONAL_LOOP_004_XML_TEST_CONFIG "[generic]\n" \
53 "autosave-thread=false\n" \
54 "simple-file=true\n" \
55 "disable-feature=experimental\n" \
56 "segmentation=4/4\n" \
57 "\n" \
58 "[thread]\n" \
59 "model=super-threaded\n" \
60 "super-threaded-scope=channel\n" \
61 "lock-global=ags-thread\n" \
62 "lock-parent=ags-recycling-thread\n" \
63 "\n" \
64 "[soundcard-0]\n" \
65 "backend=alsa\n" \
66 "device=default\n" \
67 "samplerate=44100\n" \
68 "buffer-size=1024\n" \
69 "pcm-channels=2\n" \
70 "dsp-channels=2\n" \
71 "format=16\n" \
72 "\n" \
73 "[recall]\n" \
74 "auto-sense=true\n" \
75 "\n"
76
77 CU_pSuite pSuite = NULL;
78 volatile gboolean is_available;
79
80 AgsApplicationContext *application_context;
81
82 void
ags_functional_loop_004_xml_test_add_test()83 ags_functional_loop_004_xml_test_add_test()
84 {
85 /* add the tests to the suite */
86 if((CU_add_test(pSuite, "functional test of GSequencer setup by file and play it", ags_functional_loop_004_xml_test_file_setup) == NULL)){
87 CU_cleanup_registry();
88
89 exit(CU_get_error());
90 }
91
92 /* Run all tests using the CUnit Basic interface */
93 CU_basic_set_mode(CU_BRM_VERBOSE);
94 CU_basic_run_tests();
95
96 ags_test_quit();
97
98 CU_cleanup_registry();
99
100 exit(CU_get_error());
101 }
102
103 /* The suite initialization function.
104 * Opens the temporary file used by the tests.
105 * Returns zero on success, non-zero otherwise.
106 */
107 int
ags_functional_loop_004_xml_test_init_suite()108 ags_functional_loop_004_xml_test_init_suite()
109 {
110 application_context = ags_application_context_get_instance();
111
112 return(0);
113 }
114
115 /* The suite cleanup function.
116 * Closes the temporary file used by the tests.
117 * Returns zero on success, non-zero otherwise.
118 */
119 int
ags_functional_loop_004_xml_test_clean_suite()120 ags_functional_loop_004_xml_test_clean_suite()
121 {
122 return(0);
123 }
124
125 void
ags_functional_loop_004_xml_test_file_setup()126 ags_functional_loop_004_xml_test_file_setup()
127 {
128 AgsXorgApplicationContext *xorg_application_context;
129 GtkButton *play_button;
130 GtkButton *stop_button;
131
132 struct timespec start_time, current_time;
133
134 guint i;
135 gboolean expired;
136 gboolean success;
137
138 while(!ags_ui_provider_get_gui_ready(AGS_UI_PROVIDER(application_context))){
139 usleep(500000);
140 }
141
142 usleep(500000);
143
144 ags_functional_test_util_file_default_window_resize();
145
146 ags_test_enter();
147
148 xorg_application_context = ags_application_context_get_instance();
149
150 ags_test_leave();
151
152 /* get buttons */
153 ags_test_enter();
154
155 play_button = AGS_WINDOW(xorg_application_context->window)->navigation->play;
156 stop_button = AGS_WINDOW(xorg_application_context->window)->navigation->stop;
157
158 ags_test_leave();
159
160 /* get initial time */
161 success = TRUE;
162
163 for(i = 0; success && i < AGS_FUNCTIONAL_LOOP_004_XML_TEST_FILE_SETUP_PLAYBACK_COUNT; i++){
164 clock_gettime(CLOCK_MONOTONIC, &start_time);
165
166 expired = FALSE;
167
168 g_message("start playback");
169 ags_functional_test_util_button_click(play_button);
170
171 while(!expired){
172 /* check expired */
173 clock_gettime(CLOCK_MONOTONIC, ¤t_time);
174
175 if(start_time.tv_sec + AGS_FUNCTIONAL_LOOP_004_XML_TEST_FILE_SETUP_PLAYBACK_DURATION < current_time.tv_sec){
176 expired = TRUE;
177 }
178 }
179
180 g_message("stop playback");
181 ags_functional_test_util_button_click(stop_button);
182
183 /* wait some time before next playback */
184 usleep(5000000);
185
186 if(!expired){
187 success = FALSE;
188 }
189 }
190
191 CU_ASSERT(success == TRUE);
192 }
193
194 int
main(int argc,char ** argv)195 main(int argc, char **argv)
196 {
197 char **new_argv;
198
199 /* initialize the CUnit test registry */
200 if(CUE_SUCCESS != CU_initialize_registry()){
201 return CU_get_error();
202 }
203
204 /* add a suite to the registry */
205 pSuite = CU_add_suite("AgsFuncitonalAudioConfigTest", ags_functional_loop_004_xml_test_init_suite, ags_functional_loop_004_xml_test_clean_suite);
206
207 if(pSuite == NULL){
208 CU_cleanup_registry();
209
210 return CU_get_error();
211 }
212
213 g_atomic_int_set(&is_available,
214 FALSE);
215
216 new_argv = (char **) malloc((argc + 3) * sizeof(char *));
217 memcpy(new_argv, argv, argc * sizeof(char **));
218 new_argv[argc] = "--filename";
219 new_argv[argc + 1] = AGS_FUNCTIONAL_LOOP_004_XML_TEST_FILE_SETUP_FILENAME;
220 new_argv[argc + 2] = NULL;
221 argc += 2;
222
223 ags_test_init(&argc, &new_argv,
224 AGS_FUNCTIONAL_LOOP_004_XML_TEST_CONFIG);
225
226 ags_functional_test_util_do_run(argc, new_argv,
227 ags_functional_loop_004_xml_test_add_test, &is_available);
228
229 g_thread_join(ags_functional_test_util_test_runner_thread());
230
231 return(-1);
232 }
233