1
0
Fork 0

Codechange: add unit test against enum over optimisation

pull/13379/head
Rubidium 2025-01-25 08:33:26 +01:00 committed by rubidium42
parent 5839ee3be3
commit 5b4c5632ba
2 changed files with 32 additions and 0 deletions

View File

@ -1,5 +1,6 @@
add_test_files(
bitmath_func.cpp
enum_over_optimisation.cpp
landscape_partial_pixel_z.cpp
math_func.cpp
mock_environment.h

View File

@ -0,0 +1,31 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file enum_over_optimisation.cpp Test whether we do not trigger an over optimisation of enums.
*
* For more details, see http://gcc.gnu.org/PR43680 and PR#5246.
*/
#include "../stdafx.h"
#include "../3rdparty/catch2/catch.hpp"
enum TestEnum : int8_t {
ZERO,
ONE,
TWO
};
TEST_CASE("EnumOverOptimisation_BoundsCheck")
{
TestEnum negative_one = static_cast<TestEnum>(-1);
CHECK(negative_one < ZERO);
TestEnum three = static_cast<TestEnum>(3);
CHECK(TWO < three);
}