Debian Codegraph @

ags/test/audio/fx/ags_fx_peak_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_peak_channel_test_init_suite();
33 int ags_fx_peak_channel_test_clean_suite();
34
35 void ags_fx_peak_channel_stub_finalize(GObject *gobject);
36
37 void ags_fx_peak_channel_test_new();
38 void ags_fx_peak_channel_test_dispose();
39 void ags_fx_peak_channel_test_finalize();
40 void ags_fx_peak_channel_test_input_data_alloc();
41 void ags_fx_peak_channel_test_input_data_free();
42
43 gboolean finalized;
44
45 void
46 ags_fx_peak_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_peak_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_peak_channel_test_clean_suite()
69 {
70 return(0);
71 }
72
73 void
74 ags_fx_peak_channel_test_new()
75 {
76 AgsChannel *channel;
77 AgsFxPeakChannel *fx_peak_channel;
78
79 guint i;
80 gboolean success;
81
82 channel = g_object_new(AGS_TYPE_CHANNEL,
83 NULL);
84
85 fx_peak_channel = ags_fx_peak_channel_new(channel);
86
87 CU_ASSERT(fx_peak_channel != NULL);
88 CU_ASSERT(AGS_RECALL_CHANNEL(fx_peak_channel)->source == channel);
89
90 CU_ASSERT(fx_peak_channel->peak != NULL);
91
92 success = TRUE;
93
94 for(i = 0; i < AGS_SOUND_SCOPE_LAST; i++){
95 if(fx_peak_channel->input_data[i]->parent == NULL){
96 success = FALSE;
97
98 break;
99 }
100
101 if(fx_peak_channel->input_data[i]->buffer == NULL){
102 success = FALSE;
103
104 break;
105 }
106 }
107
108 CU_ASSERT(success == TRUE);
109 }
110
111
112 void
113 ags_fx_peak_channel_test_dispose()
114 {
115 AgsChannel *channel;
116 AgsFxPeakChannel *fx_peak_channel;
117
118 channel = g_object_new(AGS_TYPE_CHANNEL,
119 NULL);
120
121 fx_peak_channel = ags_fx_peak_channel_new(channel);
122
123 g_object_run_dispose(fx_peak_channel);
124
125 CU_ASSERT(fx_peak_channel->peak == NULL);
126
127 g_object_unref(fx_peak_channel);
128 }
129
130 void
131 ags_fx_peak_channel_test_finalize()
132 {
133 AgsChannel *channel;
134 AgsFxPeakChannel *fx_peak_channel;
135
136 GObjectClass *gobject_class;
137
138 gpointer stub;
139
140 /* attempt #0 */
141 channel = g_object_new(AGS_TYPE_CHANNEL,
142 NULL);
143
144 fx_peak_channel = ags_fx_peak_channel_new(channel);
145
146 gobject_class = (GObjectClass *) g_type_class_ref(AGS_TYPE_FX_PEAK_CHANNEL);
147
148 finalized = FALSE;
149
150 stub = gobject_class->finalize;
151 gobject_class->finalize = ags_fx_peak_channel_stub_finalize;
152
153 g_object_run_dispose(fx_peak_channel);
154 g_object_unref(fx_peak_channel);
155
156 CU_ASSERT(finalized == TRUE);
157
158 gobject_class->finalize = stub;
159
160 /* attempt #1 */
161 channel = g_object_new(AGS_TYPE_CHANNEL,
162 NULL);
163
164 fx_peak_channel = ags_fx_peak_channel_new(channel);
165
166 g_object_run_dispose(fx_peak_channel);
167 g_object_unref(fx_peak_channel);
168 }
169
170 void
171 ags_fx_peak_channel_test_input_data_alloc()
172 {
173 AgsFxPeakChannelInputData *input_data;
174
175 input_data = ags_fx_peak_channel_input_data_alloc();
176
177 CU_ASSERT(input_data != NULL);
178 }
179
180 void
181 ags_fx_peak_channel_test_input_data_free()
182 {
183 AgsFxPeakChannelInputData *input_data;
184
185 input_data = ags_fx_peak_channel_input_data_alloc();
186
187 CU_ASSERT(input_data != NULL);
188
189 ags_fx_peak_channel_input_data_free(input_data);
190 }
191
192 int
193 main(int argc, char **argv)
194 {
195 CU_pSuite pSuite = NULL;
196
197 putenv("LC_ALL=C");
198 putenv("LANG=C");
199
200 putenv("LADSPA_PATH=\"\"");
201 putenv("DSSI_PATH=\"\"");
202 putenv("LV2_PATH=\"\"");
203
204 /* initialize the CUnit test registry */
205 if(CUE_SUCCESS != CU_initialize_registry()){
206 return CU_get_error();
207 }
208
209 /* add a suite to the registry */
210 pSuite = CU_add_suite("AgsFxPeakChannelTest", ags_fx_peak_channel_test_init_suite, ags_fx_peak_channel_test_clean_suite);
211
212 if(pSuite == NULL){
213 CU_cleanup_registry();
214
215 return CU_get_error();
216 }
217
218 /* add the tests to the suite */
219 if((CU_add_test(pSuite, "test of AgsFxPeakChannel new", ags_fx_peak_channel_test_new) == NULL) ||
220 (CU_add_test(pSuite, "test of AgsFxPeakChannel dispose", ags_fx_peak_channel_test_dispose) == NULL) ||
221 (CU_add_test(pSuite, "test of AgsFxPeakChannel finalize", ags_fx_peak_channel_test_finalize) == NULL) ||
222 (CU_add_test(pSuite, "test of AgsFxPeakChannel input data alloc", ags_fx_peak_channel_test_input_data_alloc) == NULL) ||
223 (CU_add_test(pSuite, "test of AgsFxPeakChannel input data free", ags_fx_peak_channel_test_input_data_free) == NULL)){
224 CU_cleanup_registry();
225
226 return CU_get_error();
227 }
228
229 /* Run all tests using the CUnit Basic interface */
230 CU_basic_set_mode(CU_BRM_VERBOSE);
231 CU_basic_run_tests();
232
233 CU_cleanup_registry();
234
235 return(CU_get_error());
236 }