mirror of https://github.com/OpenTTD/OpenTTD
Codechange: add unit test against enum over optimisation
parent
5839ee3be3
commit
5b4c5632ba
|
@ -1,5 +1,6 @@
|
||||||
add_test_files(
|
add_test_files(
|
||||||
bitmath_func.cpp
|
bitmath_func.cpp
|
||||||
|
enum_over_optimisation.cpp
|
||||||
landscape_partial_pixel_z.cpp
|
landscape_partial_pixel_z.cpp
|
||||||
math_func.cpp
|
math_func.cpp
|
||||||
mock_environment.h
|
mock_environment.h
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue