X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=tests%2Fstrutil.c;h=ec2233329b769c5eecc9597bdeb6d8e7564f4694;hp=14240f049f1f4c181d74cbe820803cb7d2f00072;hb=2622b4297fd4cc4bed5c06bb6ae0aaa8b40e0ece;hpb=83a05ca9b3113b3c57658dead05a3bcd32713851 diff --git a/tests/strutil.c b/tests/strutil.c index 14240f04..ec223332 100644 --- a/tests/strutil.c +++ b/tests/strutil.c @@ -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; @@ -145,7 +154,7 @@ START_TEST(test_locale) fprintf(stderr, "Old locale = %s\n", old_locale); /* Copy the name so it won’t be clobbered by setlocale. */ saved_locale = g_strdup(old_locale); - ck_assert_msg(saved_locale != NULL); + ck_assert(saved_locale != NULL); #ifdef _WIN32 /* @@ -388,6 +397,16 @@ START_TEST(test_fractional) test_rational("+.1", (struct sr_rational){1, 10}); test_rational("-0.1", (struct sr_rational){-1, 10}); test_rational("-.1", (struct sr_rational){-1, 10}); + test_rational(".1", (struct sr_rational){1, 10}); + test_rational(".123", (struct sr_rational){123, 1000}); + test_rational("1.", (struct sr_rational){1, 1}); + test_rational("123.", (struct sr_rational){123, 1}); + 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