aboutsummaryrefslogtreecommitdiffstats
path: root/googletest/test
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-11-20 14:36:06 -0500
committerGennadiy Civil <misterg@google.com>2019-11-22 16:33:15 -0500
commit717ce7feb87278b81dad756d973693024621f8e8 (patch)
tree2c016351f4359b94f75fa2af762d2138998d8063 /googletest/test
parent200ff599496e20f4e39566feeaf2f6734ca7570f (diff)
downloadgoogletest-717ce7feb87278b81dad756d973693024621f8e8.tar.gz
googletest-717ce7feb87278b81dad756d973693024621f8e8.tar.bz2
googletest-717ce7feb87278b81dad756d973693024621f8e8.zip
Googletest export
Use standard C++11 integer types in gtest-port.h. Remove testing::internal::{Int,Uint}{32,64} in favor of types guaranteed to be in <cstdint> since C++11. Tests for built-in integer type coverage are switched from {Int,Uint}64 to [unsigned] long long, which is guaranteed by C++11 to exist and be at least 64-bit wide. PiperOrigin-RevId: 281565263
Diffstat (limited to 'googletest/test')
-rw-r--r--googletest/test/googletest-printers-test.cc26
-rw-r--r--googletest/test/gtest_unittest.cc37
2 files changed, 32 insertions, 31 deletions
diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc
index 58be7d1c..bf37fb45 100644
--- a/googletest/test/googletest-printers-test.cc
+++ b/googletest/test/googletest-printers-test.cc
@@ -33,11 +33,12 @@
// This file tests the universal value printer.
#include <ctype.h>
-#include <limits.h>
#include <string.h>
#include <algorithm>
+#include <cstdint>
#include <deque>
#include <forward_list>
+#include <limits>
#include <list>
#include <map>
#include <set>
@@ -339,23 +340,25 @@ TEST(PrintBuiltInTypeTest, Wchar_t) {
EXPECT_EQ("L'\\xC74D' (51021)", Print(static_cast<wchar_t>(0xC74D)));
}
-// Test that Int64 provides more storage than wchar_t.
+// Test that int64_t provides more storage than wchar_t.
TEST(PrintTypeSizeTest, Wchar_t) {
- EXPECT_LT(sizeof(wchar_t), sizeof(testing::internal::Int64));
+ EXPECT_LT(sizeof(wchar_t), sizeof(int64_t));
}
// Various integer types.
TEST(PrintBuiltInTypeTest, Integer) {
EXPECT_EQ("'\\xFF' (255)", Print(static_cast<unsigned char>(255))); // uint8
EXPECT_EQ("'\\x80' (-128)", Print(static_cast<signed char>(-128))); // int8
- EXPECT_EQ("65535", Print(USHRT_MAX)); // uint16
- EXPECT_EQ("-32768", Print(SHRT_MIN)); // int16
- EXPECT_EQ("4294967295", Print(UINT_MAX)); // uint32
- EXPECT_EQ("-2147483648", Print(INT_MIN)); // int32
+ EXPECT_EQ("65535", Print(std::numeric_limits<uint16_t>::max())); // uint16
+ EXPECT_EQ("-32768", Print(std::numeric_limits<int16_t>::min())); // int16
+ EXPECT_EQ("4294967295",
+ Print(std::numeric_limits<uint32_t>::max())); // uint32
+ EXPECT_EQ("-2147483648",
+ Print(std::numeric_limits<int32_t>::min())); // int32
EXPECT_EQ("18446744073709551615",
- Print(static_cast<testing::internal::UInt64>(-1))); // uint64
+ Print(std::numeric_limits<uint64_t>::max())); // uint64
EXPECT_EQ("-9223372036854775808",
- Print(static_cast<testing::internal::Int64>(1) << 63)); // int64
+ Print(std::numeric_limits<int64_t>::min())); // int64
}
// Size types.
@@ -977,9 +980,8 @@ TEST(PrintStdTupleTest, VariousSizes) {
EXPECT_EQ("(false, 2, 3, 4)", Print(t4));
const char* const str = "8";
- ::std::tuple<bool, char, short, testing::internal::Int32, // NOLINT
- testing::internal::Int64, float, double, const char*, void*,
- std::string>
+ ::std::tuple<bool, char, short, int32_t, int64_t, float, double, // NOLINT
+ const char*, void*, std::string>
t10(false, 'a', static_cast<short>(3), 4, 5, 1.5F, -2.5, str, // NOLINT
nullptr, "10");
EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc
index 74379abc..5a1e8d03 100644
--- a/googletest/test/gtest_unittest.cc
+++ b/googletest/test/gtest_unittest.cc
@@ -60,6 +60,7 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) {
#include <string.h>
#include <time.h>
+#include <cstdint>
#include <map>
#include <ostream>
#include <type_traits>
@@ -249,7 +250,6 @@ using testing::internal::GetTestTypeId;
using testing::internal::GetTimeInMillis;
using testing::internal::GetTypeId;
using testing::internal::GetUnitTestImpl;
-using testing::internal::Int32;
using testing::internal::Int32FromEnvOrDie;
using testing::internal::IsAProtocolMessage;
using testing::internal::IsContainer;
@@ -271,7 +271,6 @@ using testing::internal::StreamableToString;
using testing::internal::String;
using testing::internal::TestEventListenersAccessor;
using testing::internal::TestResultAccessor;
-using testing::internal::UInt32;
using testing::internal::UnitTestImpl;
using testing::internal::WideStringToUtf8;
using testing::internal::edit_distance::CalculateOptimalEdits;
@@ -788,7 +787,7 @@ TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) {
}
TEST(RandomTest, GeneratesNumbersWithinRange) {
- const UInt32 kRange = 10000;
+ constexpr uint32_t kRange = 10000;
testing::internal::Random random(12345);
for (int i = 0; i < 10; i++) {
EXPECT_LT(random.Generate(kRange), kRange) << " for iteration " << i;
@@ -801,10 +800,10 @@ TEST(RandomTest, GeneratesNumbersWithinRange) {
}
TEST(RandomTest, RepeatsWhenReseeded) {
- const int kSeed = 123;
- const int kArraySize = 10;
- const UInt32 kRange = 10000;
- UInt32 values[kArraySize];
+ constexpr int kSeed = 123;
+ constexpr int kArraySize = 10;
+ constexpr uint32_t kRange = 10000;
+ uint32_t values[kArraySize];
testing::internal::Random random(kSeed);
for (int i = 0; i < kArraySize; i++) {
@@ -1772,7 +1771,7 @@ TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) {
// Tests that ParseInt32Flag() returns false and doesn't change the
// output value when the flag has wrong format
TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
- Int32 value = 123;
+ int32_t value = 123;
EXPECT_FALSE(ParseInt32Flag("--a=100", "b", &value));
EXPECT_EQ(123, value);
@@ -1785,7 +1784,7 @@ TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) {
TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
printf("(expecting 2 warnings)\n");
- Int32 value = 123;
+ int32_t value = 123;
EXPECT_FALSE(ParseInt32Flag("--abc=12345678987654321", "abc", &value));
EXPECT_EQ(123, value);
@@ -1799,7 +1798,7 @@ TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) {
TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
printf("(expecting 2 warnings)\n");
- Int32 value = 123;
+ int32_t value = 123;
EXPECT_FALSE(ParseInt32Flag("--abc=A1", "abc", &value));
EXPECT_EQ(123, value);
@@ -1811,7 +1810,7 @@ TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) {
// returns true when the flag represents a valid decimal integer in
// the range of an Int32.
TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
- Int32 value = 123;
+ int32_t value = 123;
EXPECT_TRUE(ParseInt32Flag("--" GTEST_FLAG_PREFIX_ "abc=456", "abc", &value));
EXPECT_EQ(456, value);
@@ -1834,7 +1833,7 @@ TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
#endif // !GTEST_OS_WINDOWS_MOBILE
// Tests that Int32FromEnvOrDie() aborts with an error message
-// if the variable is not an Int32.
+// if the variable is not an int32_t.
TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "xxx");
EXPECT_DEATH_IF_SUPPORTED(
@@ -1843,7 +1842,7 @@ TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) {
}
// Tests that Int32FromEnvOrDie() aborts with an error message
-// if the variable cannot be represented by an Int32.
+// if the variable cannot be represented by an int32_t.
TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) {
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "1234567891234567891234");
EXPECT_DEATH_IF_SUPPORTED(
@@ -5597,7 +5596,7 @@ struct Flags {
// Creates a Flags struct where the gtest_random_seed flag has the given
// value.
- static Flags RandomSeed(Int32 random_seed) {
+ static Flags RandomSeed(int32_t random_seed) {
Flags flags;
flags.random_seed = random_seed;
return flags;
@@ -5605,7 +5604,7 @@ struct Flags {
// Creates a Flags struct where the gtest_repeat flag has the given
// value.
- static Flags Repeat(Int32 repeat) {
+ static Flags Repeat(int32_t repeat) {
Flags flags;
flags.repeat = repeat;
return flags;
@@ -5621,7 +5620,7 @@ struct Flags {
// Creates a Flags struct where the GTEST_FLAG(stack_trace_depth) flag has
// the given value.
- static Flags StackTraceDepth(Int32 stack_trace_depth) {
+ static Flags StackTraceDepth(int32_t stack_trace_depth) {
Flags flags;
flags.stack_trace_depth = stack_trace_depth;
return flags;
@@ -5652,10 +5651,10 @@ struct Flags {
bool list_tests;
const char* output;
bool print_time;
- Int32 random_seed;
- Int32 repeat;
+ int32_t random_seed;
+ int32_t repeat;
bool shuffle;
- Int32 stack_trace_depth;
+ int32_t stack_trace_depth;
const char* stream_result_to;
bool throw_on_failure;
};