32
32
33
33
#include <memory.h>
34
34
#include <locale.h>
35
- #include <stdlib.h>
36
- #include <unistd.h>
37
35
38
36
#ifndef LINGOT_TEST_RESOURCES_PATH
39
37
#define LINGOT_TEST_RESOURCES_PATH "test/"
@@ -75,13 +73,6 @@ static void check_last_configs(const lingot_config_t* config) {
75
73
76
74
void lingot_test_io_config (void ) {
77
75
78
- lingot_io_config_create_parameter_specs ();
79
- lingot_config_t _config ;
80
- lingot_config_t * config = & _config ;
81
- lingot_config_new (config );
82
-
83
- CU_ASSERT_PTR_NOT_NULL_FATAL (config );
84
-
85
76
// check if the files are there
86
77
const char * filename = LINGOT_TEST_RESOURCES_PATH "resources/lingot-001.conf" ;
87
78
@@ -93,88 +84,79 @@ void lingot_test_io_config(void) {
93
84
return ; // we allow the test resources to be not present for the distcheck.
94
85
}
95
86
87
+ lingot_io_config_create_parameter_specs ();
88
+ lingot_config_t _config ;
89
+ lingot_config_t * config = & _config ;
90
+ lingot_config_new (config );
91
+
92
+ CU_ASSERT_PTR_NOT_NULL_FATAL (config );
93
+
96
94
// old file with obsolete options
97
95
// ------------------------------
98
96
99
97
int ok ;
100
98
ok = lingot_io_config_load (config , LINGOT_TEST_RESOURCES_PATH "resources/lingot-001.conf" );
99
+ CU_ASSERT (ok );
101
100
102
- if (ok ) { // TODO: assert
103
-
104
- CU_ASSERT_EQUAL (config -> audio_system_index , lingot_audio_system_find_by_name ("PulseAudio" ));
105
- CU_ASSERT (!strcmp (config -> audio_dev [config -> audio_system_index ],
106
- "alsa_input.pci-0000_00_1b.0.analog-stereo" ));
107
- CU_ASSERT_EQUAL (config -> sample_rate , 44100 );
108
- CU_ASSERT_EQUAL (config -> root_frequency_error , 0.0 );
109
- CU_ASSERT_EQUAL (config -> sample_rate , 44100 );
110
- CU_ASSERT_EQUAL (config -> fft_size , 512 );
111
- CU_ASSERT_EQUAL (config -> min_overall_SNR , 20.0 );
112
- CU_ASSERT_EQUAL (config -> calculation_rate , 20.0 );
113
- } else {
114
- fprintf (stderr , "warning: cannot find unit test resources\n" );
115
- }
101
+ CU_ASSERT_EQUAL (config -> audio_system_index , lingot_audio_system_find_by_name ("PulseAudio" ));
102
+ CU_ASSERT (!strcmp (config -> audio_dev [config -> audio_system_index ],
103
+ "alsa_input.pci-0000_00_1b.0.analog-stereo" ));
104
+ CU_ASSERT_EQUAL (config -> sample_rate , 44100 );
105
+ CU_ASSERT_EQUAL (config -> root_frequency_error , 0.0 );
106
+ CU_ASSERT_EQUAL (config -> sample_rate , 44100 );
107
+ CU_ASSERT_EQUAL (config -> fft_size , 512 );
108
+ CU_ASSERT_EQUAL (config -> min_overall_SNR , 20.0 );
109
+ CU_ASSERT_EQUAL (config -> calculation_rate , 20.0 );
116
110
117
111
// recent file
118
112
// -----------
119
113
120
114
ok = lingot_io_config_load (config , LINGOT_TEST_RESOURCES_PATH "resources/lingot-0_9_2b8.conf" );
121
- if (ok ) { // TODO: assert
115
+ CU_ASSERT (ok );
122
116
123
117
#ifdef PULSEAUDIO
124
- CU_ASSERT_EQUAL (config -> audio_system_index , lingot_audio_system_find_by_name ("PulseAudio" ));
125
- CU_ASSERT (!strcmp (config -> audio_dev [config -> audio_system_index ], "default" ));
118
+ CU_ASSERT_EQUAL (config -> audio_system_index , lingot_audio_system_find_by_name ("PulseAudio" ));
119
+ CU_ASSERT (!strcmp (config -> audio_dev [config -> audio_system_index ], "default" ));
126
120
#endif
127
- CU_ASSERT_EQUAL (config -> sample_rate , 44100 );
128
- CU_ASSERT_EQUAL (config -> root_frequency_error , 0.0 );
129
- CU_ASSERT_EQUAL (config -> fft_size , 512 );
130
- CU_ASSERT_EQUAL (config -> sample_rate , 44100 );
131
- CU_ASSERT_EQUAL (config -> temporal_window , 0.3 );
132
- CU_ASSERT_EQUAL (config -> min_overall_SNR , 20.0 );
133
- CU_ASSERT_EQUAL (config -> calculation_rate , 15.0 );
134
- CU_ASSERT_EQUAL (config -> min_frequency , 82.41 );
135
- CU_ASSERT_EQUAL (config -> max_frequency , 329.63 );
136
-
137
- CU_ASSERT (!strcmp (config -> scale .name , "Default equal-tempered scale" ));
138
- CU_ASSERT_EQUAL (config -> scale .notes , 12 );
139
- CU_ASSERT_EQUAL (config -> scale .base_frequency , 261.625565 );
140
- CU_ASSERT (!strcmp (config -> scale .note_name [1 ], "C#" ));
141
- CU_ASSERT (!strcmp (config -> scale .note_name [11 ], "B" ));
142
-
143
- CU_ASSERT_EQUAL (config -> scale .offset_ratios [0 ][0 ], 1 );
144
- CU_ASSERT_EQUAL (config -> scale .offset_ratios [1 ][0 ], 1 ); // defined as ratio
145
- CU_ASSERT_EQUAL (config -> scale .offset_cents [0 ], 0.0 );
146
-
147
- CU_ASSERT_EQUAL (config -> scale .offset_ratios [0 ][1 ], -1 );
148
- CU_ASSERT_EQUAL (config -> scale .offset_ratios [1 ][1 ], -1 ); // not defined as ratio
149
- CU_ASSERT_EQUAL (config -> scale .offset_cents [1 ], 100.0 ); // defined as shift in cents
150
-
151
- CU_ASSERT_EQUAL (config -> scale .offset_ratios [0 ][11 ], -1 );
152
- CU_ASSERT_EQUAL (config -> scale .offset_ratios [1 ][11 ], -1 ); // not defined as ratio
153
- CU_ASSERT_EQUAL (config -> scale .offset_cents [11 ], 1100.0 ); // defined as shift in cents
154
- } else {
155
- fprintf (stderr , "warning: cannot find unit test resources\n" );
156
- }
121
+ CU_ASSERT_EQUAL (config -> sample_rate , 44100 );
122
+ CU_ASSERT_EQUAL (config -> root_frequency_error , 0.0 );
123
+ CU_ASSERT_EQUAL (config -> fft_size , 512 );
124
+ CU_ASSERT_EQUAL (config -> sample_rate , 44100 );
125
+ CU_ASSERT_EQUAL (config -> temporal_window , 0.3 );
126
+ CU_ASSERT_EQUAL (config -> min_overall_SNR , 20.0 );
127
+ CU_ASSERT_EQUAL (config -> calculation_rate , 15.0 );
128
+ CU_ASSERT_EQUAL (config -> min_frequency , 82.41 );
129
+ CU_ASSERT_EQUAL (config -> max_frequency , 329.63 );
130
+
131
+ CU_ASSERT (!strcmp (config -> scale .name , "Default equal-tempered scale" ));
132
+ CU_ASSERT_EQUAL (config -> scale .notes , 12 );
133
+ CU_ASSERT_EQUAL (config -> scale .base_frequency , 261.625565 );
134
+ CU_ASSERT (!strcmp (config -> scale .note_name [1 ], "C#" ));
135
+ CU_ASSERT (!strcmp (config -> scale .note_name [11 ], "B" ));
136
+
137
+ CU_ASSERT_EQUAL (config -> scale .offset_ratios [0 ][0 ], 1 );
138
+ CU_ASSERT_EQUAL (config -> scale .offset_ratios [1 ][0 ], 1 ); // defined as ratio
139
+ CU_ASSERT_EQUAL (config -> scale .offset_cents [0 ], 0.0 );
140
+
141
+ CU_ASSERT_EQUAL (config -> scale .offset_ratios [0 ][1 ], -1 );
142
+ CU_ASSERT_EQUAL (config -> scale .offset_ratios [1 ][1 ], -1 ); // not defined as ratio
143
+ CU_ASSERT_EQUAL (config -> scale .offset_cents [1 ], 100.0 ); // defined as shift in cents
144
+
145
+ CU_ASSERT_EQUAL (config -> scale .offset_ratios [0 ][11 ], -1 );
146
+ CU_ASSERT_EQUAL (config -> scale .offset_ratios [1 ][11 ], -1 ); // not defined as ratio
147
+ CU_ASSERT_EQUAL (config -> scale .offset_cents [11 ], 1100.0 ); // defined as shift in cents
157
148
158
149
// -----------
159
150
160
151
ok = lingot_io_config_load (config , LINGOT_TEST_RESOURCES_PATH "resources/lingot-1_0_2b.conf" );
161
-
162
152
CU_ASSERT (ok );
163
153
164
154
check_last_configs (config );
165
155
166
156
// we check that we can save and load it again
167
- char temp_filename [32 ];
168
- strncpy (temp_filename ,"/tmp/lingot-XXXXXX" , sizeof (temp_filename ));
169
-
170
- int temp_file_id = mkstemps (temp_filename , 6 );
171
- CU_ASSERT (temp_file_id >= 0 );
172
- ok = close (temp_file_id );
173
-
174
- CU_ASSERT (!ok );
175
- ok = lingot_io_config_save (config , filename );
176
- CU_ASSERT (ok != -1 );
177
157
158
+ filename = tmpnam (NULL );
159
+ lingot_io_config_save (config , filename );
178
160
ok = lingot_io_config_load (config , filename );
179
161
CU_ASSERT (ok );
180
162
check_last_configs (config );
@@ -192,11 +174,7 @@ void lingot_test_io_config(void) {
192
174
193
175
// we check that we can save and load it again
194
176
195
- temp_file_id = mkstemps (temp_filename , 6 );
196
- CU_ASSERT (temp_file_id >= 0 );
197
- ok = close (temp_file_id );
198
-
199
- CU_ASSERT (!ok );
177
+ filename = tmpnam (NULL );
200
178
lingot_io_config_save (config , filename );
201
179
ok = lingot_io_config_load (config , filename );
202
180
CU_ASSERT (ok );
0 commit comments