-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtests_rffft_internal.c
104 lines (87 loc) · 4.25 KB
/
tests_rffft_internal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "tests_rffft_internal.h"
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdlib.h>
#include <cmocka.h>
#include "../rffft_internal.h"
// Tests
// Test SatDump filenames
void rffft_internal_parse_satdump_filenames(void **state) {
double samplerate = 0;
double frequency = 0;
char format = '\0';
char starttime[] = "YYYY-mm-ddTHH:MM:SS.sss";
char ref_format = '\0';
// s8 file without milliseconds
ref_format = 'c';
assert_int_equal(0, rffft_params_from_filename("2023-08-05_08-02-00_16000000SPS_2274000000Hz.s8", &samplerate, &frequency, &format, starttime));
// assert_double_equal has been introduced in cmocka 1.1.6 not available on most distribs yet
assert_float_equal(16e6, samplerate, 1e-12);
assert_float_equal(2.274e9, frequency, 1e-12);
assert_memory_equal(&ref_format, &format, 1);
assert_string_equal("2023-08-05T08:02:00", starttime);
// f32 file with milliseconds
ref_format = 'f';
assert_int_equal(0, rffft_params_from_filename("2023-08-17_11-41-14-373_1000000SPS_100000000Hz.f32", &samplerate, &frequency, &format, starttime));
assert_float_equal(1e6, samplerate, 1e-12);
assert_float_equal(100e6, frequency, 1e-12);
assert_memory_equal(&ref_format, &format, 1);
assert_string_equal("2023-08-17T11:41:14.373", starttime);
// s16 file with broken milliseconds format
ref_format = 'i';
assert_int_equal(0, rffft_params_from_filename("2023-08-05_18-02-45-1691258565.534000_8000000SPS_2284000000Hz.s16", &samplerate, &frequency, &format, starttime));
assert_float_equal(8e6, samplerate, 1e-12);
assert_float_equal(2.284e9, frequency, 1e-12);
assert_memory_equal(&ref_format, &format, 1);
assert_string_equal("2023-08-05T18:02:45.534", starttime);
// wav file with milliseconds
ref_format = 'w';
assert_int_equal(0, rffft_params_from_filename("2023-08-07_16-36-47-749_2400000SPS_100000000Hz.wav", &samplerate, &frequency, &format, starttime));
assert_float_equal(2.4e6, samplerate, 1e-12);
assert_float_equal(100e6, frequency, 1e-12);
assert_memory_equal(&ref_format, &format, 1);
assert_string_equal("2023-08-07T16:36:47.749", starttime);
assert_int_equal(-1, rffft_params_from_filename("2023-08-05-19:59:30_16000000SPS_402000000Hz.f32", &samplerate, &frequency, &format, starttime));
}
// Test GQRX filenames
void rffft_internal_parse_gqrx_filenames(void **state) {
double samplerate = 0;
double frequency = 0;
char format = '\0';
char starttime[] = "YYYY-mm-ddTHH:MM:SS.sss";
char ref_format = '\0';
ref_format = 'f';
assert_int_equal(0, rffft_params_from_filename("gqrx_20230806_151838_428000000_200000_fc.raw", &samplerate, &frequency, &format, starttime));
// assert_double_equal has been introduced in cmocka 1.1.6 not available on most distribs yet
assert_float_equal(200e3, samplerate, 1e-12);
assert_float_equal(428e6, frequency, 1e-12);
assert_memory_equal(&ref_format, &format, 1);
assert_string_equal("2023-08-06T15:18:38", starttime);
assert_int_equal(-1, rffft_params_from_filename("gqrx_2023-08-06_15:18:38_428000000_200000_fc.raw", &samplerate, &frequency, &format, starttime));
}
// Test SDR Console filenames
void rffft_internal_parse_sdrconsole_filenames(void **state) {
double samplerate = 0;
double frequency = 0;
char format = '\0';
char starttime[] = "YYYY-mm-ddTHH:MM:SS.sss";
char ref_format = '\0';
ref_format = 'w';
assert_int_equal(0, rffft_params_from_filename("07-Aug-2023 181711.798 401.774MHz.wav", &samplerate, &frequency, &format, starttime));
// assert_double_equal has been introduced in cmocka 1.1.6 not available on most distribs yet
assert_float_equal(0, samplerate, 1e-12);
assert_float_equal(401.774e6, frequency, 1e-12);
assert_memory_equal(&ref_format, &format, 1);
assert_string_equal("2023-08-07T18:17:11.798", starttime);
assert_int_equal(-1, rffft_params_from_filename("07-Yol-2023 181711.798 401.774MHz.wav", &samplerate, &frequency, &format, starttime));
}
// Entry point to run all tests
int run_rffft_internal_tests() {
const struct CMUnitTest tests[] = {
cmocka_unit_test(rffft_internal_parse_satdump_filenames),
cmocka_unit_test(rffft_internal_parse_gqrx_filenames),
cmocka_unit_test(rffft_internal_parse_sdrconsole_filenames),
};
return cmocka_run_group_tests_name("rffft internal", tests, NULL, NULL);
}