// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "core/common/safeint.h" #include #include #include #include "gtest/gtest.h" namespace onnxruntime::test { static_assert(is_supported_integer_v); static_assert(is_supported_integer_v); static_assert(!is_supported_integer_v); TEST(SafeIntTest, SafeMulMultipliesOperands) { EXPECT_EQ(SafeMul(size_t{2}, 3U), size_t{6}); EXPECT_EQ(SafeMul(-2, 3, 4), -24); } TEST(SafeIntTest, SafeMulHandlesSameVariableOperands) { const int value = 7; EXPECT_EQ(SafeMul(value, value), 49); } #ifndef ORT_NO_EXCEPTIONS TEST(SafeIntTest, SafeMulThrowsOnInitialCastOverflow) { EXPECT_THROW((void)SafeMul(-1, 2), OnnxRuntimeException); } TEST(SafeIntTest, SafeMulThrowsOnMultiplyOverflow) { EXPECT_THROW((void)SafeMul(std::numeric_limits::max(), 2), OnnxRuntimeException); } #endif } // namespace onnxruntime::test