From: Szabolcs Nagy Date: Mon, 13 Oct 2014 08:41:14 +0000 (+0200) Subject: add strverscmp tests from the manual, bug found by jianzhong.huang X-Git-Url: http://nsz.repo.hu/git/?p=libc-test;a=commitdiff_plain;h=da2b7d64ac5693bc2a3dbfd1138972afae1466bc add strverscmp tests from the manual, bug found by jianzhong.huang --- diff --git a/src/regression/strverscmp.c b/src/regression/strverscmp.c new file mode 100644 index 0000000..a4daa26 --- /dev/null +++ b/src/regression/strverscmp.c @@ -0,0 +1,26 @@ +// leading zero handling according to the manual +#define _GNU_SOURCE +#include +#include "test.h" + +#define ASSERT(x) ((x) || (t_error(#x " failed\n"),0)) + +int main() +{ + ASSERT(strverscmp("", "") == 0); + ASSERT(strverscmp("a", "a") == 0); + ASSERT(strverscmp("a", "b") < 0); + ASSERT(strverscmp("b", "a") > 0); + ASSERT(strverscmp("000", "00") < 0); + ASSERT(strverscmp("00", "000") > 0); + ASSERT(strverscmp("a0", "a") > 0); + ASSERT(strverscmp("00", "01") < 0); + ASSERT(strverscmp("01", "010") < 0); + ASSERT(strverscmp("010", "09") < 0); + ASSERT(strverscmp("09", "0") < 0); + ASSERT(strverscmp("9", "10") < 0); + ASSERT(strverscmp("0a", "0") > 0); + ASSERT(strverscmp("foobar-1.1.2", "foobar-1.1.3") < 0); + ASSERT(strverscmp("foobar-1.1.2", "foobar-1.01.3") > 0); + return t_status; +}