mirror of
https://github.com/google/googletest.git
synced 2026-10-28 18:07:18 +08:00
Remove BiggestInt and just use intmax_t
PiperOrigin-RevId: 974011716 Change-Id: I5dacc23eae25b749ad6c77b10b9bc0d75fac11c5
This commit is contained in:
parent
36ba75f0ad
commit
d94a7326e9
@ -104,6 +104,8 @@
|
||||
#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||
#define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <any>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
@ -279,15 +281,13 @@ struct ProtobufPrinter {
|
||||
|
||||
struct ConvertibleToIntegerPrinter {
|
||||
// Since T has no << operator or PrintTo() but can be implicitly
|
||||
// converted to BiggestInt, we print it as a BiggestInt.
|
||||
// converted to intmax_t, we print it as an intmax_t.
|
||||
//
|
||||
// Most likely T is an enum type (either named or unnamed), in which
|
||||
// case printing it as an integer is the desired behavior. In case
|
||||
// T is not an enum, printing it as an integer is the best we can do
|
||||
// given that it has no user-defined printer.
|
||||
static void PrintValue(internal::BiggestInt value, ::std::ostream* os) {
|
||||
*os << value;
|
||||
}
|
||||
static void PrintValue(intmax_t value, ::std::ostream* os) { *os << value; }
|
||||
};
|
||||
|
||||
struct ConvertibleToStringViewPrinter {
|
||||
@ -347,7 +347,7 @@ struct FindFirstPrinter<
|
||||
// - Print object pointers.
|
||||
// - Print protocol buffers.
|
||||
// - Use the stream operator, if available.
|
||||
// - Print types convertible to BiggestInt.
|
||||
// - Print types convertible to intmax_t.
|
||||
// - Print types convertible to StringView, if available.
|
||||
// - Fallback to printing the raw bytes of the object.
|
||||
template <typename T>
|
||||
|
||||
@ -1419,14 +1419,14 @@ class [[nodiscard]] EqHelper {
|
||||
}
|
||||
|
||||
// With this overloaded version, we allow anonymous enums to be used
|
||||
// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
|
||||
// enums can be implicitly cast to BiggestInt.
|
||||
// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums can be
|
||||
// implicitly cast to intmax_t.
|
||||
//
|
||||
// Even though its body looks the same as the above version, we
|
||||
// cannot merge the two, as it will make anonymous enums unhappy.
|
||||
static AssertionResult Compare(const char* lhs_expression,
|
||||
const char* rhs_expression, BiggestInt lhs,
|
||||
BiggestInt rhs) {
|
||||
const char* rhs_expression, intmax_t lhs,
|
||||
intmax_t rhs) {
|
||||
return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
|
||||
}
|
||||
|
||||
|
||||
@ -236,7 +236,6 @@
|
||||
// Integer types:
|
||||
// TypeWithSize - maps an integer to a int type.
|
||||
// TimeInMillis - integers of known sizes.
|
||||
// BiggestInt - the biggest signed integer type.
|
||||
//
|
||||
// Command-line utilities:
|
||||
// GetInjectableArgvs() - returns the command line as a vector of strings.
|
||||
@ -2303,14 +2302,6 @@ GTEST_DISABLE_DEPRECATED_POP_()
|
||||
#define GTEST_SNPRINTF_ snprintf
|
||||
#endif
|
||||
|
||||
// The biggest signed integer type the compiler supports.
|
||||
//
|
||||
// long long is guaranteed to be at least 64-bits in C++11.
|
||||
using BiggestInt = long long; // NOLINT
|
||||
|
||||
// The maximum number a BiggestInt can represent.
|
||||
constexpr BiggestInt kMaxBiggestInt = (std::numeric_limits<BiggestInt>::max)();
|
||||
|
||||
// This template class serves as a compile-time function from size to
|
||||
// type. It maps a size in bytes to a primitive type with that
|
||||
// size. e.g.
|
||||
|
||||
@ -95,10 +95,12 @@ void PrintTo(EnumWithPrintTo e, std::ostream* os) {
|
||||
*os << (e == kEWPT1 ? "kEWPT1" : "invalid");
|
||||
}
|
||||
|
||||
// A class implicitly convertible to BiggestInt.
|
||||
// A class implicitly convertible to intmax_t.
|
||||
class BiggestIntConvertible {
|
||||
public:
|
||||
operator ::testing::internal::BiggestInt() const { return 42; }
|
||||
operator intmax_t() const { // NOLINT(google-explicit-constructor)
|
||||
return 42;
|
||||
}
|
||||
};
|
||||
|
||||
// A parent class with two child classes. The parent and one of the kids have
|
||||
@ -356,7 +358,7 @@ TEST(PrintEnumTest, EnumWithPrintTo) {
|
||||
TEST(PrintClassTest, AbslStringify) { EXPECT_EQ("(10, 20)", Print(Point())); }
|
||||
#endif
|
||||
|
||||
// Tests printing a class implicitly convertible to BiggestInt.
|
||||
// Tests printing a class implicitly convertible to intmax_t.
|
||||
|
||||
TEST(PrintClassTest, BiggestIntConvertible) {
|
||||
EXPECT_EQ("42", Print(BiggestIntConvertible()));
|
||||
@ -773,7 +775,7 @@ TEST(PrintPointerTest, NonMemberFunctionPointer) {
|
||||
// pointers to objects, and some compilers (e.g. GCC 3.4) enforce
|
||||
// this limitation.
|
||||
EXPECT_EQ(PrintPointer(reinterpret_cast<const void*>(
|
||||
reinterpret_cast<internal::BiggestInt>(&MyFunction))),
|
||||
reinterpret_cast<intmax_t>(&MyFunction))),
|
||||
Print(&MyFunction));
|
||||
int (*p)(bool) = NULL; // NOLINT
|
||||
EXPECT_EQ("NULL", Print(p));
|
||||
@ -1474,8 +1476,8 @@ TEST(PrintReferenceTest, HandlesFunctionPointer) {
|
||||
// standard disallows casting between pointers to functions and
|
||||
// pointers to objects, and some compilers (e.g. GCC 3.4) enforce
|
||||
// this limitation.
|
||||
const std::string fp_string = PrintPointer(reinterpret_cast<const void*>(
|
||||
reinterpret_cast<internal::BiggestInt>(fp)));
|
||||
const std::string fp_string = PrintPointer(
|
||||
reinterpret_cast<const void*>(reinterpret_cast<intmax_t>(fp)));
|
||||
EXPECT_EQ("@" + fp_pointer_string + " " + fp_string, PrintByRef(fp));
|
||||
}
|
||||
|
||||
|
||||
@ -34,6 +34,7 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
|
||||
// Verifies that the command line flag variables can be accessed in
|
||||
// code once "gtest.h" has been #included.
|
||||
@ -4029,7 +4030,7 @@ enum {
|
||||
// On Linux, kCaseB and kCaseA have the same value when truncated to
|
||||
// int size. We want to test whether this will confuse the
|
||||
// assertions.
|
||||
kCaseB = testing::internal::kMaxBiggestInt,
|
||||
kCaseB = (std::numeric_limits<intmax_t>::max)(),
|
||||
|
||||
#else
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user