/* * * Copyright (C) 2014-2018, OFFIS e.V. * All rights reserved. See COPYRIGHT file for details. * * This software and supporting documentation were developed by * * OFFIS e.V. * R&D Division Health * Escherweg 2 * D-26121 Oldenburg, Germany * * * Module: ofstd * * Author: Jan Schlamelcher * * Purpose: unit test for OFnumeric_limits * */ #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ #define OFTEST_OFSTD_ONLY #include "dcmtk/ofstd/oftest.h" #include "dcmtk/ofstd/ofdiag.h" #include "dcmtk/ofstd/oflimits.h" #include "dcmtk/ofstd/ofstd.h" #include "dcmtk/ofstd/oftraits.h" #include "dcmtk/ofstd/ofmath.h" // for isinf and isnan // On some platforms, such as OpenIndiana, isinf is defined as a macro, // and that inteferes with the OFMath function of the same name. #ifdef isinf #undef isinf #endif #include DCMTK_DIAGNOSTIC_PUSH #include DCMTK_DIAGNOSTIC_IGNORE_OVERFLOW #include DCMTK_DIAGNOSTIC_IGNORE_IMPLICIT_CONVERSION template static void checkMinMax() { volatile T max_plus_one( OFnumeric_limits::max() ); volatile T lowest_minus_one( OFnumeric_limits::lowest() ); ++max_plus_one; --lowest_minus_one; OFCHECK ( OFnumeric_limits::max() >= max_plus_one || ( OFnumeric_limits::has_infinity && OFMath::isinf( max_plus_one ) ) ); OFCHECK ( OFnumeric_limits::lowest() <= lowest_minus_one || ( OFnumeric_limits::has_infinity && OFMath::isinf( lowest_minus_one ) ) ); OFCHECK( ( OFnumeric_limits::lowest() == OFnumeric_limits::min() ) || !OFnumeric_limits::is_integer ); } #include DCMTK_DIAGNOSTIC_POP template static OFTypename OFenable_if::has_quiet_NaN>::type checkNaN() { (OFMath::isnan)( OFnumeric_limits::quiet_NaN() ); } template static OFTypename OFenable_if::has_quiet_NaN>::type checkNaN() { } template static OFTypename OFenable_if::has_infinity>::type checkInfinity() { (OFMath::isinf)( OFnumeric_limits::infinity() ); } template static OFTypename OFenable_if::has_infinity>::type checkInfinity() { } #include DCMTK_DIAGNOSTIC_PUSH #include DCMTK_DIAGNOSTIC_IGNORE_OVERFLOW template static void checkLimits() { checkMinMax(); checkNaN(); checkInfinity(); // Only test overflow property if 'is_modulo' expands to OFTrue, since OFFalse may // also mean 'undefined'. if( OFnumeric_limits::is_modulo ) OFCHECK( OFstatic_cast( T, OFnumeric_limits::max() + 1 ) == OFnumeric_limits::min() ); } #include DCMTK_DIAGNOSTIC_POP OFTEST(ofstd_limits) { checkLimits(); checkLimits(); checkLimits(); checkLimits(); checkLimits(); checkLimits(); checkLimits(); checkLimits(); checkLimits(); checkLimits(); checkLimits(); }