]> sigrok.org Git - libsigrok.git/commitdiff
tests: add (negative) "." test case for rational conversion
authorGerhard Sittig <redacted>
Thu, 19 Jul 2018 19:45:10 +0000 (21:45 +0200)
committerUwe Hermann <redacted>
Sun, 22 Jul 2018 14:36:15 +0000 (16:36 +0200)
A naive implementation of the parse rational conversion helper could
have accepted invalid input. Check for the expected conversion failure.

tests/strutil.c

index 82856f1dd4a4d8e719bc0c5b5b9326fa6334a2a7..fca70eaaee36ef270d6725376391add9715197a2 100644 (file)
@@ -125,6 +125,15 @@ static void test_rational(const char *input, struct sr_rational expected)
                    input, rational.p, rational.q);
 }
 
+static void test_rational_fail(const char *input)
+{
+       int ret;
+       struct sr_rational rational;
+
+       ret = sr_parse_rational(input, &rational);
+       fail_unless(ret != SR_OK, "Unexpected success for '%s'.", input);
+}
+
 static void test_voltage(uint64_t v_p, uint64_t v_q, const char *expected)
 {
        char *s;
@@ -395,6 +404,9 @@ START_TEST(test_fractional)
        test_rational("-.1", (struct sr_rational){-1, 10});
        test_rational(" .1", (struct sr_rational){1, 10});
        test_rational("+.1", (struct sr_rational){1, 10});
+       test_rational_fail(".");
+       test_rational_fail(".e");
+       test_rational_fail(".e1");
 }
 END_TEST