From: Marcus Tomlinson Date: Sun, 18 Oct 2020 08:33:19 +0000 (+0100) Subject: Add safer float comparisons to bridgetest equals() X-Git-Tag: archive/raspbian/1%7.0.2-4+rpi1^2~8 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=484e0f6e1fc89ab56b7ed91184d51be93bdd5076;p=libreoffice.git Add safer float comparisons to bridgetest equals() Bug-Ubuntu: https://launchpad.net/bugs/1832360 Gbp-Pq: Name fix-flaky-bridgetest.diff --- diff --git a/testtools/source/bridgetest/bridgetest.cxx b/testtools/source/bridgetest/bridgetest.cxx index 5ce8a687d5f..8a9f00af432 100644 --- a/testtools/source/bridgetest/bridgetest.cxx +++ b/testtools/source/bridgetest/bridgetest.cxx @@ -54,6 +54,7 @@ #include "currentcontextchecker.hxx" #include "multi.hxx" #include +#include using namespace osl; using namespace cppu; @@ -122,6 +123,9 @@ public: static bool equals( const TestElement & rData1, const TestElement & rData2 ) { + const float epsilon_f = 0.00001f; + const double epsilon_d = 0.000000000001; + check( rData1.Bool == rData2.Bool, "### bool does not match!" ); check( rData1.Char == rData2.Char, "### char does not match!" ); check( rData1.Byte == rData2.Byte, "### byte does not match!" ); @@ -131,8 +135,8 @@ static bool equals( const TestElement & rData1, const TestElement & rData2 ) check( rData1.ULong == rData2.ULong, "### unsigned long does not match!" ); check( rData1.Hyper == rData2.Hyper, "### hyper does not match!" ); check( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" ); - check( rData1.Float == rData2.Float, "### float does not match!" ); - check( rData1.Double == rData2.Double, "### double does not match!" ); + check( fabs( rData1.Float - rData2.Float ) < epsilon_f, "### float does not match!" ); + check( fabs( rData1.Double - rData2.Double ) < epsilon_d, "### double does not match!" ); check( rData1.Enum == rData2.Enum, "### enum does not match!" ); check( rData1.String == rData2.String, "### string does not match!" ); check( rData1.Interface == rData2.Interface, "### interface does not match!" ); @@ -147,8 +151,8 @@ static bool equals( const TestElement & rData1, const TestElement & rData2 ) rData1.ULong == rData2.ULong && rData1.Hyper == rData2.Hyper && rData1.UHyper == rData2.UHyper && - rData1.Float == rData2.Float && - rData1.Double == rData2.Double && + fabs( rData1.Float - rData2.Float ) < epsilon_f && + fabs( rData1.Double - rData2.Double ) < epsilon_d && rData1.Enum == rData2.Enum && rData1.String == rData2.String && rData1.Interface == rData2.Interface &&