Googletest export
Rolling forward IsNan() matcher with fixes in test for -Wconversion issues. Use std::nanf and std::nanl where appropriate. PiperOrigin-RevId: 275523003
This commit is contained in:
		
				
					committed by
					
						
						Gennadiy Civil
					
				
			
			
				
	
			
			
			
						parent
						
							f966ed1581
						
					
				
				
					commit
					011c4e23d5
				
			@@ -42,8 +42,8 @@
 | 
			
		||||
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
 | 
			
		||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
 | 
			
		||||
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <cmath>
 | 
			
		||||
#include <initializer_list>
 | 
			
		||||
#include <iterator>
 | 
			
		||||
#include <limits>
 | 
			
		||||
@@ -54,6 +54,7 @@
 | 
			
		||||
#include <type_traits>
 | 
			
		||||
#include <utility>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "gmock/internal/gmock-internal-utils.h"
 | 
			
		||||
#include "gmock/internal/gmock-port.h"
 | 
			
		||||
#include "gtest/gtest.h"
 | 
			
		||||
@@ -1349,6 +1350,22 @@ MakePredicateFormatterFromMatcher(M matcher) {
 | 
			
		||||
  return PredicateFormatterFromMatcher<M>(std::move(matcher));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Implements the polymorphic IsNan() matcher, which matches any floating type
 | 
			
		||||
// value that is Nan.
 | 
			
		||||
class IsNanMatcher {
 | 
			
		||||
 public:
 | 
			
		||||
  template <typename FloatType>
 | 
			
		||||
  bool MatchAndExplain(const FloatType& f,
 | 
			
		||||
                       MatchResultListener* /* listener */) const {
 | 
			
		||||
    return (::std::isnan)(f);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void DescribeTo(::std::ostream* os) const { *os << "is NaN"; }
 | 
			
		||||
  void DescribeNegationTo(::std::ostream* os) const {
 | 
			
		||||
    *os << "isn't NaN";
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Implements the polymorphic floating point equality matcher, which matches
 | 
			
		||||
// two float values using ULP-based approximation or, optionally, a
 | 
			
		||||
// user-specified epsilon.  The template is meant to be instantiated with
 | 
			
		||||
@@ -1409,7 +1426,7 @@ class FloatingEqMatcher {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        const FloatType diff = value - expected_;
 | 
			
		||||
        if (fabs(diff) <= max_abs_error_) {
 | 
			
		||||
        if (::std::fabs(diff) <= max_abs_error_) {
 | 
			
		||||
          return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -3626,6 +3643,11 @@ inline internal::RefMatcher<T&> Ref(T& x) {  // NOLINT
 | 
			
		||||
  return internal::RefMatcher<T&>(x);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Creates a polymorphic matcher that matches any NaN floating point.
 | 
			
		||||
inline PolymorphicMatcher<internal::IsNanMatcher> IsNan() {
 | 
			
		||||
  return MakePolymorphicMatcher(internal::IsNanMatcher());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Creates a matcher that matches any double argument approximately
 | 
			
		||||
// equal to rhs, where two NANs are considered unequal.
 | 
			
		||||
inline internal::FloatingEqMatcher<double> DoubleEq(double rhs) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user