xref: /llvm-project/libc/test/include/stdckdint_test.cpp (revision 1dbc98294adc06e409b1e0d44252826857ac2ec6)
196c5b8cbSSchrodinger ZHU Yifan //===-- Unittests for stdckdint -------------------------------------------===//
296c5b8cbSSchrodinger ZHU Yifan //
396c5b8cbSSchrodinger ZHU Yifan // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
496c5b8cbSSchrodinger ZHU Yifan // See https://llvm.org/LICENSE.txt for license information.
5*1dbc9829SRoland McGrath // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
696c5b8cbSSchrodinger ZHU Yifan //
796c5b8cbSSchrodinger ZHU Yifan //===----------------------------------------------------------------------===//
896c5b8cbSSchrodinger ZHU Yifan 
996c5b8cbSSchrodinger ZHU Yifan #include "test/UnitTest/Test.h"
1096c5b8cbSSchrodinger ZHU Yifan 
1173aab2f6Slntue #include "include/llvm-libc-macros/stdckdint-macros.h"
1296c5b8cbSSchrodinger ZHU Yifan 
1396c5b8cbSSchrodinger ZHU Yifan TEST(LlvmLibcStdCkdIntTest, Add) {
1496c5b8cbSSchrodinger ZHU Yifan   int result;
1596c5b8cbSSchrodinger ZHU Yifan   ASSERT_FALSE(ckd_add(&result, 1, 2));
1696c5b8cbSSchrodinger ZHU Yifan   ASSERT_EQ(result, 3);
1796c5b8cbSSchrodinger ZHU Yifan   ASSERT_TRUE(ckd_add(&result, INT_MAX, 1));
1896c5b8cbSSchrodinger ZHU Yifan }
1996c5b8cbSSchrodinger ZHU Yifan 
2096c5b8cbSSchrodinger ZHU Yifan TEST(LlvmLibcStdCkdIntTest, Sub) {
2196c5b8cbSSchrodinger ZHU Yifan   int result;
2296c5b8cbSSchrodinger ZHU Yifan   ASSERT_FALSE(ckd_sub(&result, 3, 2));
2396c5b8cbSSchrodinger ZHU Yifan   ASSERT_EQ(result, 1);
2496c5b8cbSSchrodinger ZHU Yifan   ASSERT_TRUE(ckd_sub(&result, INT_MIN, 1));
2596c5b8cbSSchrodinger ZHU Yifan }
2696c5b8cbSSchrodinger ZHU Yifan 
2796c5b8cbSSchrodinger ZHU Yifan TEST(LlvmLibcStdCkdIntTest, Mul) {
2896c5b8cbSSchrodinger ZHU Yifan   int result;
2996c5b8cbSSchrodinger ZHU Yifan   ASSERT_FALSE(ckd_mul(&result, 2, 3));
3096c5b8cbSSchrodinger ZHU Yifan   ASSERT_EQ(result, 6);
3196c5b8cbSSchrodinger ZHU Yifan   ASSERT_TRUE(ckd_mul(&result, INT_MAX, 2));
3296c5b8cbSSchrodinger ZHU Yifan }
33