boringssl-with-bazel/src/third_party/googletest/src/gtest-internal-inl.h
Go to the documentation of this file.
1 // Copyright 2005, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 // Utility functions and classes used by the Google C++ testing framework.//
31 // This file contains purely Google Test's internal implementation. Please
32 // DO NOT #INCLUDE IT IN A USER PROGRAM.
33 
34 #ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
35 #define GTEST_SRC_GTEST_INTERNAL_INL_H_
36 
37 #ifndef _WIN32_WCE
38 # include <errno.h>
39 #endif // !_WIN32_WCE
40 #include <stddef.h>
41 #include <stdlib.h> // For strtoll/_strtoul64/malloc/free.
42 #include <string.h> // For memmove.
43 
44 #include <algorithm>
45 #include <cstdint>
46 #include <memory>
47 #include <string>
48 #include <vector>
49 
50 #include "gtest/internal/gtest-port.h"
51 
52 #if GTEST_CAN_STREAM_RESULTS_
53 # include <arpa/inet.h> // NOLINT
54 # include <netdb.h> // NOLINT
55 #endif
56 
57 #if GTEST_OS_WINDOWS
58 # include <windows.h> // NOLINT
59 #endif // GTEST_OS_WINDOWS
60 
61 #include "gtest/gtest.h"
62 #include "gtest/gtest-spi.h"
63 
65 /* class A needs to have dll-interface to be used by clients of class B */)
66 
68 
69 // Declares the flags.
70 //
71 // We don't want the users to modify this flag in the code, but want
72 // Google Test's own unit tests to be able to access it. Therefore we
73 // declare it here as opposed to in gtest.h.
74 GTEST_DECLARE_bool_(death_test_use_fork);
75 
76 namespace internal {
77 
78 // The value of GetTestTypeId() as seen from within the Google Test
79 // library. This is solely for testing GetTestTypeId().
81 
82 // Names of the flags (needed for parsing Google Test flags).
83 const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
84 const char kBreakOnFailureFlag[] = "break_on_failure";
85 const char kCatchExceptionsFlag[] = "catch_exceptions";
86 const char kColorFlag[] = "color";
87 const char kFailFast[] = "fail_fast";
88 const char kFilterFlag[] = "filter";
89 const char kListTestsFlag[] = "list_tests";
90 const char kOutputFlag[] = "output";
91 const char kBriefFlag[] = "brief";
92 const char kPrintTimeFlag[] = "print_time";
93 const char kPrintUTF8Flag[] = "print_utf8";
94 const char kRandomSeedFlag[] = "random_seed";
95 const char kRepeatFlag[] = "repeat";
96 const char kShuffleFlag[] = "shuffle";
97 const char kStackTraceDepthFlag[] = "stack_trace_depth";
98 const char kStreamResultToFlag[] = "stream_result_to";
99 const char kThrowOnFailureFlag[] = "throw_on_failure";
100 const char kFlagfileFlag[] = "flagfile";
101 
102 // A valid random seed must be in [1, kMaxRandomSeed].
103 const int kMaxRandomSeed = 99999;
104 
105 // g_help_flag is true if and only if the --help flag or an equivalent form
106 // is specified on the command line.
107 GTEST_API_ extern bool g_help_flag;
108 
109 // Returns the current time in milliseconds.
111 
112 // Returns true if and only if Google Test should use colors in the output.
113 GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
114 
115 // Formats the given time in milliseconds as seconds.
117 
118 // Converts the given time in milliseconds to a date string in the ISO 8601
119 // format, without the timezone information. N.B.: due to the use the
120 // non-reentrant localtime() function, this function is not thread safe. Do
121 // not use it in any code that can be called from multiple threads.
123 
124 // Parses a string for an Int32 flag, in the form of "--flag=value".
125 //
126 // On success, stores the value of the flag in *value, and returns
127 // true. On failure, returns false without changing *value.
129  const char* str, const char* flag, int32_t* value);
130 
131 // Returns a random seed in range [1, kMaxRandomSeed] based on the
132 // given --gtest_random_seed flag value.
133 inline int GetRandomSeedFromFlag(int32_t random_seed_flag) {
134  const unsigned int raw_seed = (random_seed_flag == 0) ?
135  static_cast<unsigned int>(GetTimeInMillis()) :
136  static_cast<unsigned int>(random_seed_flag);
137 
138  // Normalizes the actual seed to range [1, kMaxRandomSeed] such that
139  // it's easy to type.
140  const int normalized_seed =
141  static_cast<int>((raw_seed - 1U) %
142  static_cast<unsigned int>(kMaxRandomSeed)) + 1;
143  return normalized_seed;
144 }
145 
146 // Returns the first valid random seed after 'seed'. The behavior is
147 // undefined if 'seed' is invalid. The seed after kMaxRandomSeed is
148 // considered to be 1.
149 inline int GetNextRandomSeed(int seed) {
151  << "Invalid random seed " << seed << " - must be in [1, "
152  << kMaxRandomSeed << "].";
153  const int next_seed = seed + 1;
154  return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
155 }
156 
157 // This class saves the values of all Google Test flags in its c'tor, and
158 // restores them in its d'tor.
159 class GTestFlagSaver {
160  public:
161  // The c'tor.
162  GTestFlagSaver() {
163  also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
164  break_on_failure_ = GTEST_FLAG(break_on_failure);
165  catch_exceptions_ = GTEST_FLAG(catch_exceptions);
166  color_ = GTEST_FLAG(color);
167  death_test_style_ = GTEST_FLAG(death_test_style);
168  death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
169  fail_fast_ = GTEST_FLAG(fail_fast);
170  filter_ = GTEST_FLAG(filter);
171  internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
172  list_tests_ = GTEST_FLAG(list_tests);
174  brief_ = GTEST_FLAG(brief);
175  print_time_ = GTEST_FLAG(print_time);
176  print_utf8_ = GTEST_FLAG(print_utf8);
177  random_seed_ = GTEST_FLAG(random_seed);
178  repeat_ = GTEST_FLAG(repeat);
179  shuffle_ = GTEST_FLAG(shuffle);
180  stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
181  stream_result_to_ = GTEST_FLAG(stream_result_to);
182  throw_on_failure_ = GTEST_FLAG(throw_on_failure);
183  }
184 
185  // The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
186  ~GTestFlagSaver() {
187  GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
188  GTEST_FLAG(break_on_failure) = break_on_failure_;
189  GTEST_FLAG(catch_exceptions) = catch_exceptions_;
190  GTEST_FLAG(color) = color_;
191  GTEST_FLAG(death_test_style) = death_test_style_;
192  GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
193  GTEST_FLAG(filter) = filter_;
194  GTEST_FLAG(fail_fast) = fail_fast_;
195  GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
196  GTEST_FLAG(list_tests) = list_tests_;
198  GTEST_FLAG(brief) = brief_;
199  GTEST_FLAG(print_time) = print_time_;
200  GTEST_FLAG(print_utf8) = print_utf8_;
201  GTEST_FLAG(random_seed) = random_seed_;
202  GTEST_FLAG(repeat) = repeat_;
203  GTEST_FLAG(shuffle) = shuffle_;
204  GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
205  GTEST_FLAG(stream_result_to) = stream_result_to_;
206  GTEST_FLAG(throw_on_failure) = throw_on_failure_;
207  }
208 
209  private:
210  // Fields for saving the original values of flags.
211  bool also_run_disabled_tests_;
212  bool break_on_failure_;
213  bool catch_exceptions_;
214  std::string color_;
215  std::string death_test_style_;
216  bool death_test_use_fork_;
217  bool fail_fast_;
218  std::string filter_;
219  std::string internal_run_death_test_;
220  bool list_tests_;
222  bool brief_;
223  bool print_time_;
224  bool print_utf8_;
225  int32_t random_seed_;
226  int32_t repeat_;
227  bool shuffle_;
228  int32_t stack_trace_depth_;
229  std::string stream_result_to_;
230  bool throw_on_failure_;
232 
233 // Converts a Unicode code point to a narrow string in UTF-8 encoding.
234 // code_point parameter is of type UInt32 because wchar_t may not be
235 // wide enough to contain a code point.
236 // If the code_point is not a valid Unicode code point
237 // (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted
238 // to "(Invalid Unicode 0xXXXXXXXX)".
240 
241 // Converts a wide string to a narrow string in UTF-8 encoding.
242 // The wide string is assumed to have the following encoding:
243 // UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin)
244 // UTF-32 if sizeof(wchar_t) == 4 (on Linux)
245 // Parameter str points to a null-terminated wide string.
246 // Parameter num_chars may additionally limit the number
247 // of wchar_t characters processed. -1 is used when the entire string
248 // should be processed.
249 // If the string contains code points that are not valid Unicode code points
250 // (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
251 // as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
252 // and contains invalid UTF-16 surrogate pairs, values in those pairs
253 // will be encoded as individual Unicode characters from Basic Normal Plane.
254 GTEST_API_ std::string WideStringToUtf8(const wchar_t* str, int num_chars);
255 
256 // Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
257 // if the variable is present. If a file already exists at this location, this
258 // function will write over it. If the variable is present, but the file cannot
259 // be created, prints an error and exits.
261 
262 // Checks whether sharding is enabled by examining the relevant
263 // environment variable values. If the variables are present,
264 // but inconsistent (e.g., shard_index >= total_shards), prints
265 // an error and exits. If in_subprocess_for_death_test, sharding is
266 // disabled because it must only be applied to the original test
267 // process. Otherwise, we could filter out death tests we intended to execute.
268 GTEST_API_ bool ShouldShard(const char* total_shards_str,
269  const char* shard_index_str,
270  bool in_subprocess_for_death_test);
271 
272 // Parses the environment variable var as a 32-bit integer. If it is unset,
273 // returns default_val. If it is not a 32-bit integer, prints an error and
274 // and aborts.
275 GTEST_API_ int32_t Int32FromEnvOrDie(const char* env_var, int32_t default_val);
276 
277 // Given the total number of shards, the shard index, and the test id,
278 // returns true if and only if the test should be run on this shard. The test id
279 // is some arbitrary but unique non-negative integer assigned to each test
280 // method. Assumes that 0 <= shard_index < total_shards.
282  int total_shards, int shard_index, int test_id);
283 
284 // STL container utilities.
285 
286 // Returns the number of elements in the given container that satisfy
287 // the given predicate.
288 template <class Container, typename Predicate>
289 inline int CountIf(const Container& c, Predicate predicate) {
290  // Implemented as an explicit loop since std::count_if() in libCstd on
291  // Solaris has a non-standard signature.
292  int count = 0;
293  for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
294  if (predicate(*it))
295  ++count;
296  }
297  return count;
298 }
299 
300 // Applies a function/functor to each element in the container.
301 template <class Container, typename Functor>
302 void ForEach(const Container& c, Functor functor) {
303  std::for_each(c.begin(), c.end(), functor);
304 }
305 
306 // Returns the i-th element of the vector, or default_value if i is not
307 // in range [0, v.size()).
308 template <typename E>
309 inline E GetElementOr(const std::vector<E>& v, int i, E default_value) {
310  return (i < 0 || i >= static_cast<int>(v.size())) ? default_value
311  : v[static_cast<size_t>(i)];
312 }
313 
314 // Performs an in-place shuffle of a range of the vector's elements.
315 // 'begin' and 'end' are element indices as an STL-style range;
316 // i.e. [begin, end) are shuffled, where 'end' == size() means to
317 // shuffle to the end of the vector.
318 template <typename E>
319 void ShuffleRange(internal::Random* random, int begin, int end,
320  std::vector<E>* v) {
321  const int size = static_cast<int>(v->size());
322  GTEST_CHECK_(0 <= begin && begin <= size)
323  << "Invalid shuffle range start " << begin << ": must be in range [0, "
324  << size << "].";
325  GTEST_CHECK_(begin <= end && end <= size)
326  << "Invalid shuffle range finish " << end << ": must be in range ["
327  << begin << ", " << size << "].";
328 
329  // Fisher-Yates shuffle, from
330  // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
331  for (int range_width = end - begin; range_width >= 2; range_width--) {
332  const int last_in_range = begin + range_width - 1;
333  const int selected =
334  begin +
335  static_cast<int>(random->Generate(static_cast<uint32_t>(range_width)));
336  std::swap((*v)[static_cast<size_t>(selected)],
337  (*v)[static_cast<size_t>(last_in_range)]);
338  }
339 }
340 
341 // Performs an in-place shuffle of the vector's elements.
342 template <typename E>
343 inline void Shuffle(internal::Random* random, std::vector<E>* v) {
344  ShuffleRange(random, 0, static_cast<int>(v->size()), v);
345 }
346 
347 // A function for deleting an object. Handy for being used as a
348 // functor.
349 template <typename T>
350 static void Delete(T* x) {
351  delete x;
352 }
353 
354 // A predicate that checks the key of a TestProperty against a known key.
355 //
356 // TestPropertyKeyIs is copyable.
357 class TestPropertyKeyIs {
358  public:
359  // Constructor.
360  //
361  // TestPropertyKeyIs has NO default constructor.
362  explicit TestPropertyKeyIs(const std::string& key) : key_(key) {}
363 
364  // Returns true if and only if the test name of test property matches on key_.
365  bool operator()(const TestProperty& test_property) const {
366  return test_property.key() == key_;
367  }
368 
369  private:
371 };
372 
373 // Class UnitTestOptions.
374 //
375 // This class contains functions for processing options the user
376 // specifies when running the tests. It has only static members.
377 //
378 // In most cases, the user can specify an option using either an
379 // environment variable or a command line flag. E.g. you can set the
380 // test filter using either GTEST_FILTER or --gtest_filter. If both
381 // the variable and the flag are present, the latter overrides the
382 // former.
383 class GTEST_API_ UnitTestOptions {
384  public:
385  // Functions for processing the gtest_output flag.
386 
387  // Returns the output format, or "" for normal printed output.
388  static std::string GetOutputFormat();
389 
390  // Returns the absolute path of the requested output file, or the
391  // default (test_detail.xml in the original working directory) if
392  // none was explicitly specified.
393  static std::string GetAbsolutePathToOutputFile();
394 
395  // Functions for processing the gtest_filter flag.
396 
397  // Returns true if and only if the wildcard pattern matches the string.
398  // The first ':' or '\0' character in pattern marks the end of it.
399  //
400  // This recursive algorithm isn't very efficient, but is clear and
401  // works well enough for matching test names, which are short.
402  static bool PatternMatchesString(const char *pattern, const char *str);
403 
404  // Returns true if and only if the user-specified filter matches the test
405  // suite name and the test name.
406  static bool FilterMatchesTest(const std::string& test_suite_name,
407  const std::string& test_name);
408 
409 #if GTEST_OS_WINDOWS
410  // Function for supporting the gtest_catch_exception flag.
411 
412  // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
413  // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
414  // This function is useful as an __except condition.
415  static int GTestShouldProcessSEH(DWORD exception_code);
416 #endif // GTEST_OS_WINDOWS
417 
418  // Returns true if "name" matches the ':' separated list of glob-style
419  // filters in "filter".
420  static bool MatchesFilter(const std::string& name, const char* filter);
421 };
422 
423 // Returns the current application's name, removing directory path if that
424 // is present. Used by UnitTestOptions::GetOutputFile.
426 
427 // The role interface for getting the OS stack trace as a string.
428 class OsStackTraceGetterInterface {
429  public:
430  OsStackTraceGetterInterface() {}
431  virtual ~OsStackTraceGetterInterface() {}
432 
433  // Returns the current OS stack trace as an std::string. Parameters:
434  //
435  // max_depth - the maximum number of stack frames to be included
436  // in the trace.
437  // skip_count - the number of top frames to be skipped; doesn't count
438  // against max_depth.
439  virtual std::string CurrentStackTrace(int max_depth, int skip_count) = 0;
440 
441  // UponLeavingGTest() should be called immediately before Google Test calls
442  // user code. It saves some information about the current stack that
443  // CurrentStackTrace() will use to find and hide Google Test stack frames.
444  virtual void UponLeavingGTest() = 0;
445 
446  // This string is inserted in place of stack frames that are part of
447  // Google Test's implementation.
448  static const char* const kElidedFramesMarker;
449 
450  private:
451  GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
452 };
453 
454 // A working implementation of the OsStackTraceGetterInterface interface.
455 class OsStackTraceGetter : public OsStackTraceGetterInterface {
456  public:
457  OsStackTraceGetter() {}
458 
459  std::string CurrentStackTrace(int max_depth, int skip_count) override;
460  void UponLeavingGTest() override;
461 
462  private:
463 #if GTEST_HAS_ABSL
464  Mutex mutex_; // Protects all internal state.
465 
466  // We save the stack frame below the frame that calls user code.
467  // We do this because the address of the frame immediately below
468  // the user code changes between the call to UponLeavingGTest()
469  // and any calls to the stack trace code from within the user code.
470  void* caller_frame_ = nullptr;
471 #endif // GTEST_HAS_ABSL
472 
473  GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
474 };
475 
476 // Information about a Google Test trace point.
477 struct TraceInfo {
478  const char* file;
479  int line;
481 };
482 
483 // This is the default global test part result reporter used in UnitTestImpl.
484 // This class should only be used by UnitTestImpl.
485 class DefaultGlobalTestPartResultReporter
486  : public TestPartResultReporterInterface {
487  public:
488  explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
489  // Implements the TestPartResultReporterInterface. Reports the test part
490  // result in the current test.
491  void ReportTestPartResult(const TestPartResult& result) override;
492 
493  private:
494  UnitTestImpl* const unit_test_;
495 
496  GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter);
497 };
498 
499 // This is the default per thread test part result reporter used in
500 // UnitTestImpl. This class should only be used by UnitTestImpl.
501 class DefaultPerThreadTestPartResultReporter
502  : public TestPartResultReporterInterface {
503  public:
504  explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
505  // Implements the TestPartResultReporterInterface. The implementation just
506  // delegates to the current global test part result reporter of *unit_test_.
507  void ReportTestPartResult(const TestPartResult& result) override;
508 
509  private:
510  UnitTestImpl* const unit_test_;
511 
512  GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter);
513 };
514 
515 // The private implementation of the UnitTest class. We don't protect
516 // the methods under a mutex, as this class is not accessible by a
517 // user and the UnitTest class that delegates work to this class does
518 // proper locking.
519 class GTEST_API_ UnitTestImpl {
520  public:
521  explicit UnitTestImpl(UnitTest* parent);
522  virtual ~UnitTestImpl();
523 
524  // There are two different ways to register your own TestPartResultReporter.
525  // You can register your own repoter to listen either only for test results
526  // from the current thread or for results from all threads.
527  // By default, each per-thread test result repoter just passes a new
528  // TestPartResult to the global test result reporter, which registers the
529  // test part result for the currently running test.
530 
531  // Returns the global test part result reporter.
532  TestPartResultReporterInterface* GetGlobalTestPartResultReporter();
533 
534  // Sets the global test part result reporter.
535  void SetGlobalTestPartResultReporter(
536  TestPartResultReporterInterface* reporter);
537 
538  // Returns the test part result reporter for the current thread.
539  TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();
540 
541  // Sets the test part result reporter for the current thread.
542  void SetTestPartResultReporterForCurrentThread(
543  TestPartResultReporterInterface* reporter);
544 
545  // Gets the number of successful test suites.
546  int successful_test_suite_count() const;
547 
548  // Gets the number of failed test suites.
549  int failed_test_suite_count() const;
550 
551  // Gets the number of all test suites.
552  int total_test_suite_count() const;
553 
554  // Gets the number of all test suites that contain at least one test
555  // that should run.
556  int test_suite_to_run_count() const;
557 
558  // Gets the number of successful tests.
559  int successful_test_count() const;
560 
561  // Gets the number of skipped tests.
562  int skipped_test_count() const;
563 
564  // Gets the number of failed tests.
565  int failed_test_count() const;
566 
567  // Gets the number of disabled tests that will be reported in the XML report.
568  int reportable_disabled_test_count() const;
569 
570  // Gets the number of disabled tests.
571  int disabled_test_count() const;
572 
573  // Gets the number of tests to be printed in the XML report.
574  int reportable_test_count() const;
575 
576  // Gets the number of all tests.
577  int total_test_count() const;
578 
579  // Gets the number of tests that should run.
580  int test_to_run_count() const;
581 
582  // Gets the time of the test program start, in ms from the start of the
583  // UNIX epoch.
584  TimeInMillis start_timestamp() const { return start_timestamp_; }
585 
586  // Gets the elapsed time, in milliseconds.
587  TimeInMillis elapsed_time() const { return elapsed_time_; }
588 
589  // Returns true if and only if the unit test passed (i.e. all test suites
590  // passed).
591  bool Passed() const { return !Failed(); }
592 
593  // Returns true if and only if the unit test failed (i.e. some test suite
594  // failed or something outside of all tests failed).
595  bool Failed() const {
596  return failed_test_suite_count() > 0 || ad_hoc_test_result()->Failed();
597  }
598 
599  // Gets the i-th test suite among all the test suites. i can range from 0 to
600  // total_test_suite_count() - 1. If i is not in that range, returns NULL.
601  const TestSuite* GetTestSuite(int i) const {
602  const int index = GetElementOr(test_suite_indices_, i, -1);
603  return index < 0 ? nullptr : test_suites_[static_cast<size_t>(i)];
604  }
605 
606  // Legacy API is deprecated but still available
607 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
608  const TestCase* GetTestCase(int i) const { return GetTestSuite(i); }
609 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
610 
611  // Gets the i-th test suite among all the test suites. i can range from 0 to
612  // total_test_suite_count() - 1. If i is not in that range, returns NULL.
613  TestSuite* GetMutableSuiteCase(int i) {
614  const int index = GetElementOr(test_suite_indices_, i, -1);
615  return index < 0 ? nullptr : test_suites_[static_cast<size_t>(index)];
616  }
617 
618  // Provides access to the event listener list.
619  TestEventListeners* listeners() { return &listeners_; }
620 
621  // Returns the TestResult for the test that's currently running, or
622  // the TestResult for the ad hoc test if no test is running.
623  TestResult* current_test_result();
624 
625  // Returns the TestResult for the ad hoc test.
626  const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }
627 
628  // Sets the OS stack trace getter.
629  //
630  // Does nothing if the input and the current OS stack trace getter
631  // are the same; otherwise, deletes the old getter and makes the
632  // input the current getter.
633  void set_os_stack_trace_getter(OsStackTraceGetterInterface* getter);
634 
635  // Returns the current OS stack trace getter if it is not NULL;
636  // otherwise, creates an OsStackTraceGetter, makes it the current
637  // getter, and returns it.
638  OsStackTraceGetterInterface* os_stack_trace_getter();
639 
640  // Returns the current OS stack trace as an std::string.
641  //
642  // The maximum number of stack frames to be included is specified by
643  // the gtest_stack_trace_depth flag. The skip_count parameter
644  // specifies the number of top frames to be skipped, which doesn't
645  // count against the number of frames to be included.
646  //
647  // For example, if Foo() calls Bar(), which in turn calls
648  // CurrentOsStackTraceExceptTop(1), Foo() will be included in the
649  // trace but Bar() and CurrentOsStackTraceExceptTop() won't.
650  std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
651 
652  // Finds and returns a TestSuite with the given name. If one doesn't
653  // exist, creates one and returns it.
654  //
655  // Arguments:
656  //
657  // test_suite_name: name of the test suite
658  // type_param: the name of the test's type parameter, or NULL if
659  // this is not a typed or a type-parameterized test.
660  // set_up_tc: pointer to the function that sets up the test suite
661  // tear_down_tc: pointer to the function that tears down the test suite
662  TestSuite* GetTestSuite(const char* test_suite_name, const char* type_param,
664  internal::TearDownTestSuiteFunc tear_down_tc);
665 
666 // Legacy API is deprecated but still available
667 #ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
668  TestCase* GetTestCase(const char* test_case_name, const char* type_param,
670  internal::TearDownTestSuiteFunc tear_down_tc) {
671  return GetTestSuite(test_case_name, type_param, set_up_tc, tear_down_tc);
672  }
673 #endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
674 
675  // Adds a TestInfo to the unit test.
676  //
677  // Arguments:
678  //
679  // set_up_tc: pointer to the function that sets up the test suite
680  // tear_down_tc: pointer to the function that tears down the test suite
681  // test_info: the TestInfo object
682  void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc,
683  internal::TearDownTestSuiteFunc tear_down_tc,
684  TestInfo* test_info) {
685 #if GTEST_HAS_DEATH_TEST
686  // In order to support thread-safe death tests, we need to
687  // remember the original working directory when the test program
688  // was first invoked. We cannot do this in RUN_ALL_TESTS(), as
689  // the user may have changed the current directory before calling
690  // RUN_ALL_TESTS(). Therefore we capture the current directory in
691  // AddTestInfo(), which is called to register a TEST or TEST_F
692  // before main() is reached.
693  if (original_working_dir_.IsEmpty()) {
694  original_working_dir_.Set(FilePath::GetCurrentDir());
696  << "Failed to get the current working directory.";
697  }
698 #endif // GTEST_HAS_DEATH_TEST
699 
700  GetTestSuite(test_info->test_suite_name(), test_info->type_param(),
701  set_up_tc, tear_down_tc)
702  ->AddTestInfo(test_info);
703  }
704 
705  // Returns ParameterizedTestSuiteRegistry object used to keep track of
706  // value-parameterized tests and instantiate and register them.
707  internal::ParameterizedTestSuiteRegistry& parameterized_test_registry() {
708  return parameterized_test_registry_;
709  }
710 
711  std::set<std::string>* ignored_parameterized_test_suites() {
712  return &ignored_parameterized_test_suites_;
713  }
714 
715  // Returns TypeParameterizedTestSuiteRegistry object used to keep track of
716  // type-parameterized tests and instantiations of them.
717  internal::TypeParameterizedTestSuiteRegistry&
718  type_parameterized_test_registry() {
719  return type_parameterized_test_registry_;
720  }
721 
722  // Sets the TestSuite object for the test that's currently running.
723  void set_current_test_suite(TestSuite* a_current_test_suite) {
724  current_test_suite_ = a_current_test_suite;
725  }
726 
727  // Sets the TestInfo object for the test that's currently running. If
728  // current_test_info is NULL, the assertion results will be stored in
729  // ad_hoc_test_result_.
730  void set_current_test_info(TestInfo* a_current_test_info) {
731  current_test_info_ = a_current_test_info;
732  }
733 
734  // Registers all parameterized tests defined using TEST_P and
735  // INSTANTIATE_TEST_SUITE_P, creating regular tests for each test/parameter
736  // combination. This method can be called more then once; it has guards
737  // protecting from registering the tests more then once. If
738  // value-parameterized tests are disabled, RegisterParameterizedTests is
739  // present but does nothing.
740  void RegisterParameterizedTests();
741 
742  // Runs all tests in this UnitTest object, prints the result, and
743  // returns true if all tests are successful. If any exception is
744  // thrown during a test, this test is considered to be failed, but
745  // the rest of the tests will still be run.
746  bool RunAllTests();
747 
748  // Clears the results of all tests, except the ad hoc tests.
749  void ClearNonAdHocTestResult() {
750  ForEach(test_suites_, TestSuite::ClearTestSuiteResult);
751  }
752 
753  // Clears the results of ad-hoc test assertions.
754  void ClearAdHocTestResult() {
755  ad_hoc_test_result_.Clear();
756  }
757 
758  // Adds a TestProperty to the current TestResult object when invoked in a
759  // context of a test or a test suite, or to the global property set. If the
760  // result already contains a property with the same key, the value will be
761  // updated.
762  void RecordProperty(const TestProperty& test_property);
763 
764  enum ReactionToSharding {
765  HONOR_SHARDING_PROTOCOL,
766  IGNORE_SHARDING_PROTOCOL
767  };
768 
769  // Matches the full name of each test against the user-specified
770  // filter to decide whether the test should run, then records the
771  // result in each TestSuite and TestInfo object.
772  // If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
773  // based on sharding variables in the environment.
774  // Returns the number of tests that should run.
775  int FilterTests(ReactionToSharding shard_tests);
776 
777  // Prints the names of the tests matching the user-specified filter flag.
778  void ListTestsMatchingFilter();
779 
780  const TestSuite* current_test_suite() const { return current_test_suite_; }
781  TestInfo* current_test_info() { return current_test_info_; }
782  const TestInfo* current_test_info() const { return current_test_info_; }
783 
784  // Returns the vector of environments that need to be set-up/torn-down
785  // before/after the tests are run.
786  std::vector<Environment*>& environments() { return environments_; }
787 
788  // Getters for the per-thread Google Test trace stack.
789  std::vector<TraceInfo>& gtest_trace_stack() {
790  return *(gtest_trace_stack_.pointer());
791  }
792  const std::vector<TraceInfo>& gtest_trace_stack() const {
793  return gtest_trace_stack_.get();
794  }
795 
796 #if GTEST_HAS_DEATH_TEST
797  void InitDeathTestSubprocessControlInfo() {
798  internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
799  }
800  // Returns a pointer to the parsed --gtest_internal_run_death_test
801  // flag, or NULL if that flag was not specified.
802  // This information is useful only in a death test child process.
803  // Must not be called before a call to InitGoogleTest.
804  const InternalRunDeathTestFlag* internal_run_death_test_flag() const {
805  return internal_run_death_test_flag_.get();
806  }
807 
808  // Returns a pointer to the current death test factory.
809  internal::DeathTestFactory* death_test_factory() {
810  return death_test_factory_.get();
811  }
812 
813  void SuppressTestEventsIfInSubprocess();
814 
815  friend class ReplaceDeathTestFactory;
816 #endif // GTEST_HAS_DEATH_TEST
817 
818  // Initializes the event listener performing XML output as specified by
819  // UnitTestOptions. Must not be called before InitGoogleTest.
820  void ConfigureXmlOutput();
821 
822 #if GTEST_CAN_STREAM_RESULTS_
823  // Initializes the event listener for streaming test results to a socket.
824  // Must not be called before InitGoogleTest.
825  void ConfigureStreamingOutput();
826 #endif
827 
828  // Performs initialization dependent upon flag values obtained in
829  // ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
830  // ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
831  // this function is also called from RunAllTests. Since this function can be
832  // called more than once, it has to be idempotent.
833  void PostFlagParsingInit();
834 
835  // Gets the random seed used at the start of the current test iteration.
836  int random_seed() const { return random_seed_; }
837 
838  // Gets the random number generator.
839  internal::Random* random() { return &random_; }
840 
841  // Shuffles all test suites, and the tests within each test suite,
842  // making sure that death tests are still run first.
843  void ShuffleTests();
844 
845  // Restores the test suites and tests to their order before the first shuffle.
846  void UnshuffleTests();
847 
848  // Returns the value of GTEST_FLAG(catch_exceptions) at the moment
849  // UnitTest::Run() starts.
850  bool catch_exceptions() const { return catch_exceptions_; }
851 
852  private:
853  friend class ::testing::UnitTest;
854 
855  // Used by UnitTest::Run() to capture the state of
856  // GTEST_FLAG(catch_exceptions) at the moment it starts.
857  void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
858 
859  // The UnitTest object that owns this implementation object.
860  UnitTest* const parent_;
861 
862  // The working directory when the first TEST() or TEST_F() was
863  // executed.
865 
866  // The default test part result reporters.
867  DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
868  DefaultPerThreadTestPartResultReporter
869  default_per_thread_test_part_result_reporter_;
870 
871  // Points to (but doesn't own) the global test part result reporter.
872  TestPartResultReporterInterface* global_test_part_result_repoter_;
873 
874  // Protects read and write access to global_test_part_result_reporter_.
875  internal::Mutex global_test_part_result_reporter_mutex_;
876 
877  // Points to (but doesn't own) the per-thread test part result reporter.
878  internal::ThreadLocal<TestPartResultReporterInterface*>
879  per_thread_test_part_result_reporter_;
880 
881  // The vector of environments that need to be set-up/torn-down
882  // before/after the tests are run.
883  std::vector<Environment*> environments_;
884 
885  // The vector of TestSuites in their original order. It owns the
886  // elements in the vector.
887  std::vector<TestSuite*> test_suites_;
888 
889  // Provides a level of indirection for the test suite list to allow
890  // easy shuffling and restoring the test suite order. The i-th
891  // element of this vector is the index of the i-th test suite in the
892  // shuffled order.
893  std::vector<int> test_suite_indices_;
894 
895  // ParameterizedTestRegistry object used to register value-parameterized
896  // tests.
897  internal::ParameterizedTestSuiteRegistry parameterized_test_registry_;
898  internal::TypeParameterizedTestSuiteRegistry
899  type_parameterized_test_registry_;
900 
901  // The set holding the name of parameterized
902  // test suites that may go uninstantiated.
903  std::set<std::string> ignored_parameterized_test_suites_;
904 
905  // Indicates whether RegisterParameterizedTests() has been called already.
906  bool parameterized_tests_registered_;
907 
908  // Index of the last death test suite registered. Initially -1.
909  int last_death_test_suite_;
910 
911  // This points to the TestSuite for the currently running test. It
912  // changes as Google Test goes through one test suite after another.
913  // When no test is running, this is set to NULL and Google Test
914  // stores assertion results in ad_hoc_test_result_. Initially NULL.
915  TestSuite* current_test_suite_;
916 
917  // This points to the TestInfo for the currently running test. It
918  // changes as Google Test goes through one test after another. When
919  // no test is running, this is set to NULL and Google Test stores
920  // assertion results in ad_hoc_test_result_. Initially NULL.
921  TestInfo* current_test_info_;
922 
923  // Normally, a user only writes assertions inside a TEST or TEST_F,
924  // or inside a function called by a TEST or TEST_F. Since Google
925  // Test keeps track of which test is current running, it can
926  // associate such an assertion with the test it belongs to.
927  //
928  // If an assertion is encountered when no TEST or TEST_F is running,
929  // Google Test attributes the assertion result to an imaginary "ad hoc"
930  // test, and records the result in ad_hoc_test_result_.
931  TestResult ad_hoc_test_result_;
932 
933  // The list of event listeners that can be used to track events inside
934  // Google Test.
935  TestEventListeners listeners_;
936 
937  // The OS stack trace getter. Will be deleted when the UnitTest
938  // object is destructed. By default, an OsStackTraceGetter is used,
939  // but the user can set this field to use a custom getter if that is
940  // desired.
941  OsStackTraceGetterInterface* os_stack_trace_getter_;
942 
943  // True if and only if PostFlagParsingInit() has been called.
944  bool post_flag_parse_init_performed_;
945 
946  // The random number seed used at the beginning of the test run.
947  int random_seed_;
948 
949  // Our random number generator.
950  internal::Random random_;
951 
952  // The time of the test program start, in ms from the start of the
953  // UNIX epoch.
954  TimeInMillis start_timestamp_;
955 
956  // How long the test took to run, in milliseconds.
957  TimeInMillis elapsed_time_;
958 
959 #if GTEST_HAS_DEATH_TEST
960  // The decomposed components of the gtest_internal_run_death_test flag,
961  // parsed when RUN_ALL_TESTS is called.
962  std::unique_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
963  std::unique_ptr<internal::DeathTestFactory> death_test_factory_;
964 #endif // GTEST_HAS_DEATH_TEST
965 
966  // A per-thread stack of traces created by the SCOPED_TRACE() macro.
967  internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
968 
969  // The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
970  // starts.
971  bool catch_exceptions_;
972 
973  GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
974 }; // class UnitTestImpl
975 
976 // Convenience function for accessing the global UnitTest
977 // implementation object.
978 inline UnitTestImpl* GetUnitTestImpl() {
979  return UnitTest::GetInstance()->impl();
980 }
981 
982 #if GTEST_USES_SIMPLE_RE
983 
984 // Internal helper functions for implementing the simple regular
985 // expression matcher.
986 GTEST_API_ bool IsInSet(char ch, const char* str);
987 GTEST_API_ bool IsAsciiDigit(char ch);
988 GTEST_API_ bool IsAsciiPunct(char ch);
989 GTEST_API_ bool IsRepeat(char ch);
990 GTEST_API_ bool IsAsciiWhiteSpace(char ch);
991 GTEST_API_ bool IsAsciiWordChar(char ch);
992 GTEST_API_ bool IsValidEscape(char ch);
993 GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
994 GTEST_API_ bool ValidateRegex(const char* regex);
995 GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
996 GTEST_API_ bool MatchRepetitionAndRegexAtHead(
997  bool escaped, char ch, char repeat, const char* regex, const char* str);
998 GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
999 
1000 #endif // GTEST_USES_SIMPLE_RE
1001 
1002 // Parses the command line for Google Test flags, without initializing
1003 // other parts of Google Test.
1004 GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
1005 GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
1006 
1007 #if GTEST_HAS_DEATH_TEST
1008 
1009 // Returns the message describing the last system error, regardless of the
1010 // platform.
1011 GTEST_API_ std::string GetLastErrnoDescription();
1012 
1013 // Attempts to parse a string into a positive integer pointed to by the
1014 // number parameter. Returns true if that is possible.
1015 // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
1016 // it here.
1017 template <typename Integer>
1018 bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
1019  // Fail fast if the given string does not begin with a digit;
1020  // this bypasses strtoXXX's "optional leading whitespace and plus
1021  // or minus sign" semantics, which are undesirable here.
1022  if (str.empty() || !IsDigit(str[0])) {
1023  return false;
1024  }
1025  errno = 0;
1026 
1027  char* end;
1028  // BiggestConvertible is the largest integer type that system-provided
1029  // string-to-number conversion routines can return.
1030  using BiggestConvertible = unsigned long long; // NOLINT
1031 
1032  const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10); // NOLINT
1033  const bool parse_success = *end == '\0' && errno == 0;
1034 
1035  GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
1036 
1037  const Integer result = static_cast<Integer>(parsed);
1038  if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
1039  *number = result;
1040  return true;
1041  }
1042  return false;
1043 }
1044 #endif // GTEST_HAS_DEATH_TEST
1045 
1046 // TestResult contains some private methods that should be hidden from
1047 // Google Test user but are required for testing. This class allow our tests
1048 // to access them.
1049 //
1050 // This class is supplied only for the purpose of testing Google Test's own
1051 // constructs. Do not use it in user tests, either directly or indirectly.
1052 class TestResultAccessor {
1053  public:
1054  static void RecordProperty(TestResult* test_result,
1055  const std::string& xml_element,
1056  const TestProperty& property) {
1057  test_result->RecordProperty(xml_element, property);
1058  }
1059 
1060  static void ClearTestPartResults(TestResult* test_result) {
1061  test_result->ClearTestPartResults();
1062  }
1063 
1064  static const std::vector<testing::TestPartResult>& test_part_results(
1065  const TestResult& test_result) {
1066  return test_result.test_part_results();
1067  }
1068 };
1069 
1070 #if GTEST_CAN_STREAM_RESULTS_
1071 
1072 // Streams test results to the given port on the given host machine.
1073 class StreamingListener : public EmptyTestEventListener {
1074  public:
1075  // Abstract base class for writing strings to a socket.
1076  class AbstractSocketWriter {
1077  public:
1078  virtual ~AbstractSocketWriter() {}
1079 
1080  // Sends a string to the socket.
1081  virtual void Send(const std::string& message) = 0;
1082 
1083  // Closes the socket.
1084  virtual void CloseConnection() {}
1085 
1086  // Sends a string and a newline to the socket.
1087  void SendLn(const std::string& message) { Send(message + "\n"); }
1088  };
1089 
1090  // Concrete class for actually writing strings to a socket.
1091  class SocketWriter : public AbstractSocketWriter {
1092  public:
1093  SocketWriter(const std::string& host, const std::string& port)
1094  : sockfd_(-1), host_name_(host), port_num_(port) {
1095  MakeConnection();
1096  }
1097 
1098  ~SocketWriter() override {
1099  if (sockfd_ != -1)
1100  CloseConnection();
1101  }
1102 
1103  // Sends a string to the socket.
1104  void Send(const std::string& message) override {
1105  GTEST_CHECK_(sockfd_ != -1)
1106  << "Send() can be called only when there is a connection.";
1107 
1108  const auto len = static_cast<size_t>(message.length());
1109  if (write(sockfd_, message.c_str(), len) != static_cast<ssize_t>(len)) {
1111  << "stream_result_to: failed to stream to "
1112  << host_name_ << ":" << port_num_;
1113  }
1114  }
1115 
1116  private:
1117  // Creates a client socket and connects to the server.
1118  void MakeConnection();
1119 
1120  // Closes the socket.
1121  void CloseConnection() override {
1122  GTEST_CHECK_(sockfd_ != -1)
1123  << "CloseConnection() can be called only when there is a connection.";
1124 
1125  close(sockfd_);
1126  sockfd_ = -1;
1127  }
1128 
1129  int sockfd_; // socket file descriptor
1130  const std::string host_name_;
1131  const std::string port_num_;
1132 
1133  GTEST_DISALLOW_COPY_AND_ASSIGN_(SocketWriter);
1134  }; // class SocketWriter
1135 
1136  // Escapes '=', '&', '%', and '\n' characters in str as "%xx".
1137  static std::string UrlEncode(const char* str);
1138 
1139  StreamingListener(const std::string& host, const std::string& port)
1140  : socket_writer_(new SocketWriter(host, port)) {
1141  Start();
1142  }
1143 
1144  explicit StreamingListener(AbstractSocketWriter* socket_writer)
1145  : socket_writer_(socket_writer) { Start(); }
1146 
1147  void OnTestProgramStart(const UnitTest& /* unit_test */) override {
1148  SendLn("event=TestProgramStart");
1149  }
1150 
1151  void OnTestProgramEnd(const UnitTest& unit_test) override {
1152  // Note that Google Test current only report elapsed time for each
1153  // test iteration, not for the entire test program.
1154  SendLn("event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
1155 
1156  // Notify the streaming server to stop.
1157  socket_writer_->CloseConnection();
1158  }
1159 
1160  void OnTestIterationStart(const UnitTest& /* unit_test */,
1161  int iteration) override {
1162  SendLn("event=TestIterationStart&iteration=" +
1163  StreamableToString(iteration));
1164  }
1165 
1166  void OnTestIterationEnd(const UnitTest& unit_test,
1167  int /* iteration */) override {
1168  SendLn("event=TestIterationEnd&passed=" +
1169  FormatBool(unit_test.Passed()) + "&elapsed_time=" +
1170  StreamableToString(unit_test.elapsed_time()) + "ms");
1171  }
1172 
1173  // Note that "event=TestCaseStart" is a wire format and has to remain
1174  // "case" for compatibilty
1175  void OnTestCaseStart(const TestCase& test_case) override {
1176  SendLn(std::string("event=TestCaseStart&name=") + test_case.name());
1177  }
1178 
1179  // Note that "event=TestCaseEnd" is a wire format and has to remain
1180  // "case" for compatibilty
1181  void OnTestCaseEnd(const TestCase& test_case) override {
1182  SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed()) +
1183  "&elapsed_time=" + StreamableToString(test_case.elapsed_time()) +
1184  "ms");
1185  }
1186 
1187  void OnTestStart(const TestInfo& test_info) override {
1188  SendLn(std::string("event=TestStart&name=") + test_info.name());
1189  }
1190 
1191  void OnTestEnd(const TestInfo& test_info) override {
1192  SendLn("event=TestEnd&passed=" +
1193  FormatBool((test_info.result())->Passed()) +
1194  "&elapsed_time=" +
1195  StreamableToString((test_info.result())->elapsed_time()) + "ms");
1196  }
1197 
1198  void OnTestPartResult(const TestPartResult& test_part_result) override {
1199  const char* file_name = test_part_result.file_name();
1200  if (file_name == nullptr) file_name = "";
1201  SendLn("event=TestPartResult&file=" + UrlEncode(file_name) +
1202  "&line=" + StreamableToString(test_part_result.line_number()) +
1203  "&message=" + UrlEncode(test_part_result.message()));
1204  }
1205 
1206  private:
1207  // Sends the given message and a newline to the socket.
1208  void SendLn(const std::string& message) { socket_writer_->SendLn(message); }
1209 
1210  // Called at the start of streaming to notify the receiver what
1211  // protocol we are using.
1212  void Start() { SendLn("gtest_streaming_protocol_version=1.0"); }
1213 
1214  std::string FormatBool(bool value) { return value ? "1" : "0"; }
1215 
1216  const std::unique_ptr<AbstractSocketWriter> socket_writer_;
1217 
1218  GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener);
1219 }; // class StreamingListener
1220 
1221 #endif // GTEST_CAN_STREAM_RESULTS_
1222 
1223 } // namespace internal
1224 } // namespace testing
1225 
1227 
1228 #endif // GTEST_SRC_GTEST_INTERNAL_INL_H_
xds_interop_client.str
str
Definition: xds_interop_client.py:487
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
flag
uint32_t flag
Definition: ssl_versions.cc:162
testing
Definition: aws_request_signer_test.cc:25
testing::internal::kStreamResultToFlag
const char kStreamResultToFlag[]
Definition: gmock-gtest-all.cc:508
regen-readme.it
it
Definition: regen-readme.py:15
env_var
Definition: win/process.c:40
testing::internal::ShouldRunTestOnShard
bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5485
check_tracer_sanity.pattern
pattern
Definition: check_tracer_sanity.py:25
file
const grpc_generator::File * file
Definition: python_private_generator.h:38
testing::internal::kListTestsFlag
const char kListTestsFlag[]
Definition: gmock-gtest-all.cc:501
RunAllTests
int RunAllTests()
Definition: bloaty/third_party/googletest/googletest/test/googletest-output-test_.cc:362
GTEST_API_
#define GTEST_API_
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:754
begin
char * begin
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1007
write
#define write
Definition: test-fs.c:47
GTEST_DISABLE_MSC_WARNINGS_PUSH_
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251) namespace testing
Definition: boringssl-with-bazel/src/third_party/googletest/src/gtest-internal-inl.h:64
testing::internal::TearDownTestSuiteFunc
void(*)() TearDownTestSuiteFunc
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:478
string.h
seed
static const uint8_t seed[20]
Definition: dsa_test.cc:79
testing::internal::GetUnitTestImpl
UnitTestImpl * GetUnitTestImpl()
Definition: gmock-gtest-all.cc:1334
testing::internal::TypeId
const typedef void * TypeId
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:405
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
testing::internal::GetNextRandomSeed
int GetNextRandomSeed(int seed)
Definition: gmock-gtest-all.cc:559
testing::internal::kAlsoRunDisabledTestsFlag
const char kAlsoRunDisabledTestsFlag[]
Definition: gmock-gtest-all.cc:496
setup.name
name
Definition: setup.py:542
grpc_core::ForEach
for_each_detail::ForEach< Reader, Action > ForEach(Reader reader, Action action)
For each item acquired by calling Reader::Next, run the promise Action.
Definition: for_each.h:133
original_working_dir_
FilePath original_working_dir_
Definition: bloaty/third_party/googletest/googletest/test/googletest-options-test.cc:140
grpc::testing::test_result
test_result
Definition: h2_ssl_cert_test.cc:201
testing::internal::GetElementOr
E GetElementOr(const std::vector< E > &v, int i, E default_value)
Definition: gmock-gtest-all.cc:710
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
GTEST_NO_INLINE_
#define GTEST_NO_INLINE_
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:765
T
#define T(upbtypeconst, upbtype, ctype, default_value)
namespace
Definition: namespace.py:1
testing::internal::ShouldUseColor
bool ShouldUseColor(bool stdout_is_tty)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:2996
testing::internal::ShouldShard
bool ShouldShard(const char *total_shards_env, const char *shard_index_env, bool in_subprocess_for_death_test)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5422
GTEST_LOG_
#define GTEST_LOG_(severity)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:975
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
testing::internal::StreamableToString
std::string StreamableToString(const T &streamable)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest-message.h:209
absl::debugging_internal::IsDigit
static bool IsDigit(char c)
Definition: abseil-cpp/absl/debugging/internal/demangle.cc:383
GTEST_ATTRIBUTE_UNUSED_
#define GTEST_ATTRIBUTE_UNUSED_
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:655
ssize_t
intptr_t ssize_t
Definition: win.h:27
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
testing::internal::kTestTypeIdInGoogleTest
const TypeId kTestTypeIdInGoogleTest
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/src/gtest.cc:653
testing::internal::FormatTimeInMillisAsSeconds
std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:3715
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
testing::internal::CodePointToUtf8
std::string CodePointToUtf8(UInt32 code_point)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1770
setup.v
v
Definition: third_party/bloaty/third_party/capstone/bindings/python/setup.py:42
testing::internal::WideStringToUtf8
std::string WideStringToUtf8(const wchar_t *str, int num_chars)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:1837
number
int32_t number
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:850
testing::internal::kBreakOnFailureFlag
const char kBreakOnFailureFlag[]
Definition: gmock-gtest-all.cc:497
std::swap
void swap(Json::Value &a, Json::Value &b)
Specialize std::swap() for Json::Value.
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:1226
close
#define close
Definition: test-fs.c:48
testing::TimeInMillis
internal::TimeInMillis TimeInMillis
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:519
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
testing::internal::Int32FromEnvOrDie
Int32 Int32FromEnvOrDie(const char *var, Int32 default_val)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5467
key_
RlsLb::RequestKey key_
Definition: rls.cc:659
google::protobuf::WARNING
static const LogLevel WARNING
Definition: bloaty/third_party/protobuf/src/google/protobuf/testing/googletest.h:71
testing::internal::kRandomSeedFlag
const char kRandomSeedFlag[]
Definition: gmock-gtest-all.cc:504
TestCase
Definition: benchmark/test/output_test.h:31
TestSuite
Definition: cavp_main.cc:32
Delete
void Delete(T *t)
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:208
testing::internal::GetCurrentExecutableName
FilePath GetCurrentExecutableName()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:429
testing::internal::GetTimeInMillis
TimeInMillis GetTimeInMillis()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:836
testing::internal::kRepeatFlag
const char kRepeatFlag[]
Definition: gmock-gtest-all.cc:505
testing::internal::ParseGoogleTestFlagsOnly
void ParseGoogleTestFlagsOnly(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6053
GTEST_DISALLOW_COPY_AND_ASSIGN_
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:683
tests.unit._exit_scenarios.port
port
Definition: _exit_scenarios.py:179
value
const char * value
Definition: hpack_parser_table.cc:165
output_
std::string output_
Definition: json_writer.cc:76
GTEST_FLAG
#define GTEST_FLAG(name)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2169
GTEST_CHECK_
#define GTEST_CHECK_(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:999
key
const char * key
Definition: hpack_parser_table.cc:164
testing::internal::kFilterFlag
const char kFilterFlag[]
Definition: gmock-gtest-all.cc:500
testing::internal::Shuffle
void Shuffle(internal::Random *random, std::vector< E > *v)
Definition: gmock-gtest-all.cc:740
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
testing::internal::kMaxRandomSeed
const int kMaxRandomSeed
Definition: gmock-gtest-all.cc:513
testing::internal::ShuffleRange
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
Definition: gmock-gtest-all.cc:719
index
int index
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:1184
testing::internal::kStackTraceDepthFlag
const char kStackTraceDepthFlag[]
Definition: gmock-gtest-all.cc:507
google::protobuf.internal::Mutex
WrappedMutex Mutex
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/mutex.h:113
testing::internal::SetUpTestSuiteFunc
void(*)() SetUpTestSuiteFunc
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-internal.h:477
testing::internal::PatternMatchesString
static bool PatternMatchesString(const std::string &name_str, const char *pattern, const char *pattern_end)
Definition: googletest/googletest/src/gtest.cc:682
testing::internal::kShuffleFlag
const char kShuffleFlag[]
Definition: gmock-gtest-all.cc:506
regen-readme.line
line
Definition: regen-readme.py:30
testing::internal::kOutputFlag
const char kOutputFlag[]
Definition: gmock-gtest-all.cc:502
absl::base_internal::Random
static int Random(uint32_t *state)
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:122
GTEST_DISABLE_MSC_WARNINGS_POP_
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:309
testing::internal::kCatchExceptionsFlag
const char kCatchExceptionsFlag[]
Definition: gmock-gtest-all.cc:498
testing::internal::kThrowOnFailureFlag
const char kThrowOnFailureFlag[]
Definition: gmock-gtest-all.cc:509
testing::internal::kFlagfileFlag
const char kFlagfileFlag[]
Definition: gmock-gtest-all.cc:510
testing::internal::CountIf
int CountIf(const Container &c, Predicate predicate)
Definition: gmock-gtest-all.cc:690
internal
Definition: benchmark/test/output_test_helper.cc:20
testing::internal::kColorFlag
const char kColorFlag[]
Definition: gmock-gtest-all.cc:499
GTEST_DECLARE_bool_
#define GTEST_DECLARE_bool_(name)
Definition: bloaty/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:2180
mutex_
internal::WrappedMutex mutex_
Definition: bloaty/third_party/protobuf/src/google/protobuf/message.cc:569
ch
char ch
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3621
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
parent_
RefCountedPtr< GrpcLb > parent_
Definition: grpclb.cc:438
benchmark::ParseInt32Flag
bool ParseInt32Flag(const char *str, const char *flag, int32_t *value)
Definition: benchmark/src/commandlineflags.cc:216
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
testing::internal::FormatEpochTimeInMillisAsIso8601
std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:3738
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
google::protobuf::compiler::objectivec::FilePath
string FilePath(const FileDescriptor *file)
Definition: bloaty/third_party/protobuf/src/google/protobuf/compiler/objectivec/objectivec_helpers.cc:404
testing::internal::kPrintTimeFlag
const char kPrintTimeFlag[]
Definition: gmock-gtest-all.cc:503
testing::internal::WriteToShardStatusFileIfNeeded
void WriteToShardStatusFileIfNeeded()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:5400
testing::internal::g_help_flag
bool g_help_flag
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:182
errno.h
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
testing::internal::GetRandomSeedFromFlag
int GetRandomSeedFromFlag(Int32 random_seed_flag)
Definition: gmock-gtest-all.cc:543
google::protobuf.internal.decoder.long
long
Definition: bloaty/third_party/protobuf/python/google/protobuf/internal/decoder.py:89


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:46