Skip to content

Commit 81978f1

Browse files
authored
minor: Fix fileformat unit tests (#3520)
1 parent fd1994e commit 81978f1

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

src/fileformat.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ static void file_type(char const *filename, file_info_t *info)
203203
else if (len == 4 && !strncasecmp("cf32", t, 4)) file_type_set_format(&info->format, F_CF32);
204204
else if (len == 5 && !strncasecmp("cfile", t, 5)) file_type_set_format(&info->format, F_CF32); // compat
205205
else if (len == 5 && !strncasecmp("logic", t, 5)) file_type_set_content(&info->format, F_LOGIC);
206-
else if (len == 3 && !strncasecmp("complex16u", t, 10)) file_type_set_format(&info->format, F_CU8); // compat
207-
else if (len == 3 && !strncasecmp("complex16s", t, 10)) file_type_set_format(&info->format, F_CS8); // compat
208-
else if (len == 4 && !strncasecmp("complex", t, 7)) file_type_set_format(&info->format, F_CF32); // compat
209-
//else fprintf(stderr, "Skipping type (len %ld) %s\n", len, t);
206+
else if (len == 10 && !strncasecmp("complex16u", t, 10)) file_type_set_format(&info->format, F_CU8); // compat
207+
else if (len == 10 && !strncasecmp("complex16s", t, 10)) file_type_set_format(&info->format, F_CS8); // compat
208+
else if (len == 7 && !strncasecmp("complex", t, 7)) file_type_set_format(&info->format, F_CF32); // compat
209+
//else fprintf(stderr, "Skipping type (len %lu) %s\n", (unsigned long)len, t);
210210
} else {
211211
p++; // skip non-alphanum char otherwise
212212
}
@@ -278,40 +278,48 @@ int file_info_parse_filename(file_info_t *info, char const *filename)
278278

279279
// Unit testing
280280
#ifdef _TEST
281+
static unsigned passed = 0;
282+
static unsigned failed = 0;
283+
281284
static void assert_file_type(int check, char const *spec)
282285
{
283286
file_info_t info = {0};
284287
int ret = file_info_parse_filename(&info, spec);
285288
if (check != ret) {
289+
++failed;
286290
fprintf(stderr, "\nTEST failed: determine_file_type(\"%s\", &foo) = %8x == %8x\n", spec, ret, check);
287291
} else {
288-
fprintf(stderr, ".");
292+
++passed;
289293
}
290294
}
291295

292296
static void assert_str_equal(char const *a, char const *b)
293297
{
294298
if (a != b && (!a || !b || strcmp(a, b))) {
299+
++failed;
295300
fprintf(stderr, "\nTEST failed: \"%s\" == \"%s\"\n", a, b);
296301
} else {
297-
fprintf(stderr, ".");
302+
++passed;
298303
}
299304
}
300305

301306
int main(void)
302307
{
303-
fprintf(stderr, "Testing:\n");
304-
308+
fprintf(stderr, "fileformat:: last_plain_colon\n");
305309
assert_str_equal(last_plain_colon("foo:bar:baz"), ":baz");
306310
assert_str_equal(last_plain_colon("foo"), NULL);
307311
assert_str_equal(last_plain_colon(":foo"), ":foo");
308312
assert_str_equal(last_plain_colon("foo:"), ":");
309313
assert_str_equal(last_plain_colon("foo:bar:C:\\path.txt"), ":C:\\path.txt");
310314
assert_str_equal(last_plain_colon("foo:bar:C:\\path.txt:baz"), ":C:\\path.txt:baz");
311315

316+
fprintf(stderr, "fileformat:: file_info_parse_filename\n");
312317
assert_file_type(CU8_IQ, "cu8:");
313318
assert_file_type(CS16_IQ, "cs16:");
314319
assert_file_type(CF32_IQ, "cf32:");
320+
assert_file_type(CU8_IQ, "complex16u:");
321+
assert_file_type(CS8_IQ, "complex16s:");
322+
assert_file_type(CF32_IQ, "complex:");
315323
assert_file_type(S16_AM, "am:");
316324
assert_file_type(S16_AM, "am.s16:");
317325
assert_file_type(S16_AM, "am-s16:");
@@ -351,6 +359,8 @@ int main(void)
351359
assert_file_type(S16_FM, ".s16_fm");
352360
assert_file_type(S16_FM, ".s16,fm");
353361

354-
fprintf(stderr, "\nDone!\n");
362+
fprintf(stderr, "fileformat:: test (%u/%u) passed, (%u) failed.\n", passed, passed + failed, failed);
363+
364+
return failed > 0 ? 1 : 0;
355365
}
356366
#endif /* _TEST */

0 commit comments

Comments
 (0)