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_play_wave_channel_test_init_suite();
33 int ags_play_wave_channel_test_clean_suite();
34 
35 void ags_play_wave_channel_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_play_wave_channel_test_init_suite()47 ags_play_wave_channel_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_play_wave_channel_test_clean_suite()100 ags_play_wave_channel_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_play_wave_channel_test_port()112 ags_play_wave_channel_test_port()
113 {
114   AgsPlayWaveChannel *play_wave_channel;
115   AgsPort *port;
116 
117   play_wave_channel = ags_play_wave_channel_new(audio->input);
118 
119   CU_ASSERT(play_wave_channel != NULL);
120   CU_ASSERT(AGS_IS_PLAY_WAVE_CHANNEL(play_wave_channel));
121 
122   /* test ports */
123   port = NULL;
124   g_object_get(play_wave_channel,
125 	       "do-playback", &port,
126 	       NULL);
127 
128   CU_ASSERT(port != NULL);
129   CU_ASSERT(AGS_IS_PORT(port));
130 
131   port = NULL;
132   g_object_get(play_wave_channel,
133 	       "x-offset", &port,
134 	       NULL);
135 
136   CU_ASSERT(port != NULL);
137   CU_ASSERT(AGS_IS_PORT(port));
138 }
139 
140 int
main(int argc,char ** argv)141 main(int argc, char **argv)
142 {
143   CU_pSuite pSuite = NULL;
144 
145   putenv("LC_ALL=C");
146   putenv("LANG=C");
147 
148   putenv("LADSPA_PATH=\"\"");
149   putenv("DSSI_PATH=\"\"");
150   putenv("LV2_PATH=\"\"");
151 
152   /* initialize the CUnit test registry */
153   if(CUE_SUCCESS != CU_initialize_registry()){
154     return CU_get_error();
155   }
156 
157   /* add a suite to the registry */
158   pSuite = CU_add_suite("AgsPlayWaveChannelTest", ags_play_wave_channel_test_init_suite, ags_play_wave_channel_test_clean_suite);
159 
160   if(pSuite == NULL){
161     CU_cleanup_registry();
162 
163     return CU_get_error();
164   }
165 
166   /* add the tests to the suite */
167   if((CU_add_test(pSuite, "test of AgsPlayWaveChannel port", ags_play_wave_channel_test_port) == NULL)){
168     CU_cleanup_registry();
169 
170     return CU_get_error();
171   }
172 
173   /* Run all tests using the CUnit Basic interface */
174   CU_basic_set_mode(CU_BRM_VERBOSE);
175   CU_basic_run_tests();
176 
177   CU_cleanup_registry();
178 
179   return(CU_get_error());
180 }
181