diff options
Diffstat (limited to 'test/test-misc.c')
-rw-r--r-- | test/test-misc.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/test-misc.c b/test/test-misc.c index 3f4b229..5101dcf 100644 --- a/test/test-misc.c +++ b/test/test-misc.c @@ -1001,6 +1001,48 @@ START_TEST(calibration_prop_parser) } END_TEST +struct parser_test_pressure_range { + char *tag; + bool success; + int hi, lo; +}; + +START_TEST(pressure_range_prop_parser) +{ + struct parser_test_pressure_range tests[] = { + { "10:8", true, 10, 8 }, + { "100:-1", true, 100, -1 }, + { "-203813:-502023", true, -203813, -502023 }, + { "238492:28210", true, 238492, 28210 }, + { "none", true, 0, 0 }, + { "0:0", false, 0, 0 }, + { "", false, 0, 0 }, + { "abcd", false, 0, 0 }, + { "10:30:10", false, 0, 0 }, + { NULL, false, 0, 0 } + }; + int i; + int hi, lo; + bool success; + + for (i = 0; tests[i].tag != NULL; i++) { + hi = lo = 0xad; + success = parse_pressure_range_property(tests[i].tag, &hi, &lo); + ck_assert(success == tests[i].success); + if (success) { + ck_assert_int_eq(hi, tests[i].hi); + ck_assert_int_eq(lo, tests[i].lo); + } else { + ck_assert_int_eq(hi, 0xad); + ck_assert_int_eq(lo, 0xad); + } + } + + success = parse_pressure_range_property(NULL, NULL, NULL); + ck_assert(success == false); +} +END_TEST + START_TEST(time_conversion) { ck_assert_int_eq(us(10), 10); @@ -1275,6 +1317,7 @@ litest_setup_tests_misc(void) litest_add_no_device("misc:parser", dimension_prop_parser); litest_add_no_device("misc:parser", reliability_prop_parser); litest_add_no_device("misc:parser", calibration_prop_parser); + litest_add_no_device("misc:parser", pressure_range_prop_parser); litest_add_no_device("misc:parser", safe_atoi_test); litest_add_no_device("misc:parser", safe_atod_test); litest_add_no_device("misc:parser", strsplit_test); |