Debian Codegraph @

ags/test/audio/fx/ags_fx_analyse_channel_test.c

raw symbols SCIP
1 /* GSequencer - Advanced GTK Sequencer
2 * Copyright (C) 2005-2025 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_fx_analyse_channel_test_init_suite();
33 int ags_fx_analyse_channel_test_clean_suite();
34
35 void ags_fx_analyse_channel_stub_finalize(GObject *gobject);
36
37 void ags_fx_analyse_channel_test_new();
38 void ags_fx_analyse_channel_test_dispose();
39 void ags_fx_analyse_channel_test_finalize();
40 void ags_fx_analyse_channel_test_input_data_alloc();
41 void ags_fx_analyse_channel_test_input_data_free();
42
43 gboolean finalized;
44
45 void
46 ags_fx_analyse_channel_stub_finalize(GObject *gobject)
47 {
48 finalized = TRUE;
49 }
50
51 /* The suite initialization function.
52 * Opens the temporary file used by the tests.
53 * Returns zero on success, non-zero otherwise.
54 */
55 int
56 ags_fx_analyse_channel_test_init_suite()
57 {
58 ags_audio_application_context_new();
59
60 return(0);
61 }
62
63 /* The suite cleanup function.
64 * Closes the temporary file used by the tests.
65 * Returns zero on success, non-zero otherwise.
66 */
67 int
68 ags_fx_analyse_channel_test_clean_suite()
69 {
70 return(0);
71 }
72
73 void
74 ags_fx_analyse_channel_test_new()
75 {
76 AgsChannel *channel;
77 AgsFxAnalyseChannel *fx_analyse_channel;
78
79 guint i;
80 gboolean success;
81
82 channel = g_object_new(AGS_TYPE_CHANNEL,
83 NULL);
84
85 fx_analyse_channel = ags_fx_analyse_channel_new(channel);
86
87 CU_ASSERT(fx_analyse_channel != NULL);
88
89 CU_ASSERT(AGS_RECALL_CHANNEL(fx_analyse_channel)->source == channel);
90
91 CU_ASSERT(fx_analyse_channel->frequency != NULL);
92 CU_ASSERT(fx_analyse_channel->magnitude != NULL);
93
94 success = TRUE;
95
96 for(i = 0; i < AGS_SOUND_SCOPE_LAST; i++){
97 if(fx_analyse_channel->input_data[i]->parent == NULL){
98 success = FALSE;
99
100 break;
101 }
102
103 if(fx_analyse_channel->input_data[i]->plan == NULL){
104 success = FALSE;
105
106 break;
107 }
108
109 if(fx_analyse_channel->input_data[i]->comout == NULL){
110 success = FALSE;
111
112 break;
113 }
114
115 if(fx_analyse_channel->input_data[i]->in == NULL){
116 success = FALSE;
117
118 break;
119 }
120
121 if(fx_analyse_channel->input_data[i]->out == NULL){
122 success = FALSE;
123
124 break;
125 }
126 }
127
128 CU_ASSERT(success == TRUE);
129 }
130
131 void
132 ags_fx_analyse_channel_test_dispose()
133 {
134 AgsChannel *channel;
135 AgsFxAnalyseChannel *fx_analyse_channel;
136
137 channel = g_object_new(AGS_TYPE_CHANNEL,
138 NULL);
139
140 fx_analyse_channel = ags_fx_analyse_channel_new(channel);
141
142 g_object_run_dispose(fx_analyse_channel);
143
144 CU_ASSERT(fx_analyse_channel->frequency == NULL);
145 CU_ASSERT(fx_analyse_channel->magnitude == NULL);
146
147 g_object_unref(fx_analyse_channel);
148 }
149
150 void
151 ags_fx_analyse_channel_test_finalize()
152 {
153 AgsChannel *channel;
154 AgsFxAnalyseChannel *fx_analyse_channel;
155
156 GObjectClass *gobject_class;
157
158 gpointer stub;
159
160 /* attempt #0 */
161 channel = g_object_new(AGS_TYPE_CHANNEL,
162 NULL);
163
164 fx_analyse_channel = ags_fx_analyse_channel_new(channel);
165
166 gobject_class = (GObjectClass *) g_type_class_ref(AGS_TYPE_FX_ANALYSE_CHANNEL);
167
168 finalized = FALSE;
169
170 stub = gobject_class->finalize;
171 gobject_class->finalize = ags_fx_analyse_channel_stub_finalize;
172
173 g_object_run_dispose(fx_analyse_channel);
174 g_object_unref(fx_analyse_channel);
175
176 CU_ASSERT(finalized == TRUE);
177
178 gobject_class->finalize = stub;
179
180 /* attempt #1 */
181 channel = g_object_new(AGS_TYPE_CHANNEL,
182 NULL);
183
184 fx_analyse_channel = ags_fx_analyse_channel_new(channel);
185
186 g_object_run_dispose(fx_analyse_channel);
187 g_object_unref(fx_analyse_channel);
188 }
189
190 void
191 ags_fx_analyse_channel_test_input_data_alloc()
192 {
193 AgsFxAnalyseChannelInputData *input_data;
194
195 input_data = ags_fx_analyse_channel_input_data_alloc();
196
197 CU_ASSERT(input_data != NULL);
198 }
199
200 void
201 ags_fx_analyse_channel_test_input_data_free()
202 {
203 AgsFxAnalyseChannelInputData *input_data;
204
205 input_data = ags_fx_analyse_channel_input_data_alloc();
206
207 CU_ASSERT(input_data != NULL);
208
209 ags_fx_analyse_channel_input_data_free(input_data);
210 }
211
212 int
213 main(int argc, char **argv)
214 {
215 CU_pSuite pSuite = NULL;
216
217 putenv("LC_ALL=C");
218 putenv("LANG=C");
219
220 putenv("LADSPA_PATH=\"\"");
221 putenv("DSSI_PATH=\"\"");
222 putenv("LV2_PATH=\"\"");
223
224 /* initialize the CUnit test registry */
225 if(CUE_SUCCESS != CU_initialize_registry()){
226 return CU_get_error();
227 }
228
229 /* add a suite to the registry */
230 pSuite = CU_add_suite("AgsFxAnalyseChannelTest", ags_fx_analyse_channel_test_init_suite, ags_fx_analyse_channel_test_clean_suite);
231
232 if(pSuite == NULL){
233 CU_cleanup_registry();
234
235 return CU_get_error();
236 }
237
238 /* add the tests to the suite */
239 if((CU_add_test(pSuite, "test of AgsFxAnalyseChannel new", ags_fx_analyse_channel_test_new) == NULL) ||
240 (CU_add_test(pSuite, "test of AgsFxAnalyseChannel dispose", ags_fx_analyse_channel_test_dispose) == NULL) ||
241 (CU_add_test(pSuite, "test of AgsFxAnalyseChannel finalize", ags_fx_analyse_channel_test_finalize) == NULL) ||
242 (CU_add_test(pSuite, "test of AgsFxAnalyseChannel input data alloc", ags_fx_analyse_channel_test_input_data_alloc) == NULL) ||
243 (CU_add_test(pSuite, "test of AgsFxAnalyseChannel input data free", ags_fx_analyse_channel_test_input_data_free) == NULL)){
244 CU_cleanup_registry();
245
246 return CU_get_error();
247 }
248
249 /* Run all tests using the CUnit Basic interface */
250 CU_basic_set_mode(CU_BRM_VERBOSE);
251 CU_basic_run_tests();
252
253 CU_cleanup_registry();
254
255 return(CU_get_error());
256 }