1 /*- 2 * Copyright (c) 2023 Dag-Erling Smørgrav 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7 #include <limits.h> 8 #include <stdckdint.h> 9 10 #include <atf-c.h> 11 12 ATF_TC_WITHOUT_HEAD(ckd_add); 13 ATF_TC_BODY(ckd_add, tc) 14 { 15 int result; 16 17 ATF_CHECK(!ckd_add(&result, INT_MAX, 0)); 18 ATF_CHECK_EQ(INT_MAX, result); 19 ATF_CHECK(ckd_add(&result, INT_MAX, 1)); 20 ATF_CHECK_EQ(INT_MIN, result); 21 } 22 23 ATF_TC_WITHOUT_HEAD(ckd_sub); 24 ATF_TC_BODY(ckd_sub, tc) 25 { 26 int result; 27 28 ATF_CHECK(!ckd_sub(&result, INT_MIN, 0)); 29 ATF_CHECK_EQ(INT_MIN, result); 30 ATF_CHECK(ckd_sub(&result, INT_MIN, 1)); 31 ATF_CHECK_EQ(INT_MAX, result); 32 } 33 34 ATF_TC_WITHOUT_HEAD(ckd_mul); 35 ATF_TC_BODY(ckd_mul, tc) 36 { 37 int result; 38 39 ATF_CHECK(!ckd_mul(&result, INT_MAX / 2, 2)); 40 ATF_CHECK_EQ(INT_MAX - 1, result); 41 ATF_CHECK(ckd_mul(&result, INT_MAX / 2 + 1, 2)); 42 ATF_CHECK_EQ(INT_MIN, result); 43 } 44 45 ATF_TP_ADD_TCS(tp) 46 { 47 ATF_TP_ADD_TC(tp, ckd_add); 48 ATF_TP_ADD_TC(tp, ckd_sub); 49 ATF_TP_ADD_TC(tp, ckd_mul); 50 return (atf_no_error()); 51 52 } 53