X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/51004dcb01e06fef634b61be77ed73dd61cb6db9..249c4c5ea9376c24572daf9c2effa7484a282f14:/icuSources/test/cintltst/putiltst.c?ds=sidebyside diff --git a/icuSources/test/cintltst/putiltst.c b/icuSources/test/cintltst/putiltst.c index d6abc935..1c3e0730 100644 --- a/icuSources/test/cintltst/putiltst.c +++ b/icuSources/test/cintltst/putiltst.c @@ -1,6 +1,8 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /******************************************************************** * COPYRIGHT: - * Copyright (c) 1998-2012, International Business Machines Corporation and + * Copyright (c) 1998-2016, International Business Machines Corporation and * others. All Rights Reserved. ********************************************************************/ /* @@ -126,6 +128,20 @@ static void TestPUtilAPI(void){ log_err("ERROR: uprv_isInfinite failed.\n"); } + log_verbose("Testing the APIs uprv_add32_overflow and uprv_mul32_overflow\n"); + int32_t overflow_result; + doAssert(FALSE, uprv_add32_overflow(INT32_MAX - 2, 1, &overflow_result), "should not overflow"); + doAssert(INT32_MAX - 1, overflow_result, "should equal INT32_MAX - 1"); + doAssert(FALSE, uprv_add32_overflow(INT32_MAX - 2, 2, &overflow_result), "should not overflow"); + doAssert(INT32_MAX, overflow_result, "should equal exactly INT32_MAX"); + doAssert(TRUE, uprv_add32_overflow(INT32_MAX - 2, 3, &overflow_result), "should overflow"); + doAssert(FALSE, uprv_mul32_overflow(INT32_MAX / 5, 4, &overflow_result), "should not overflow"); + doAssert(INT32_MAX / 5 * 4, overflow_result, "should equal INT32_MAX / 5 * 4"); + doAssert(TRUE, uprv_mul32_overflow(INT32_MAX / 5, 6, &overflow_result), "should overflow"); + // Test on negative numbers: + doAssert(FALSE, uprv_add32_overflow(-3, -2, &overflow_result), "should not overflow"); + doAssert(-5, overflow_result, "should equal -5"); + #if 0 log_verbose("Testing the API uprv_digitsAfterDecimal()....\n"); doAssert(uprv_digitsAfterDecimal(value1), 3, "uprv_digitsAfterDecimal() failed."); @@ -565,7 +581,7 @@ static void toolutil_findBasename(void) "" }, }; - int32_t count=(sizeof(testCases)/sizeof(testCases[0])); + int32_t count=UPRV_LENGTHOF(testCases); int32_t i; @@ -661,7 +677,7 @@ static void toolutil_findDirname(void) "" } }; - int32_t count=(sizeof(testCases)/sizeof(testCases[0])); + int32_t count=UPRV_LENGTHOF(testCases); log_verbose("Testing findDirname()\n"); for(i=0;i