Skip to content

Commit c911599

Browse files
committed
Add sr_voltage_string() unit tests.
1 parent d2391b5 commit c911599

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/strutil.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ static void test_rational(const char *input, struct sr_rational expected)
5656
input, rational.p, rational.q);
5757
}
5858

59+
static void test_voltage(uint64_t v_p, uint64_t v_q, const char *expected)
60+
{
61+
char *s;
62+
63+
s = sr_voltage_string(v_p, v_q);
64+
fail_unless(s != NULL);
65+
fail_unless(!strcmp(s, expected),
66+
"Invalid result for '%s': %s.", expected, s);
67+
g_free(s);
68+
}
69+
5970
/*
6071
* Check various inputs for sr_samplerate_string():
6172
*
@@ -214,6 +225,19 @@ START_TEST(test_ghz_period)
214225
}
215226
END_TEST
216227

228+
START_TEST(test_volt)
229+
{
230+
test_voltage(34, 1, "34V");
231+
test_voltage(34, 2, "17V");
232+
test_voltage(1, 1, "1V");
233+
test_voltage(1, 5, "0.2V");
234+
test_voltage(200, 1000, "200mV");
235+
test_voltage(1, 72, "0.0138889V");
236+
test_voltage(1, 388, "0.00257732V");
237+
test_voltage(10, 1000, "10mV");
238+
}
239+
END_TEST
240+
217241
START_TEST(test_integral)
218242
{
219243
test_rational("1", (struct sr_rational){1, 1});
@@ -264,6 +288,7 @@ Suite *suite_strutil(void)
264288
tcase_add_test(tc, test_ghz);
265289
tcase_add_test(tc, test_hz_period);
266290
tcase_add_test(tc, test_ghz_period);
291+
tcase_add_test(tc, test_volt);
267292
tcase_add_test(tc, test_integral);
268293
tcase_add_test(tc, test_fractional);
269294
tcase_add_test(tc, test_exponent);

0 commit comments

Comments
 (0)