Skip to content

Commit 50bdfd6

Browse files
deps: update googletest to 36ba75f0ad5383a9759f17f3f72fd4661c72cb6d
PR-URL: #65654 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 6c7e226 commit 50bdfd6

8 files changed

Lines changed: 130 additions & 57 deletions

File tree

deps/googletest/include/gtest/gtest-param-test.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ auto ConvertGenerator(Gen&& gen, Func&& f) {
552552

553553
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name, ...) \
554554
static ::testing::internal::ParamGenerator<test_suite_name::ParamType> \
555-
gtest_##prefix##test_suite_name##_EvalGenerator_() { \
555+
gtest_##prefix##test_suite_name##_EvalGenerator_() { \
556556
return GTEST_EXPAND_(GTEST_GET_FIRST_(__VA_ARGS__, DUMMY_PARAM_)); \
557557
} \
558558
static ::std::string gtest_##prefix##test_suite_name##_EvalGenerateName_( \
@@ -562,7 +562,7 @@ auto ConvertGenerator(Gen&& gen, Func&& f) {
562562
__VA_ARGS__, \
563563
::testing::internal::DefaultParamName<test_suite_name::ParamType>, \
564564
DUMMY_PARAM_))); \
565-
auto t = std::make_tuple(__VA_ARGS__); \
565+
const auto t = std::make_tuple(__VA_ARGS__); \
566566
static_assert(std::tuple_size<decltype(t)>::value <= 2, \
567567
"Too Many Args!"); \
568568
} \

deps/googletest/include/gtest/gtest-printers.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -522,17 +522,14 @@ inline void PrintTo(bool x, ::std::ostream* os) {
522522
GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os);
523523

524524
GTEST_API_ void PrintTo(char32_t c, ::std::ostream* os);
525-
inline void PrintTo(char16_t c, ::std::ostream* os) {
526-
// TODO(b/418738869): Incorrect for values not representing valid codepoints.
527-
// Also see https://github.com/google/googletest/issues/4762.
528-
PrintTo(static_cast<char32_t>(c), os);
529-
}
525+
526+
// Overloads for the UTF-8 and UTF-16 code unit types. A code unit that
527+
// encodes a code point all by itself is printed with the U+XXXX notation;
528+
// one that does not (any non-ASCII char8_t, and the UTF-16 surrogates) is
529+
// printed as a code unit instead, the way wchar_t is.
530+
GTEST_API_ void PrintTo(char16_t c, ::std::ostream* os);
530531
#ifdef __cpp_lib_char8_t
531-
inline void PrintTo(char8_t c, ::std::ostream* os) {
532-
// TODO(b/418738869): Incorrect for values not representing valid codepoints.
533-
// Also see https://github.com/google/googletest/issues/4762.
534-
PrintTo(static_cast<char32_t>(c), os);
535-
}
532+
GTEST_API_ void PrintTo(char8_t c, ::std::ostream* os);
536533
#endif
537534

538535
// gcc/clang __{u,}int128_t
@@ -674,12 +671,12 @@ inline void PrintTo(char32_t* s, ::std::ostream* os) {
674671
PrintTo(ImplicitCast_<const char32_t*>(s), os);
675672
}
676673

677-
// MSVC can be configured to define wchar_t as a typedef of unsigned
678-
// short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native
679-
// type. When wchar_t is a typedef, defining an overload for const
680-
// wchar_t* would cause unsigned short* be printed as a wide string,
681-
// possibly causing invalid memory accesses.
682-
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
674+
// Only add an overload for printing wchar_t* if:
675+
// 1. Wide string support is enabled.
676+
// 2. wchar_t is a distinct native type. (If it's a typedef, the overload could
677+
// cause a pointer to the underlying type to be mistakenly treated as a
678+
// string.)
679+
#if GTEST_HAS_STD_WSTRING && GTEST_HAS_NATIVE_WCHAR
683680
// Overloads for wide C strings
684681
GTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os);
685682
inline void PrintTo(wchar_t* s, ::std::ostream* os) {

deps/googletest/include/gtest/gtest.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
#include "gtest/gtest-typed-test.h" // IWYU pragma: export
7272
#include "gtest/gtest_pred_impl.h" // IWYU pragma: export
7373
#include "gtest/gtest_prod.h" // IWYU pragma: export
74-
#include "gtest/internal/gtest-internal.h"
74+
#include "gtest/internal/gtest-internal.h" // IWYU pragma: export
7575
#include "gtest/internal/gtest-string.h"
7676

7777
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
@@ -1514,6 +1514,8 @@ GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
15141514
const char* s2_expression,
15151515
const char* s1, const char* s2);
15161516

