Debian Codegraph @

modules/lsp-runtime-lib/src/test/utest/fmt/sfz/parse.cpp

raw
1 /*
2 * Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2023 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 2 мар. 2023 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #include <lsp-plug.in/fmt/sfz/parse.h>
23 #include <lsp-plug.in/test-fw/helpers.h>
24 #include <lsp-plug.in/test-fw/utest.h>
25
26 UTEST_BEGIN("runtime.fmt.sfz", parse)
27
28 void check_bool(const char *text, bool value)
29 {
30 bool tmp;
31 printf("check_bool %s\n", text);
32 UTEST_ASSERT_MSG(
33 sfz::parse_bool(&tmp, text) == STATUS_OK,
34 "Failed parse boolean value text='%s'",
35 text);
36 UTEST_ASSERT_MSG(
37 tmp == value,
38 "Invalid boolean value text='%s', value=%s, expected=%s",
39 text, (tmp) ? "true" : "false", (value) ? "true" : "false");
40 }
41
42 void check_int(const char *text, ssize_t value)
43 {
44 ssize_t tmp;
45 printf("check_int %s\n", text);
46 UTEST_ASSERT_MSG(
47 sfz::parse_int(&tmp, text) == STATUS_OK,
48 "Failed parse integer value text='%s'",
49 text);
50 UTEST_ASSERT_MSG(
51 tmp == value,
52 "Invalid integer value text='%s', value=%d, expected=%d",
53 text, int(tmp), int(value));
54 }
55
56 void check_float(const char *text, float value)
57 {
58 float tmp;
59 printf("check_float %s\n", text);
60 UTEST_ASSERT_MSG(
61 sfz::parse_float(&tmp, text) == STATUS_OK,
62 "Failed parse integer value text='%s'",
63 text);
64 UTEST_ASSERT_MSG(
65 float_equals_adaptive(tmp, value),
66 "Invalid integer value text='%s', value=%f, expected=%f",
67 text, tmp, value);
68 }
69
70 void check_note(const char *text, ssize_t value)
71 {
72 ssize_t tmp;
73 printf("check_note %s\n", text);
74 UTEST_ASSERT_MSG(
75 sfz::parse_note(&tmp, text) == STATUS_OK,
76 "Failed parse note value text='%s'",
77 text);
78 UTEST_ASSERT_MSG(
79 tmp == value,
80 "Invalid note value text='%s', value=%d, expected=%d",
81 text, int(tmp), int(value));
82 }
83
84 UTEST_MAIN
85 {
86 // Check boolean parsing
87 check_bool("t", true);
88 check_bool("f", false);
89 check_bool("on", true);
90 check_bool("off", false);
91 check_bool("yes", true);
92 check_bool("no", false);
93 check_bool("true", true);
94 check_bool("false", false);
95
96 // Check integer parsing
97 check_int("0", 0);
98 check_int("123", 123);
99 check_int("-12345", -12345);
100
101 // Check floating-point parsing
102 check_float("0", 0.0f);
103 check_float("0.0", 0.0f);
104 check_float("440.0", 440.0f);
105 check_float("-48000.0", -48000.0f);
106 check_float("12.34", 12.34f);
107
108 // Check note parsing
109 check_note("35", 35);
110 check_note("b1", 35);
111 check_note("B1", 35);
112 check_note("B#1", 36);
113 check_note("B##1", 37);
114 check_note("Bb1", 34);
115 check_note("Bbb1", 33);
116 check_note("A-1", 9);
117 }
118
119 UTEST_END
120
121
122
123