Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/stdlib Don't use integer downcasts, use corre...



details:   https://anonhg.NetBSD.org/src/rev/f07495b93c8a
branches:  trunk
changeset: 793848:f07495b93c8a
user:      joerg <joerg%NetBSD.org@localhost>
date:      Thu Feb 27 17:25:28 2014 +0000

description:
Don't use integer downcasts, use correctly sized constants for each test.

diffstat:

 tests/lib/libc/stdlib/t_abs.c |  52 ++++++++++++++++++++++++++++--------------
 1 files changed, 35 insertions(+), 17 deletions(-)

diffs (131 lines):

diff -r a77b83bb12b4 -r f07495b93c8a tests/lib/libc/stdlib/t_abs.c
--- a/tests/lib/libc/stdlib/t_abs.c     Thu Feb 27 16:51:37 2014 +0000
+++ b/tests/lib/libc/stdlib/t_abs.c     Thu Feb 27 17:25:28 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_abs.c,v 1.1 2012/03/29 06:16:56 jruoho Exp $ */
+/* $NetBSD: t_abs.c,v 1.2 2014/02/27 17:25:28 joerg Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,18 +29,13 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_abs.c,v 1.1 2012/03/29 06:16:56 jruoho Exp $");
+__RCSID("$NetBSD: t_abs.c,v 1.2 2014/02/27 17:25:28 joerg Exp $");
 
 #include <atf-c.h>
 #include <inttypes.h>
 #include <limits.h>
 #include <stdlib.h>
 
-struct test {
-       int64_t val;
-       int64_t res;
-};
-
 ATF_TC(abs_basic);
 ATF_TC_HEAD(abs_basic, tc)
 {
@@ -49,7 +44,10 @@
 
 ATF_TC_BODY(abs_basic, tc)
 {
-       static const struct test table[] = {
+       static const struct {
+               int val;
+               int res;
+       } table[] = {
                { 0,            0               },
                { +0,           0               },
                { -0,           0               },
@@ -59,7 +57,7 @@
        };
 
        for (size_t i = 0; i < __arraycount(table); i++)
-               ATF_CHECK(abs(table[i].val) == (int)table[i].res);
+               ATF_CHECK(abs(table[i].val) == table[i].res);
 }
 
 ATF_TC(imaxabs_basic);
@@ -70,14 +68,23 @@
 
 ATF_TC_BODY(imaxabs_basic, tc)
 {
-       static const struct test table[] = {
+       static const struct {
+               intmax_t val;
+               intmax_t res;
+       } table[] = {
                { 0,            0               },
                { INT_MAX,      INT_MAX         },
                { -INT_MAX,     INT_MAX         },
+               { LONG_MAX,     LONG_MAX        },
+               { -LONG_MAX,    LONG_MAX        },
+               { LLONG_MAX,    LLONG_MAX       },
+               { -LLONG_MAX,   LLONG_MAX       },
+               { INT_MAX,      INT_MAX         },
+               { -INT_MAX,     INT_MAX         },
        };
 
        for (size_t i = 0; i < __arraycount(table); i++)
-               ATF_CHECK(imaxabs(table[i].val) == (intmax_t)table[i].res);
+               ATF_CHECK(imaxabs(table[i].val) == table[i].res);
 }
 
 ATF_TC(labs_basic);
@@ -88,18 +95,22 @@
 
 ATF_TC_BODY(labs_basic, tc)
 {
-       static const struct test table[] = {
+       static const struct {
+               long val;
+               long res;
+       } table[] = {
                { 0,            0               },
                { +0,           0               },
                { -0,           0               },
                { -1,           1               },
                { LONG_MAX,     LONG_MAX        },
                { -LONG_MAX,    LONG_MAX        },
-               { -0x100000000, 0x100000000     },
+               { INT_MAX,      INT_MAX         },
+               { -INT_MAX,     -INT_MAX        },
        };
 
        for (size_t i = 0; i < __arraycount(table); i++)
-               ATF_CHECK(labs(table[i].val) == (long int)table[i].res);
+               ATF_CHECK(labs(table[i].val) == table[i].res);
 }
 
 ATF_TC(llabs_basic);
@@ -110,18 +121,25 @@
 
 ATF_TC_BODY(llabs_basic, tc)
 {
-       static const struct test table[] = {
+       static const struct {
+               long long val;
+               long long res;
+       } table[] = {
                { 0,            0               },
                { +0,           0               },
                { -0,           0               },
                { -1,           1               },
+               { INT_MAX,      INT_MAX         },
+               { -INT_MAX,     INT_MAX         },
+               { LONG_MAX,     LONG_MAX        },
+               { -LONG_MAX,    LONG_MAX        },
                { LLONG_MAX,    LLONG_MAX       },
                { -LLONG_MAX,   LLONG_MAX       },
-               { -0x100000000, 0x100000000     },
+               { -0x100000000LL,       0x100000000LL   },
        };
 
        for (size_t i = 0; i < __arraycount(table); i++)
-               ATF_CHECK(llabs(table[i].val) == (long long int)table[i].res);
+               ATF_CHECK(llabs(table[i].val) == table[i].res);
 }
 
 ATF_TP_ADD_TCS(tp)



Home | Main Index | Thread Index | Old Index