1517+
#if GTEST_HAS_STD_WSTRING
1518+
15171519
// Helper function for *_STREQ on wide strings.
15181520
//
15191521
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
@@ -1528,6 +1530,8 @@ GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
15281530
const char* s2_expression,
15291531
const wchar_t* s1, const wchar_t* s2);
15301532

1533+
#endif // GTEST_HAS_STD_WSTRING
1534+
15311535
} // namespace internal
15321536

15331537
// IsSubstring() and IsNotSubstring() are intended to be used as the
@@ -1542,18 +1546,10 @@ GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
15421546
const char* haystack_expr,
15431547
const char* needle,
15441548
const char* haystack);
1545-
GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
1546-
const char* haystack_expr,
1547-
const wchar_t* needle,
1548-
const wchar_t* haystack);
15491549
GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
15501550
const char* haystack_expr,
15511551
const char* needle,
15521552
const char* haystack);
1553-
GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
1554-
const char* haystack_expr,
1555-
const wchar_t* needle,
1556-
const wchar_t* haystack);
15571553
GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
15581554
const char* haystack_expr,
15591555
const ::std::string& needle,
@@ -1564,6 +1560,14 @@ GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
15641560
const ::std::string& haystack);
15651561

15661562
#if GTEST_HAS_STD_WSTRING
1563+
GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
1564+
const char* haystack_expr,
1565+
const wchar_t* needle,
1566+
const wchar_t* haystack);
1567+
GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
1568+
const char* haystack_expr,
1569+
const wchar_t* needle,
1570+
const wchar_t* haystack);
15671571
GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
15681572
const char* haystack_expr,
15691573
const ::std::wstring& needle,

deps/googletest/include/gtest/internal/gtest-internal.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
4040
#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
4141

42-
#include "gtest/internal/gtest-port.h"
42+
#include "gtest/internal/gtest-port.h" // IWYU pragma: export
4343

4444
#ifdef GTEST_OS_LINUX
4545
#include <stdlib.h>
@@ -1516,8 +1516,9 @@ class [[nodiscard]] NeverThrown {
15161516
parent_class>::GetSetUpCaseOrSuite(__FILE__, __LINE__), \
15171517
::testing::internal::SuiteApiResolver< \
15181518
parent_class>::GetTearDownCaseOrSuite(__FILE__, __LINE__), \
1519-
new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_( \
1520-
test_suite_name, test_name)>); \
1519+
::std::make_unique<::testing::internal::TestFactoryImpl< \
1520+
GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)>>() \
1521+
.release()); \
15211522
void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody()
15221523

15231524
#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_

deps/googletest/include/gtest/internal/gtest-port.h

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,17 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
500500
#endif // defined(_MSC_VER) || defined(__BORLANDC__)
501501
#endif // GTEST_HAS_EXCEPTIONS
502502

