blob: ae59675b4939d70c0c60f5a4b1d3df64eaf51508 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <limits>
#include <zxtest/zxtest.h>
namespace {
// Global to prevent "unused variable" compiler error, volatile to make sure
// the compiler doesn't optimize out any operations.
volatile int c = 0;
TEST(IntegerTest, NormalMath) {
volatile int a = 5;
volatile int b = 6;
c = a + b;
EXPECT_EQ(11, c);
}
TEST(IntegerTest, SignedOverflow) {
ASSERT_DEATH([] {
volatile int a = std::numeric_limits<int>::max();
volatile int b = 6;
c = a + b; // crash occurs here
});
}
TEST(IntegerTest, SignedUnderflow) {
ASSERT_DEATH([] {
volatile int a = std::numeric_limits<int>::min();
volatile int b = -6;
c = a + b; // crash occurs here
});
}
TEST(IntegerTest, DivideByZero) {
ASSERT_DEATH([] {
volatile int a = 5;
volatile int b = 0;
c = a / b; // crash occurs here
});
}
} // namespace