1 /* GSequencer - Advanced GTK Sequencer
2  * Copyright (C) 2005-2017 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 #ifdef AGS_WITH_LIBINSTPATCH
32 #include <libinstpatch/libinstpatch.h>
33 #endif
34 
35 #include <ags/gsequencer_main.h>
36 
37 #include <ags/test/X/libgsequencer.h>
38 
39 #include "../gsequencer_setup_util.h"
40 #include "../ags_functional_test_util.h"
41 
42 void ags_functional_drum_test_add_test();
43 
44 int ags_functional_drum_test_init_suite();
45 int ags_functional_drum_test_clean_suite();
46 
47 void ags_functional_drum_test_open_drum_kit();
48 void ags_functional_drum_test_resize_pads();
49 void ags_functional_drum_test_resize_audio_channels();
50 
51 #define AGS_FUNCTIONAL_DRUM_TEST_OPEN_DRUM_KIT_PATH "/usr/share/hydrogen/data/drumkits/HardElectro1/"
52 
53 #define AGS_FUNCTIONAL_DRUM_TEST_RESIZE_OUTPUT_PADS (5)
54 #define AGS_FUNCTIONAL_DRUM_TEST_RESIZE_INPUT_PADS (15)
55 
56 #define AGS_FUNCTIONAL_DRUM_TEST_RESIZE_AUDIO_CHANNELS (7)
57 
58 #define AGS_FUNCTIONAL_DRUM_TEST_CONFIG "[generic]\n" \
59   "autosave-thread=false\n"			       \
60   "simple-file=true\n"				       \
61   "disable-feature=experimental\n"		       \
62   "segmentation=4/4\n"				       \
63   "\n"						       \
64   "[thread]\n"					       \
65   "model=super-threaded\n"			       \
66   "super-threaded-scope=channel\n"		       \
67   "lock-global=ags-thread\n"			       \
68   "lock-parent=ags-recycling-thread\n"		       \
69   "\n"						       \
70   "[soundcard-0]\n"				       \
71   "backend=alsa\n"                                     \
72   "device=default\n"				       \
73   "samplerate=44100\n"				       \
74   "buffer-size=1024\n"				       \
75   "pcm-channels=2\n"				       \
76   "dsp-channels=2\n"				       \
77   "format=16\n"					       \
78   "\n"						       \
79   "[recall]\n"					       \
80   "auto-sense=true\n"				       \
81   "\n"
82 
83 CU_pSuite pSuite = NULL;
84 volatile gboolean is_available;
85 
86 extern AgsApplicationContext *ags_application_context;
87 
88 void
ags_functional_drum_test_add_test()89 ags_functional_drum_test_add_test()
90 {
91   /* add the tests to the suite */
92   if((CU_add_test(pSuite, "functional test of AgsDrum open drum kit", ags_functional_drum_test_open_drum_kit) == NULL) ||
93      (CU_add_test(pSuite, "functional test of AgsDrum resize pads", ags_functional_drum_test_resize_pads) == NULL) ||
94      (CU_add_test(pSuite, "functional test of AgsDrum resize audio channels", ags_functional_drum_test_resize_audio_channels) == NULL)){
95     CU_cleanup_registry();
96 
97     exit(CU_get_error());
98   }
99 
100   /* Run all tests using the CUnit Basic interface */
101   CU_basic_set_mode(CU_BRM_VERBOSE);
102   CU_basic_run_tests();
103 
104   ags_test_quit();
105 
106   CU_cleanup_registry();
107 
108   exit(CU_get_error());
109 }
110 
111 /* The suite initialization function.
112  * Opens the temporary file used by the tests.
113  * Returns zero on success, non-zero otherwise.
114  */
115 int
ags_functional_drum_test_init_suite()116 ags_functional_drum_test_init_suite()
117 {
118   return(0);
119 }
120 
121 /* The suite cleanup function.
122  * Closes the temporary file used by the tests.
123  * Returns zero on success, non-zero otherwise.
124  */
125 int
ags_functional_drum_test_clean_suite()126 ags_functional_drum_test_clean_suite()
127 {
128   return(0);
129 }
130 
131 void
ags_functional_drum_test_open_drum_kit()132 ags_functional_drum_test_open_drum_kit()
133 {
134   AgsXorgApplicationContext *xorg_application_context;
135 
136   AgsDrum *drum;
137 
138   GList *list_start, *list;
139 
140   guint nth_machine;
141   gboolean success;
142 
143   /* add drum */
144   success = ags_functional_test_util_add_machine(NULL,
145 						 "Drum");
146 
147   CU_ASSERT(success == TRUE);
148 
149   /*  */
150   ags_test_enter();
151 
152   xorg_application_context = ags_application_context_get_instance();
153 
154   /* retrieve drum */
155   nth_machine = 0;
156 
157   list_start = gtk_container_get_children(AGS_WINDOW(xorg_application_context->window)->machines);
158   list = g_list_nth(list_start,
159 		    nth_machine);
160 
161   ags_test_leave();
162 
163   if(list != NULL &&
164      AGS_IS_DRUM(list->data)){
165     drum = list->data;
166   }else{
167     drum = NULL;
168   }
169 
170   CU_ASSERT(drum != NULL);
171 
172   /* open dialog */
173   success = ags_functional_test_util_drum_open(0);
174 
175   CU_ASSERT(success == TRUE);
176 
177   /* open path */
178   CU_ASSERT(g_file_test(AGS_FUNCTIONAL_DRUM_TEST_OPEN_DRUM_KIT_PATH,
179 			G_FILE_TEST_EXISTS));
180 
181   success = ags_functional_test_util_file_chooser_open_path(GTK_FILE_CHOOSER(drum->open_dialog),
182 							    AGS_FUNCTIONAL_DRUM_TEST_OPEN_DRUM_KIT_PATH);
183   CU_ASSERT(success == TRUE);
184 
185   /* select all */
186   success = ags_functional_test_util_file_chooser_select_all(GTK_FILE_CHOOSER(drum->open_dialog));
187 
188   CU_ASSERT(success == TRUE);
189 
190   /* response ok */
191   success = ags_functional_test_util_dialog_ok(GTK_DIALOG(drum->open_dialog));
192 
193   CU_ASSERT(success == TRUE);
194 
195   /* destroy drum */
196   success = ags_functional_test_util_machine_destroy(0);
197 
198   CU_ASSERT(success == TRUE);
199 }
200 
201 void
ags_functional_drum_test_resize_pads()202 ags_functional_drum_test_resize_pads()
203 {
204   GtkDialog *properties;
205 
206   AgsXorgApplicationContext *xorg_application_context;
207 
208   AgsDrum *drum;
209 
210   GList *list_start, *list;
211 
212   guint nth_machine;
213   guint resize_tab;
214   gboolean success;
215 
216   /* add drum */
217   success = ags_functional_test_util_add_machine(NULL,
218 						 "Drum");
219 
220   CU_ASSERT(success == TRUE);
221 
222   /*  */
223   ags_test_enter();
224 
225   xorg_application_context = ags_application_context_get_instance();
226 
227   /* retrieve drum */
228   nth_machine = 0;
229 
230   list_start = gtk_container_get_children(AGS_WINDOW(xorg_application_context->window)->machines);
231   list = g_list_nth(list_start,
232 		    nth_machine);
233 
234   ags_test_leave();
235 
236   if(list != NULL &&
237      AGS_IS_DRUM(list->data)){
238     drum = list->data;
239   }else{
240     drum = NULL;
241   }
242 
243   CU_ASSERT(drum != NULL);
244 
245   /*
246    * resize output and input pads
247    */
248 
249   /* open properties */
250   ags_functional_test_util_machine_properties_open(nth_machine);
251 
252   /* click tab */
253   resize_tab = 4;
254 
255   ags_functional_test_util_machine_properties_click_tab(nth_machine,
256 							resize_tab);
257 
258   /* click enable */
259   ags_functional_test_util_machine_properties_click_enable(nth_machine);
260 
261   /* set output pads */
262   ags_functional_test_util_machine_properties_resize_outputs(nth_machine,
263 							     AGS_FUNCTIONAL_DRUM_TEST_RESIZE_OUTPUT_PADS);
264 
265   /* set input pads */
266   ags_functional_test_util_machine_properties_resize_inputs(nth_machine,
267 							    AGS_FUNCTIONAL_DRUM_TEST_RESIZE_INPUT_PADS);
268 
269   /* response ok */
270   ags_test_enter();
271 
272   properties = AGS_MACHINE(drum)->properties;
273 
274   ags_test_leave();
275 
276   ags_functional_test_util_dialog_ok(properties);
277 
278   /* destroy drum */
279   success = ags_functional_test_util_machine_destroy(0);
280 }
281 
282 void
ags_functional_drum_test_resize_audio_channels()283 ags_functional_drum_test_resize_audio_channels()
284 {
285   GtkDialog *properties;
286 
287   AgsXorgApplicationContext *xorg_application_context;
288 
289   AgsDrum *drum;
290 
291   GList *list_start, *list;
292 
293   guint nth_machine;
294   guint resize_tab;
295   gboolean success;
296 
297   /* add drum */
298   success = ags_functional_test_util_add_machine(NULL,
299 						 "Drum");
300 
301   CU_ASSERT(success == TRUE);
302 
303   /*  */
304   ags_test_enter();
305 
306   xorg_application_context = ags_application_context_get_instance();
307 
308   /* retrieve drum */
309   nth_machine = 0;
310 
311   list_start = gtk_container_get_children(AGS_WINDOW(xorg_application_context->window)->machines);
312   list = g_list_nth(list_start,
313 		    nth_machine);
314 
315   ags_test_leave();
316 
317   if(list != NULL &&
318      AGS_IS_DRUM(list->data)){
319     drum = list->data;
320   }else{
321     drum = NULL;
322   }
323 
324   CU_ASSERT(drum != NULL);
325 
326   /*
327    * resize audio channels
328    */
329 
330   /* open properties */
331   ags_functional_test_util_machine_properties_open(nth_machine);
332 
333   /* click tab */
334   resize_tab = 4;
335 
336   ags_functional_test_util_machine_properties_click_tab(nth_machine,
337 							resize_tab);
338 
339   /* click enable */
340   ags_functional_test_util_machine_properties_click_enable(nth_machine);
341 
342   /* set output audio_channels */
343   ags_functional_test_util_machine_properties_resize_audio_channels(nth_machine,
344 								    AGS_FUNCTIONAL_DRUM_TEST_RESIZE_AUDIO_CHANNELS);
345 
346   /* response ok */
347   ags_test_enter();
348 
349   properties = AGS_MACHINE(drum)->properties;
350 
351   ags_test_leave();
352 
353   ags_functional_test_util_dialog_ok(properties);
354 
355   /* destroy drum */
356   success = ags_functional_test_util_machine_destroy(0);
357 }
358 
359 int
main(int argc,char ** argv)360 main(int argc, char **argv)
361 {
362   /* initialize the CUnit test registry */
363   if(CUE_SUCCESS != CU_initialize_registry()){
364     return CU_get_error();
365   }
366 
367   /* add a suite to the registry */
368   pSuite = CU_add_suite("AgsFunctionalDrumTest", ags_functional_drum_test_init_suite, ags_functional_drum_test_clean_suite);
369 
370   if(pSuite == NULL){
371     CU_cleanup_registry();
372 
373     return CU_get_error();
374   }
375 
376   g_atomic_int_set(&is_available,
377 		   FALSE);
378 
379   ags_test_init(&argc, &argv,
380 		AGS_FUNCTIONAL_DRUM_TEST_CONFIG);
381   ags_functional_test_util_do_run(argc, argv,
382 				  ags_functional_drum_test_add_test, &is_available);
383 
384   g_thread_join(ags_functional_test_util_test_runner_thread());
385 
386   return(-1);
387 }
388