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_
|
#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||||
#define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
#define GOOGLETEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <any>
|
#include <any>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@ -279,15 +281,13 @@ struct ProtobufPrinter {
|
|||||||
|
|
||||||
struct ConvertibleToIntegerPrinter {
|
struct ConvertibleToIntegerPrinter {
|
||||||
// Since T has no << operator or PrintTo() but can be implicitly
|
// 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
|
// 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
|
// 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
|
// T is not an enum, printing it as an integer is the best we can do
|
||||||
// given that it has no user-defined printer.
|
// given that it has no user-defined printer.
|
||||||
static void PrintValue(internal::BiggestInt value, ::std::ostream* os) {
|
static void PrintValue(intmax_t value, ::std::ostream* os) { *os << value; }
|
||||||
*os << value;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ConvertibleToStringViewPrinter {
|
struct ConvertibleToStringViewPrinter {
|
||||||
@ -347,7 +347,7 @@ struct FindFirstPrinter<
|
|||||||
// - Print object pointers.
|
// - Print object pointers.
|
||||||
// - Print protocol buffers.
|
// - Print protocol buffers.
|
||||||
// - Use the stream operator, if available.
|
// - Use the stream operator, if available.
|
||||||
// - Print types convertible to BiggestInt.
|
// - Print types convertible to intmax_t.
|
||||||
// - Print types convertible to StringView, if available.
|
// - Print types convertible to StringView, if available.
|
||||||
// - Fallback to printing the raw bytes of the object.
|
// - Fallback to printing the raw bytes of the object.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
@ -1419,14 +1419,14 @@ class [[nodiscard]] EqHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// With this overloaded version, we allow anonymous enums to be used
|
// With this overloaded version, we allow anonymous enums to be used
|
||||||
// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
|
// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums can be
|
||||||
// enums can be implicitly cast to BiggestInt.
|
// implicitly cast to intmax_t.
|
||||||
//
|
//
|
||||||
// Even though its body looks the same as the above version, we
|
// Even though its body looks the same as the above version, we
|
||||||
// cannot merge the two, as it will make anonymous enums unhappy.
|
// cannot merge the two, as it will make anonymous enums unhappy.
|
||||||
static AssertionResult Compare(const char* lhs_expression,
|
static AssertionResult Compare(const char* lhs_expression,
|
||||||
const char* rhs_expression, BiggestInt lhs,
|
const char* rhs_expression, intmax_t lhs,
|
||||||
BiggestInt rhs) {
|
intmax_t rhs) {
|
||||||
return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
|
return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -236,7 +236,6 @@
|
|||||||
// Integer types:
|
// Integer types:
|
||||||
// TypeWithSize - maps an integer to a int type.
|
// TypeWithSize - maps an integer to a int type.
|
||||||
// TimeInMillis - integers of known sizes.
|
// TimeInMillis - integers of known sizes.
|
||||||
// BiggestInt - the biggest signed integer type.
|
|
||||||
//
|
//
|
||||||
// Command-line utilities:
|
// Command-line utilities:
|
||||||
// GetInjectableArgvs() - returns the command line as a vector of strings.
|
// GetInjectableArgvs() - returns the command line as a vector of strings.
|
||||||
@ -2303,14 +2302,6 @@ GTEST_DISABLE_DEPRECATED_POP_()
|
|||||||
#define GTEST_SNPRINTF_ snprintf
|
#define GTEST_SNPRINTF_ snprintf
|
||||||
#endif
|
#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
|
// 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
|
// type. It maps a size in bytes to a primitive type with that
|
||||||
// size. e.g.
|
// size. e.g.
|
||||||
|
|||||||
@ -95,10 +95,12 @@ void PrintTo(EnumWithPrintTo e, std::ostream* os) {
|
|||||||
*os << (e == kEWPT1 ? "kEWPT1" : "invalid");
|
*os << (e == kEWPT1 ? "kEWPT1" : "invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
// A class implicitly convertible to BiggestInt.
|
// A class implicitly convertible to intmax_t.
|
||||||
class BiggestIntConvertible {
|
class BiggestIntConvertible {
|
||||||
public:
|
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
|
// 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())); }
|
TEST(PrintClassTest, AbslStringify) { EXPECT_EQ("(10, 20)", Print(Point())); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Tests printing a class implicitly convertible to BiggestInt.
|
// Tests printing a class implicitly convertible to intmax_t.
|
||||||
|
|
||||||
TEST(PrintClassTest, BiggestIntConvertible) {
|
TEST(PrintClassTest, BiggestIntConvertible) {
|
||||||
EXPECT_EQ("42", Print(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
|
// pointers to objects, and some compilers (e.g. GCC 3.4) enforce
|
||||||
// this limitation.
|
// this limitation.
|
||||||
EXPECT_EQ(PrintPointer(reinterpret_cast<const void*>(
|
EXPECT_EQ(PrintPointer(reinterpret_cast<const void*>(
|
||||||
reinterpret_cast<internal::BiggestInt>(&MyFunction))),
|
reinterpret_cast<intmax_t>(&MyFunction))),
|
||||||
Print(&MyFunction));
|
Print(&MyFunction));
|
||||||
int (*p)(bool) = NULL; // NOLINT
|
int (*p)(bool) = NULL; // NOLINT
|
||||||
EXPECT_EQ("NULL", Print(p));
|
EXPECT_EQ("NULL", Print(p));
|
||||||
@ -1474,8 +1476,8 @@ TEST(PrintReferenceTest, HandlesFunctionPointer) {
|
|||||||
// standard disallows casting between pointers to functions and
|
// standard disallows casting between pointers to functions and
|
||||||
// pointers to objects, and some compilers (e.g. GCC 3.4) enforce
|
// pointers to objects, and some compilers (e.g. GCC 3.4) enforce
|
||||||
// this limitation.
|
// this limitation.
|
||||||
const std::string fp_string = PrintPointer(reinterpret_cast<const void*>(
|
const std::string fp_string = PrintPointer(
|
||||||
reinterpret_cast<internal::BiggestInt>(fp)));
|
reinterpret_cast<const void*>(reinterpret_cast<intmax_t>(fp)));
|
||||||
EXPECT_EQ("@" + fp_pointer_string + " " + fp_string, PrintByRef(fp));
|
EXPECT_EQ("@" + fp_pointer_string + " " + fp_string, PrintByRef(fp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,6 +34,7 @@
|
|||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
// Verifies that the command line flag variables can be accessed in
|
// Verifies that the command line flag variables can be accessed in
|
||||||
// code once "gtest.h" has been #included.
|
// code once "gtest.h" has been #included.
|
||||||
@ -4029,7 +4030,7 @@ enum {
|
|||||||
// On Linux, kCaseB and kCaseA have the same value when truncated to
|
// On Linux, kCaseB and kCaseA have the same value when truncated to
|
||||||
// int size. We want to test whether this will confuse the
|
// int size. We want to test whether this will confuse the
|
||||||
// assertions.
|
// assertions.
|
||||||
kCaseB = testing::internal::kMaxBiggestInt,
|
kCaseB = (std::numeric_limits<intmax_t>::max)(),
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user