503+
// MSVC either defines wchar_t as a typedef of unsigned short, or as a native
504+
// type (in which case, it defines _NATIVE_WCHAR_T_DEFINED). When wchar_t is a
505+
// typedef, defining an overload for const wchar_t* would cause unsigned short*
506+
// be printed as a wide string, possibly causing invalid memory accesses, so we
507+
// omit wchar_t overloads in that case.
508+
#if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)
509+
#define GTEST_HAS_NATIVE_WCHAR 0
510+
#else
511+
#define GTEST_HAS_NATIVE_WCHAR 1
512+
#endif
513+
503514
// 1. Calculate default GTEST_HAS_STD_WSTRING values based on STL capabilities.
504515
#if defined(_MSVC_STL_VERSION)
505516
// Microsoft's STL implementation always supports ::std::wstring.
@@ -2185,7 +2196,13 @@ GTEST_DISABLE_DEPRECATED_PUSH_()
21852196
!defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_WINDOWS_GAMES) && \
21862197
!defined(GTEST_OS_ESP8266) && !defined(GTEST_OS_XTENSA) && \
21872198
!defined(GTEST_OS_QURT)
2188-
inline int ChDir(const char* dir) { return chdir(dir); }
2199+
inline int ChDir(const char* dir) {
2200+
#ifdef GTEST_OS_WINDOWS
2201+
return _chdir(dir);
2202+
#else
2203+
return chdir(dir);
2204+
#endif
2205+
}
21892206
#endif
21902207
inline FILE* FOpen(const char* path, const char* mode) {
21912208
#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW)
@@ -2202,17 +2219,37 @@ inline FILE* FOpen(const char* path, const char* mode) {
22022219
inline FILE* FReopen(const char* path, const char* mode, FILE* stream) {
22032220
return freopen(path, mode, stream);
22042221
}
2205-
inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
2222+
inline FILE* FDOpen(int fd, const char* mode) {
2223+
#ifdef GTEST_OS_WINDOWS
2224+
return _fdopen(fd, mode);
2225+
#else
2226+
return fdopen(fd, mode);
2227+
#endif
2228+
}
22062229
#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT
22072230
inline int FClose(FILE* fp) { return fclose(fp); }
22082231
#if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT)
22092232
inline int Read(int fd, void* buf, unsigned int count) {
2233+
#ifdef GTEST_OS_WINDOWS
2234+
return static_cast<int>(_read(fd, buf, count));
2235+
#else
22102236
return static_cast<int>(read(fd, buf, count));
2237+
#endif
22112238
}
22122239
inline int Write(int fd, const void* buf, unsigned int count) {
2240+
#ifdef GTEST_OS_WINDOWS
2241+
return static_cast<int>(_write(fd, buf, count));
2242+
#else
22132243
return static_cast<int>(write(fd, buf, count));
2244+
#endif
2245+
}
2246+
inline int Close(int fd) {
2247+
#ifdef GTEST_OS_WINDOWS
2248+
return _close(fd);
2249+
#else
2250+
return close(fd);
2251+
#endif
22142252
}
2215-
inline int Close(int fd) { return close(fd); }
22162253
#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT
22172254
#endif // GTEST_HAS_FILE_SYSTEM
22182255

deps/googletest/src/gtest-port.cc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,14 @@ bool EndsWithPathSeparator(const std::string& path) {
10851085
class CapturedStream {
10861086
public:
10871087
// The ctor redirects the stream to a temporary file.
1088-
explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
1088+
explicit CapturedStream(int fd)
1089+
: fd_(fd),
1090+
#ifdef GTEST_OS_WINDOWS
1091+
uncaptured_fd_(_dup(fd))
1092+
#else
1093+
uncaptured_fd_(dup(fd))
1094+
#endif
1095+
{
10891096
#ifdef GTEST_OS_WINDOWS
10901097
char temp_dir_path[MAX_PATH + 1] = {'\0'}; // NOLINT
10911098
char temp_file_path[MAX_PATH + 1] = {'\0'}; // NOLINT
@@ -1097,7 +1104,7 @@ class CapturedStream {
10971104
GTEST_CHECK_(success != 0)
10981105
<< "Failed to create temporary file in " << temp_dir_path
10991106
<< " with error " << ::GetLastError();
1100-
const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE);
1107+
const int captured_fd = _creat(temp_file_path, _S_IREAD | _S_IWRITE);
11011108
GTEST_CHECK_(captured_fd != -1)
11021109
<< "Failed to open temporary file " << temp_file_path << " with error "
11031110
<< ::GetLastError();
@@ -1167,8 +1174,12 @@ class CapturedStream {
11671174
filename_ = std::move(name_template);
11681175
#endif // GTEST_OS_WINDOWS
11691176
fflush(nullptr);
1177+
#ifdef GTEST_OS_WINDOWS
1178+
_dup2(captured_fd, fd_);
1179+
#else
11701180
dup2(captured_fd, fd_);
1171-
close(captured_fd);
1181+
#endif
1182+
posix::Close(captured_fd);
11721183
}
11731184

11741185
~CapturedStream() { remove(filename_.c_str()); }
@@ -1177,8 +1188,12 @@ class CapturedStream {
11771188
if (uncaptured_fd_ != -1) {
11781189
// Restores the original stream.
11791190
fflush(nullptr);
1191+
#ifdef GTEST_OS_WINDOWS
1192+
_dup2(uncaptured_fd_, fd_);
1193+
#else
11801194
dup2(uncaptured_fd_, fd_);
1181-
close(uncaptured_fd_);
1195+
#endif
1196+
posix::Close(uncaptured_fd_);
11821197
uncaptured_fd_ = -1;
11831198
}
11841199

deps/googletest/src/gtest-printers.cc

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,28 @@ void PrintTo(char32_t c, ::std::ostream* os) {
286286
<< static_cast<uint32_t>(c);
287287
}
288288

289+
// char8_t and char16_t hold code units, not code points, so the U+XXXX
290+
// notation only applies to the values that encode a code point on their own.
291+
// The rest -- non-ASCII char8_t, which are always part of a multi-unit UTF-8
292+
// sequence, and the UTF-16 surrogates -- are printed as code units.
293+
void PrintTo(char16_t c, ::std::ostream* os) {
294+
if (c >= 0xD800 && c <= 0xDFFF) {
295+
PrintCharAndCodeTo(c, os);
296+
} else {
297+
PrintTo(static_cast<char32_t>(c), os);
298+
}
299+
}
300+
301+
#ifdef __cpp_lib_char8_t
302+
void PrintTo(char8_t c, ::std::ostream* os) {
303+
if (c >= 0x80) {
304+
PrintCharAndCodeTo(c, os);
305+
} else {
306+
PrintTo(static_cast<char32_t>(c), os);
307+
}
308+
}
309+
#endif
310+
289311
// gcc/clang __{u,}int128_t
290312
#if defined(__SIZEOF_INT128__)
291313
void PrintTo(__uint128_t v, ::std::ostream* os) {
@@ -468,16 +490,9 @@ void PrintTo(const char16_t* s, ostream* os) { PrintCStringTo(s, os); }
468490

469491
void PrintTo(const char32_t* s, ostream* os) { PrintCStringTo(s, os); }
470492

471-
// MSVC compiler can be configured to define whar_t as a typedef
472-
// of unsigned short. Defining an overload for const wchar_t* in that case
473-
// would cause pointers to unsigned shorts be printed as wide strings,
474-
// possibly accessing more memory than intended and causing invalid
475-
// memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when
476-
// wchar_t is implemented as a native type.
477-
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
478-
// Prints the given wide C string to the ostream.
493+
#if GTEST_HAS_STD_WSTRING && GTEST_HAS_NATIVE_WCHAR
479494
void PrintTo(const wchar_t* s, ostream* os) { PrintCStringTo(s, os); }
480-
#endif // wchar_t is native
495+
#endif
481496

482497
namespace {
483498

deps/googletest/src/gtest.cc

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,11 +1876,13 @@ bool IsSubstringPred(const char* needle, const char* haystack) {
18761876
return strstr(haystack, needle) != nullptr;
18771877
}
18781878

1879+
#if GTEST_HAS_STD_WSTRING
18791880
bool IsSubstringPred(const wchar_t* needle, const wchar_t* haystack) {
18801881
if (needle == nullptr || haystack == nullptr) return needle == haystack;
18811882

18821883
return wcsstr(haystack, needle) != nullptr;
18831884
}
1885+
#endif // GTEST_HAS_STD_WSTRING
18841886

18851887
// StringType here can be either ::std::string or ::std::wstring.
18861888
template <typename StringType>
@@ -1922,23 +1924,12 @@ AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr,
19221924
return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
19231925
}
19241926

1925-
AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr,
1926-
const wchar_t* needle, const wchar_t* haystack) {
1927-
return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
1928-
}
1929-
19301927
AssertionResult IsNotSubstring(const char* needle_expr,
19311928
const char* haystack_expr, const char* needle,
19321929
const char* haystack) {
19331930
return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
19341931
}
19351932

1936-
AssertionResult IsNotSubstring(const char* needle_expr,
1937-
const char* haystack_expr, const wchar_t* needle,
1938-
const wchar_t* haystack) {
1939-
return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
1940-
}
1941-
19421933
AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr,
19431934
const ::std::string& needle,
19441935
const ::std::string& haystack) {
@@ -1953,6 +1944,17 @@ AssertionResult IsNotSubstring(const char* needle_expr,
19531944
}
19541945

19551946
#if GTEST_HAS_STD_WSTRING
1947+
AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr,
1948+
const wchar_t* needle, const wchar_t* haystack) {
1949+
return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
1950+
}
1951+
1952+
AssertionResult IsNotSubstring(const char* needle_expr,
1953+
const char* haystack_expr, const wchar_t* needle,
1954+
const wchar_t* haystack) {
1955+
return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
1956+
}
1957+
19561958
AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr,
19571959
const ::std::wstring& needle,
19581960
const ::std::wstring& haystack) {
@@ -2182,6 +2184,7 @@ bool String::WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs) {
21822184
return wcscmp(lhs, rhs) == 0;
21832185
}
21842186

2187+
#if GTEST_HAS_STD_WSTRING
21852188
// Helper function for *_STREQ on wide strings.
21862189
AssertionResult CmpHelperSTREQ(const char* lhs_expression,
21872190
const char* rhs_expression, const wchar_t* lhs,
@@ -2206,6 +2209,7 @@ AssertionResult CmpHelperSTRNE(const char* s1_expression,
22062209
<< "Expected: (" << s1_expression << ") != (" << s2_expression
22072210
<< "), actual: " << PrintToString(s1) << " vs " << PrintToString(s2);
22082211
}
2212+
#endif // GTEST_HAS_STD_WSTRING
22092213

22102214
// Compares two C strings, ignoring case. Returns true if and only if they have
22112215
// the same content.

0 commit comments

Comments
 (0)