1 /* GSequencer - Advanced GTK Sequencer
2 * Copyright (C) 2005-2018 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/Automated.h>
25 #include <CUnit/Basic.h>
26
27 #include <ags/libags.h>
28 #include <ags/libags-audio.h>
29
30 #include <math.h>
31
32 int ags_count_beats_audio_test_init_suite();
33 int ags_count_beats_audio_test_clean_suite();
34
35 void ags_count_beats_audio_test_port();
36
37 AgsDevout *devout;
38 AgsAudio *audio;
39
40 AgsApplicationContext *application_context;
41
42 /* The suite initialization function.
43 * Opens the temporary file used by the tests.
44 * Returns zero on success, non-zero otherwise.
45 */
46 int
ags_count_beats_audio_test_init_suite()47 ags_count_beats_audio_test_init_suite()
48 {
49 application_context = ags_audio_application_context_new();
50 g_object_ref(application_context);
51
52 ags_application_context_prepare(application_context);
53 ags_application_context_setup(application_context);
54
55 /* create soundcard */
56 devout = g_object_new(AGS_TYPE_DEVOUT,
57 NULL);
58 g_object_ref(devout);
59
60 /* create audio */
61 audio = ags_audio_new(devout);
62 g_object_ref(audio);
63
64 ags_audio_set_flags(audio,
65 (AGS_AUDIO_OUTPUT_HAS_RECYCLING |
66 AGS_AUDIO_INPUT_HAS_RECYCLING));
67 ags_audio_set_ability_flags(audio,
68 AGS_SOUND_ABILITY_PLAYBACK);
69
70 /* create input/output */
71 ags_audio_set_audio_channels(audio,
72 1, 0);
73
74 ags_audio_set_pads(audio,
75 AGS_TYPE_OUTPUT,
76 1, 0);
77 ags_audio_set_pads(audio,
78 AGS_TYPE_INPUT,
79 1, 0);
80
81 ags_channel_set_ability_flags(audio->output,
82 AGS_SOUND_ABILITY_PLAYBACK);
83
84 ags_channel_set_ability_flags(audio->input,
85 AGS_SOUND_ABILITY_PLAYBACK);
86
87 ags_connectable_connect(AGS_CONNECTABLE(audio));
88
89 ags_connectable_connect(AGS_CONNECTABLE(audio->output));
90 ags_connectable_connect(AGS_CONNECTABLE(audio->input));
91
92 return(0);
93 }
94
95 /* The suite cleanup function.
96 * Closes the temporary file used by the tests.
97 * Returns zero on success, non-zero otherwise.
98 */
99 int
ags_count_beats_audio_test_clean_suite()100 ags_count_beats_audio_test_clean_suite()
101 {
102 g_object_run_dispose(devout);
103 g_object_unref(devout);
104
105 g_object_run_dispose(audio);
106 g_object_unref(audio);
107
108 return(0);
109 }
110
111 void
ags_count_beats_audio_test_port()112 ags_count_beats_audio_test_port()
113 {
114 AgsCountBeatsAudio *count_beats_audio;
115 AgsPort *port;
116
117 count_beats_audio = ags_count_beats_audio_new(audio);
118
119 CU_ASSERT(count_beats_audio != NULL);
120 CU_ASSERT(AGS_IS_COUNT_BEATS_AUDIO(count_beats_audio));
121
122 /* test ports - sequencer */
123 port = NULL;
124 g_object_get(count_beats_audio,
125 "sequencer-loop", &port,
126 NULL);
127
128 CU_ASSERT(port != NULL);
129 CU_ASSERT(AGS_IS_PORT(port));
130
131 port = NULL;
132 g_object_get(count_beats_audio,
133 "sequencer-loop-start", &port,
134 NULL);
135
136 CU_ASSERT(port != NULL);
137 CU_ASSERT(AGS_IS_PORT(port));
138
139 port = NULL;
140 g_object_get(count_beats_audio,
141 "sequencer-loop-end", &port,
142 NULL);
143
144 CU_ASSERT(port != NULL);
145 CU_ASSERT(AGS_IS_PORT(port));
146
147 /* test ports - notation */
148 port = NULL;
149 g_object_get(count_beats_audio,
150 "notation-loop", &port,
151 NULL);
152
153 CU_ASSERT(port != NULL);
154 CU_ASSERT(AGS_IS_PORT(port));
155
156 port = NULL;
157 g_object_get(count_beats_audio,
158 "notation-loop-start", &port,
159 NULL);
160
161 CU_ASSERT(port != NULL);
162 CU_ASSERT(AGS_IS_PORT(port));
163
164 port = NULL;
165 g_object_get(count_beats_audio,
166 "notation-loop-end", &port,
167 NULL);
168
169 CU_ASSERT(port != NULL);
170 CU_ASSERT(AGS_IS_PORT(port));
171
172 /* test ports - wave */
173 port = NULL;
174 g_object_get(count_beats_audio,
175 "wave-loop", &port,
176 NULL);
177
178 CU_ASSERT(port != NULL);
179 CU_ASSERT(AGS_IS_PORT(port));
180
181 port = NULL;
182 g_object_get(count_beats_audio,
183 "wave-loop-start", &port,
184 NULL);
185
186 CU_ASSERT(port != NULL);
187 CU_ASSERT(AGS_IS_PORT(port));
188
189 port = NULL;
190 g_object_get(count_beats_audio,
191 "wave-loop-end", &port,
192 NULL);
193
194 CU_ASSERT(port != NULL);
195 CU_ASSERT(AGS_IS_PORT(port));
196
197 /* test ports - midi */
198 port = NULL;
199 g_object_get(count_beats_audio,
200 "midi-loop", &port,
201 NULL);
202
203 CU_ASSERT(port != NULL);
204 CU_ASSERT(AGS_IS_PORT(port));
205
206 port = NULL;
207 g_object_get(count_beats_audio,
208 "midi-loop-start", &port,
209 NULL);
210
211 CU_ASSERT(port != NULL);
212 CU_ASSERT(AGS_IS_PORT(port));
213
214 port = NULL;
215 g_object_get(count_beats_audio,
216 "midi-loop-end", &port,
217 NULL);
218
219 CU_ASSERT(port != NULL);
220 CU_ASSERT(AGS_IS_PORT(port));
221 }
222
223 int
main(int argc,char ** argv)224 main(int argc, char **argv)
225 {
226 CU_pSuite pSuite = NULL;
227
228 putenv("LC_ALL=C");
229 putenv("LANG=C");
230
231 putenv("LADSPA_PATH=\"\"");
232 putenv("DSSI_PATH=\"\"");
233 putenv("LV2_PATH=\"\"");
234
235 /* initialize the CUnit test registry */
236 if(CUE_SUCCESS != CU_initialize_registry()){
237 return CU_get_error();
238 }
239
240 /* add a suite to the registry */
241 pSuite = CU_add_suite("AgsCountBeatsAudioTest", ags_count_beats_audio_test_init_suite, ags_count_beats_audio_test_clean_suite);
242
243 if(pSuite == NULL){
244 CU_cleanup_registry();
245
246 return CU_get_error();
247 }
248
249 /* add the tests to the suite */
250 if((CU_add_test(pSuite, "test of AgsCountBeatsAudio port", ags_count_beats_audio_test_port) == NULL)){
251 CU_cleanup_registry();
252
253 return CU_get_error();
254 }
255
256 /* Run all tests using the CUnit Basic interface */
257 CU_basic_set_mode(CU_BRM_VERBOSE);
258 CU_basic_run_tests();
259
260 CU_cleanup_registry();
261
262 return(CU_get_error());
263 }
264