1 /* GSequencer - Advanced GTK Sequencer
2 * Copyright (C) 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 <stdlib.h>
31 #include <string.h>
32 #include <math.h>
33
34 int ags_osc_config_controller_test_init_suite();
35 int ags_osc_config_controller_test_clean_suite();
36
37 void ags_osc_config_controller_test_apply_config();
38
39 #define AGS_OSC_CONFIG_CONTROLLER_TEST_CONFIG "[generic]\n" \
40 "autosave-thread=false\n" \
41 "simple-file=false\n" \
42 "disable-feature=experimental\n" \
43 "segmentation=4/4\n" \
44 "\n" \
45 "[thread]\n" \
46 "model=super-threaded\n" \
47 "super-threaded-scope=channel\n" \
48 "lock-global=ags-thread\n" \
49 "lock-parent=ags-recycling-thread\n" \
50 "\n" \
51 "[soundcard-0]\n" \
52 "backend=alsa\n" \
53 "device=default\n" \
54 "samplerate=44100\n" \
55 "buffer-size=1024\n" \
56 "pcm-channels=2\n" \
57 "dsp-channels=2\n" \
58 "format=16\n" \
59 "\n" \
60 "[recall]\n" \
61 "auto-sense=true\n" \
62 "\n"
63
64 #define AGS_OSC_CONFIG_CONTROLLER_TEST_APPLY_CONFIG_ARGUMENT "[generic]\n" \
65 "autosave-thread=false\n" \
66 "simple-file=false\n" \
67 "disable-feature=experimental\n" \
68 "segmentation=4/4\n" \
69 "\n" \
70 "[thread]\n" \
71 "model=super-threaded\n" \
72 "super-threaded-scope=channel\n" \
73 "lock-global=ags-thread\n" \
74 "lock-parent=ags-recycling-thread\n" \
75 "\n" \
76 "[soundcard-0]\n" \
77 "backend=alsa\n" \
78 "device=default\n" \
79 "samplerate=44100\n" \
80 "buffer-size=256\n" \
81 "pcm-channels=2\n" \
82 "dsp-channels=2\n" \
83 "format=16\n" \
84 "\n" \
85 "[recall]\n" \
86 "auto-sense=true\n" \
87 "\n"
88
89 AgsApplicationContext *application_context;
90
91 GObject *default_soundcard;
92
93 /* The suite initialization function.
94 * Opens the temporary file used by the tests.
95 * Returns zero on success, non-zero otherwise.
96 */
97 int
ags_osc_config_controller_test_init_suite()98 ags_osc_config_controller_test_init_suite()
99 {
100 AgsConfig *config;
101
102 GList *start_audio;
103
104 ags_priority_load_defaults(ags_priority_get_instance());
105
106 config = ags_config_get_instance();
107 ags_config_load_from_data(config,
108 AGS_OSC_CONFIG_CONTROLLER_TEST_CONFIG,
109 strlen(AGS_OSC_CONFIG_CONTROLLER_TEST_CONFIG));
110
111 application_context = ags_audio_application_context_new();
112 g_object_ref(application_context);
113
114 ags_application_context_prepare(application_context);
115 ags_application_context_setup(application_context);
116
117 default_soundcard = ags_sound_provider_get_default_soundcard(AGS_SOUND_PROVIDER(application_context));
118
119 return(0);
120 }
121
122 /* The suite cleanup function.
123 * Closes the temporary file used by the tests.
124 * Returns zero on success, non-zero otherwise.
125 */
126 int
ags_osc_config_controller_test_clean_suite()127 ags_osc_config_controller_test_clean_suite()
128 {
129 return(0);
130 }
131
132 void
ags_osc_config_controller_test_apply_config()133 ags_osc_config_controller_test_apply_config()
134 {
135 AgsOscConnection *osc_connection;
136
137 AgsOscConfigController *osc_config_controller;
138
139 GList *osc_response;
140
141 unsigned char *message;
142
143 guint config_length;
144 guint length;
145
146 static const unsigned char *config_message = "/config\x00,s\x00\x00";
147
148 static const guint config_message_size = 12;
149
150 osc_connection = ags_osc_connection_new(NULL);
151
152 osc_config_controller = ags_osc_config_controller_new();
153
154 config_length = strlen(AGS_OSC_CONFIG_CONTROLLER_TEST_APPLY_CONFIG_ARGUMENT);
155
156 length = config_message_size + (4 * ceil((double) (config_length + 1) / 4.0));
157
158 message = (unsigned char *) malloc(length * sizeof(unsigned char));
159 memset(message, 0, length * sizeof(unsigned char));
160
161 memcpy(message, config_message, config_message_size * sizeof(unsigned char));
162 memcpy(message + config_message_size, AGS_OSC_CONFIG_CONTROLLER_TEST_APPLY_CONFIG_ARGUMENT, config_length * sizeof(unsigned char));
163
164 osc_response = ags_osc_config_controller_apply_config(osc_config_controller,
165 osc_connection,
166 message, length);
167
168 CU_ASSERT(osc_response != NULL);
169
170 sleep(5);
171 }
172
173 int
main(int argc,char ** argv)174 main(int argc, char **argv)
175 {
176 CU_pSuite pSuite = NULL;
177
178 putenv("LC_ALL=C");
179 putenv("LANG=C");
180
181 putenv("LADSPA_PATH=\"\"");
182 putenv("DSSI_PATH=\"\"");
183 putenv("LV2_PATH=\"\"");
184
185 /* initialize the CUnit test registry */
186 if(CUE_SUCCESS != CU_initialize_registry()){
187 return CU_get_error();
188 }
189
190 /* add a suite to the registry */
191 pSuite = CU_add_suite("AgsOscConfigControllerTest", ags_osc_config_controller_test_init_suite, ags_osc_config_controller_test_clean_suite);
192
193 if(pSuite == NULL){
194 CU_cleanup_registry();
195
196 return CU_get_error();
197 }
198
199 /* add the tests to the suite */
200 if((CU_add_test(pSuite, "test of AgsOscConfigController apply config", ags_osc_config_controller_test_apply_config) == NULL)){
201 CU_cleanup_registry();
202
203 return CU_get_error();
204 }
205
206 /* Run all tests using the CUnit Basic interface */
207 CU_basic_set_mode(CU_BRM_VERBOSE);
208 CU_basic_run_tests();
209
210 CU_cleanup_registry();
211
212 return(CU_get_error());
213 }
214
215