xref: /llvm-project/libc/test/include/stdckdint_test.cpp (revision 1dbc98294adc06e409b1e0d44252826857ac2ec6)
1 //===-- Unittests for stdckdint -------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "test/UnitTest/Test.h"
10 
11 #include "include/llvm-libc-macros/stdckdint-macros.h"
12 
13 TEST(LlvmLibcStdCkdIntTest, Add) {
14   int result;
15   ASSERT_FALSE(ckd_add(&result, 1, 2));
16   ASSERT_EQ(result, 3);
17   ASSERT_TRUE(ckd_add(&result, INT_MAX, 1));
18 }
19 
20 TEST(LlvmLibcStdCkdIntTest, Sub) {
21   int result;
22   ASSERT_FALSE(ckd_sub(&result, 3, 2));
23   ASSERT_EQ(result, 1);
24   ASSERT_TRUE(ckd_sub(&result, INT_MIN, 1));
25 }
26 
27 TEST(LlvmLibcStdCkdIntTest, Mul) {
28   int result;
29   ASSERT_FALSE(ckd_mul(&result, 2, 3));
30   ASSERT_EQ(result, 6);
31   ASSERT_TRUE(ckd_mul(&result, INT_MAX, 2));
32 }
33