gtest/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 //
32 // Author: wan@google.com (Zhanyong Wan)
33 //
34 // This file contains purely Google Test's internal implementation. Please
35 // DO NOT #INCLUDE IT IN A USER PROGRAM.
36 
37 #ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
38 #define GTEST_SRC_GTEST_INTERNAL_INL_H_
39 
40 // GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
41 // part of Google Test's implementation; otherwise it's undefined.
42 #if !GTEST_IMPLEMENTATION_
43 // A user is trying to include this from his code - just say no.
44 # error "gtest-internal-inl.h is part of Google Test's internal implementation."
45 # error "It must not be included except by Google Test itself."
46 #endif // GTEST_IMPLEMENTATION_
47 
48 #ifndef _WIN32_WCE
49 # include <errno.h>
50 #endif // !_WIN32_WCE
51 #include <stddef.h>
52 #include <stdlib.h> // For strtoll/_strtoul64/malloc/free.
53 #include <string.h> // For memmove.
54 
55 #include <algorithm>
56 #include <string>
57 #include <vector>
58 
59 #include "gtest/internal/gtest-port.h"
60 
61 #if GTEST_CAN_STREAM_RESULTS_
62 # include <arpa/inet.h> // NOLINT
63 # include <netdb.h> // NOLINT
64 #endif
65 
66 #if GTEST_OS_WINDOWS
67 # include <windows.h> // NOLINT
68 #endif // GTEST_OS_WINDOWS
69 
70 #include "gtest/gtest.h" // NOLINT
71 #include "gtest/gtest-spi.h"
72 
73 namespace testing
74 {
75 
76 // Declares the flags.
77 //
78 // We don't want the users to modify this flag in the code, but want
79 // Google Test's own unit tests to be able to access it. Therefore we
80 // declare it here as opposed to in gtest.h.
81 GTEST_DECLARE_bool_(death_test_use_fork);
82 
83 namespace internal
84 {
85 
86 // The value of GetTestTypeId() as seen from within the Google Test
87 // library. This is solely for testing GetTestTypeId().
89 
90 // Names of the flags (needed for parsing Google Test flags).
91 const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
92 const char kBreakOnFailureFlag[] = "break_on_failure";
93 const char kCatchExceptionsFlag[] = "catch_exceptions";
94 const char kColorFlag[] = "color";
95 const char kFilterFlag[] = "filter";
96 const char kListTestsFlag[] = "list_tests";
97 const char kOutputFlag[] = "output";
98 const char kPrintTimeFlag[] = "print_time";
99 const char kRandomSeedFlag[] = "random_seed";
100 const char kRepeatFlag[] = "repeat";
101 const char kShuffleFlag[] = "shuffle";
102 const char kStackTraceDepthFlag[] = "stack_trace_depth";
103 const char kStreamResultToFlag[] = "stream_result_to";
104 const char kThrowOnFailureFlag[] = "throw_on_failure";
105 
106 // A valid random seed must be in [1, kMaxRandomSeed].
107 const int kMaxRandomSeed = 99999;
108 
109 // g_help_flag is true iff the --help flag or an equivalent form is
110 // specified on the command line.
111 GTEST_API_ extern bool g_help_flag;
112 
113 // Returns the current time in milliseconds.
115 
116 // Returns true iff Google Test should use colors in the output.
117 GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
118 
119 // Formats the given time in milliseconds as seconds.
121 
122 // Converts the given time in milliseconds to a date string in the ISO 8601
123 // format, without the timezone information. N.B.: due to the use the
124 // non-reentrant localtime() function, this function is not thread safe. Do
125 // not use it in any code that can be called from multiple threads.
127 
128 // Parses a string for an Int32 flag, in the form of "--flag=value".
129 //
130 // On success, stores the value of the flag in *value, and returns
131 // true. On failure, returns false without changing *value.
133  const char * str, const char * flag, Int32 * value);
134 
135 // Returns a random seed in range [1, kMaxRandomSeed] based on the
136 // given --gtest_random_seed flag value.
137 inline int GetRandomSeedFromFlag(Int32 random_seed_flag)
138 {
139  const unsigned int raw_seed = (random_seed_flag == 0) ?
140  static_cast<unsigned int>(GetTimeInMillis()) :
141  static_cast<unsigned int>(random_seed_flag);
142 
143  // Normalizes the actual seed to range [1, kMaxRandomSeed] such that
144  // it's easy to type.
145  const int normalized_seed =
146  static_cast<int>((raw_seed - 1U) %
147  static_cast<unsigned int>(kMaxRandomSeed)) + 1;
148  return normalized_seed;
149 }
150 
151 // Returns the first valid random seed after 'seed'. The behavior is
152 // undefined if 'seed' is invalid. The seed after kMaxRandomSeed is
153 // considered to be 1.
154 inline int GetNextRandomSeed(int seed)
155 {
156  GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)
157  << "Invalid random seed " << seed << " - must be in [1, "
158  << kMaxRandomSeed << "].";
159  const int next_seed = seed + 1;
160  return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
161 }
162 
163 // This class saves the values of all Google Test flags in its c'tor, and
164 // restores them in its d'tor.
165 class GTestFlagSaver
166 {
167 public:
168  // The c'tor.
170  {
171  also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
172  break_on_failure_ = GTEST_FLAG(break_on_failure);
173  catch_exceptions_ = GTEST_FLAG(catch_exceptions);
174  color_ = GTEST_FLAG(color);
175  death_test_style_ = GTEST_FLAG(death_test_style);
176  death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
177  filter_ = GTEST_FLAG(filter);
178  internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
179  list_tests_ = GTEST_FLAG(list_tests);
181  print_time_ = GTEST_FLAG(print_time);
182  random_seed_ = GTEST_FLAG(random_seed);
183  repeat_ = GTEST_FLAG(repeat);
184  shuffle_ = GTEST_FLAG(shuffle);
185  stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
186  stream_result_to_ = GTEST_FLAG(stream_result_to);
187  throw_on_failure_ = GTEST_FLAG(throw_on_failure);
188  }
189 
190  // The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
192  {
193  GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
194  GTEST_FLAG(break_on_failure) = break_on_failure_;
195  GTEST_FLAG(catch_exceptions) = catch_exceptions_;
196  GTEST_FLAG(color) = color_;
197  GTEST_FLAG(death_test_style) = death_test_style_;
198  GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
199  GTEST_FLAG(filter) = filter_;
200  GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
201  GTEST_FLAG(list_tests) = list_tests_;
203  GTEST_FLAG(print_time) = print_time_;
204  GTEST_FLAG(random_seed) = random_seed_;
205  GTEST_FLAG(repeat) = repeat_;
206  GTEST_FLAG(shuffle) = shuffle_;
207  GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
208  GTEST_FLAG(stream_result_to) = stream_result_to_;
209  GTEST_FLAG(throw_on_failure) = throw_on_failure_;
210  }
211 
212 private:
213  // Fields for saving the original values of flags.
215  bool break_on_failure_;
216  bool catch_exceptions_;
222  bool list_tests_;
224  bool print_time_;
227  bool shuffle_;
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, Symbian OS)
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 an Int32. If it is unset,
273 // returns default_val. If it is not an Int32, prints an error and
274 // and aborts.
275 GTEST_API_ Int32 Int32FromEnvOrDie(const char * env_var, Int32 default_val);
276 
277 // Given the total number of shards, the shard index, and the test id,
278 // returns true iff the test should be run on this shard. The test id is
279 // 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 {
291  // Implemented as an explicit loop since std::count_if() in libCstd on
292  // Solaris has a non-standard signature.
293  int count = 0;
294 
295  for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it)
296  {
297  if (predicate(*it))
298  { ++count; }
299  }
300 
301  return count;
302 }
303 
304 // Applies a function/functor to each element in the container.
305 template <class Container, typename Functor>
306 void ForEach(const Container & c, Functor functor)
307 {
308  std::for_each(c.begin(), c.end(), functor);
309 }
310 
311 // Returns the i-th element of the vector, or default_value if i is not
312 // in range [0, v.size()).
313 template <typename E>
314 inline E GetElementOr(const std::vector<E> & v, int i, E default_value)
315 {
316  return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
317 }
318 
319 // Performs an in-place shuffle of a range of the vector's elements.
320 // 'begin' and 'end' are element indices as an STL-style range;
321 // i.e. [begin, end) are shuffled, where 'end' == size() means to
322 // shuffle to the end of the vector.
323 template <typename E>
324 void ShuffleRange(internal::Random * random, int begin, int end,
325  std::vector<E> * v)
326 {
327  const int size = static_cast<int>(v->size());
328  GTEST_CHECK_(0 <= begin && begin <= size)
329  << "Invalid shuffle range start " << begin << ": must be in range [0, "
330  << size << "].";
331  GTEST_CHECK_(begin <= end && end <= size)
332  << "Invalid shuffle range finish " << end << ": must be in range ["
333  << begin << ", " << size << "].";
334 
335  // Fisher-Yates shuffle, from
336  // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
337  for (int range_width = end - begin; range_width >= 2; range_width--)
338  {
339  const int last_in_range = begin + range_width - 1;
340  const int selected = begin + random->Generate(range_width);
341  std::swap((*v)[selected], (*v)[last_in_range]);
342  }
343 }
344 
345 // Performs an in-place shuffle of the vector's elements.
346 template <typename E>
347 inline void Shuffle(internal::Random * random, std::vector<E> * v)
348 {
349  ShuffleRange(random, 0, static_cast<int>(v->size()), v);
350 }
351 
352 // A function for deleting an object. Handy for being used as a
353 // functor.
354 template <typename T>
355 static void Delete(T * x)
356 {
357  delete x;
358 }
359 
360 // A predicate that checks the key of a TestProperty against a known key.
361 //
362 // TestPropertyKeyIs is copyable.
363 class TestPropertyKeyIs
364 {
365 public:
366  // Constructor.
367  //
368  // TestPropertyKeyIs has NO default constructor.
369  explicit TestPropertyKeyIs(const std::string & key) : key_(key) {}
370 
371  // Returns true iff the test name of test property matches on key_.
372  bool operator()(const TestProperty & test_property) const
373  {
374  return test_property.key() == key_;
375  }
376 
377 private:
378  std::string key_;
379 };
380 
381 // Class UnitTestOptions.
382 //
383 // This class contains functions for processing options the user
384 // specifies when running the tests. It has only static members.
385 //
386 // In most cases, the user can specify an option using either an
387 // environment variable or a command line flag. E.g. you can set the
388 // test filter using either GTEST_FILTER or --gtest_filter. If both
389 // the variable and the flag are present, the latter overrides the
390 // former.
391 class GTEST_API_ UnitTestOptions
392 {
393 public:
394  // Functions for processing the gtest_output flag.
395 
396  // Returns the output format, or "" for normal printed output.
397  static std::string GetOutputFormat();
398 
399  // Returns the absolute path of the requested output file, or the
400  // default (test_detail.xml in the original working directory) if
401  // none was explicitly specified.
402  static std::string GetAbsolutePathToOutputFile();
403 
404  // Functions for processing the gtest_filter flag.
405 
406  // Returns true iff the wildcard pattern matches the string. The
407  // first ':' or '\0' character in pattern marks the end of it.
408  //
409  // This recursive algorithm isn't very efficient, but is clear and
410  // works well enough for matching test names, which are short.
411  static bool PatternMatchesString(const char * pattern, const char * str);
412 
413  // Returns true iff the user-specified filter matches the test case
414  // name and the test name.
415  static bool FilterMatchesTest(const std::string & test_case_name,
416  const std::string & test_name);
417 
418 #if GTEST_OS_WINDOWS
419  // Function for supporting the gtest_catch_exception flag.
420 
421  // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
422  // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
423  // This function is useful as an __except condition.
424  static int GTestShouldProcessSEH(DWORD exception_code);
425 #endif // GTEST_OS_WINDOWS
426 
427  // Returns true if "name" matches the ':' separated list of glob-style
428  // filters in "filter".
429  static bool MatchesFilter(const std::string & name, const char * filter);
430 };
431 
432 // Returns the current application's name, removing directory path if that
433 // is present. Used by UnitTestOptions::GetOutputFile.
435 
436 // The role interface for getting the OS stack trace as a string.
438 {
439 public:
442 
443  // Returns the current OS stack trace as an std::string. Parameters:
444  //
445  // max_depth - the maximum number of stack frames to be included
446  // in the trace.
447  // skip_count - the number of top frames to be skipped; doesn't count
448  // against max_depth.
449  virtual string CurrentStackTrace(int max_depth, int skip_count) = 0;
450 
451  // UponLeavingGTest() should be called immediately before Google Test calls
452  // user code. It saves some information about the current stack that
453  // CurrentStackTrace() will use to find and hide Google Test stack frames.
454  virtual void UponLeavingGTest() = 0;
455 
456 private:
458 };
459 
460 // A working implementation of the OsStackTraceGetterInterface interface.
462 {
463 public:
464  OsStackTraceGetter() : caller_frame_(NULL) {}
465 
466  virtual string CurrentStackTrace(int max_depth, int skip_count)
467  GTEST_LOCK_EXCLUDED_(mutex_);
468 
469  virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_);
470 
471  // This string is inserted in place of stack frames that are part of
472  // Google Test's implementation.
473  static const char * const kElidedFramesMarker;
474 
475 private:
476  Mutex mutex_; // protects all internal state
477 
478  // We save the stack frame below the frame that calls user code.
479  // We do this because the address of the frame immediately below
480  // the user code changes between the call to UponLeavingGTest()
481  // and any calls to CurrentStackTrace() from within the user code.
482  void * caller_frame_;
483 
485 };
486 
487 // Information about a Google Test trace point.
488 struct TraceInfo
489 {
490  const char * file;
491  int line;
493 };
494 
495 // This is the default global test part result reporter used in UnitTestImpl.
496 // This class should only be used by UnitTestImpl.
499 {
500 public:
502  // Implements the TestPartResultReporterInterface. Reports the test part
503  // result in the current test.
504  virtual void ReportTestPartResult(const TestPartResult & result);
505 
506 private:
507  UnitTestImpl * const unit_test_;
508 
510 };
511 
512 // This is the default per thread test part result reporter used in
513 // UnitTestImpl. This class should only be used by UnitTestImpl.
516 {
517 public:
519  // Implements the TestPartResultReporterInterface. The implementation just
520  // delegates to the current global test part result reporter of *unit_test_.
521  virtual void ReportTestPartResult(const TestPartResult & result);
522 
523 private:
524  UnitTestImpl * const unit_test_;
525 
527 };
528 
529 // The private implementation of the UnitTest class. We don't protect
530 // the methods under a mutex, as this class is not accessible by a
531 // user and the UnitTest class that delegates work to this class does
532 // proper locking.
533 class GTEST_API_ UnitTestImpl
534 {
535 public:
536  explicit UnitTestImpl(UnitTest * parent);
537  virtual ~UnitTestImpl();
538 
539  // There are two different ways to register your own TestPartResultReporter.
540  // You can register your own repoter to listen either only for test results
541  // from the current thread or for results from all threads.
542  // By default, each per-thread test result repoter just passes a new
543  // TestPartResult to the global test result reporter, which registers the
544  // test part result for the currently running test.
545 
546  // Returns the global test part result reporter.
547  TestPartResultReporterInterface * GetGlobalTestPartResultReporter();
548 
549  // Sets the global test part result reporter.
550  void SetGlobalTestPartResultReporter(
552 
553  // Returns the test part result reporter for the current thread.
554  TestPartResultReporterInterface * GetTestPartResultReporterForCurrentThread();
555 
556  // Sets the test part result reporter for the current thread.
557  void SetTestPartResultReporterForCurrentThread(
559 
560  // Gets the number of successful test cases.
561  int successful_test_case_count() const;
562 
563  // Gets the number of failed test cases.
564  int failed_test_case_count() const;
565 
566  // Gets the number of all test cases.
567  int total_test_case_count() const;
568 
569  // Gets the number of all test cases that contain at least one test
570  // that should run.
571  int test_case_to_run_count() const;
572 
573  // Gets the number of successful tests.
574  int successful_test_count() const;
575 
576  // Gets the number of failed tests.
577  int failed_test_count() const;
578 
579  // Gets the number of disabled tests that will be reported in the XML report.
580  int reportable_disabled_test_count() const;
581 
582  // Gets the number of disabled tests.
583  int disabled_test_count() const;
584 
585  // Gets the number of tests to be printed in the XML report.
586  int reportable_test_count() const;
587 
588  // Gets the number of all tests.
589  int total_test_count() const;
590 
591  // Gets the number of tests that should run.
592  int test_to_run_count() const;
593 
594  // Gets the time of the test program start, in ms from the start of the
595  // UNIX epoch.
596  TimeInMillis start_timestamp() const { return start_timestamp_; }
597 
598  // Gets the elapsed time, in milliseconds.
599  TimeInMillis elapsed_time() const { return elapsed_time_; }
600 
601  // Returns true iff the unit test passed (i.e. all test cases passed).
602  bool Passed() const { return !Failed(); }
603 
604  // Returns true iff the unit test failed (i.e. some test case failed
605  // or something outside of all tests failed).
606  bool Failed() const
607  {
608  return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
609  }
610 
611  // Gets the i-th test case among all the test cases. i can range from 0 to
612  // total_test_case_count() - 1. If i is not in that range, returns NULL.
613  const TestCase * GetTestCase(int i) const
614  {
615  const int index = GetElementOr(test_case_indices_, i, -1);
616  return index < 0 ? NULL : test_cases_[i];
617  }
618 
619  // Gets the i-th test case among all the test cases. i can range from 0 to
620  // total_test_case_count() - 1. If i is not in that range, returns NULL.
622  {
623  const int index = GetElementOr(test_case_indices_, i, -1);
624  return index < 0 ? NULL : test_cases_[index];
625  }
626 
627  // Provides access to the event listener list.
628  TestEventListeners * listeners() { return &listeners_; }
629 
630  // Returns the TestResult for the test that's currently running, or
631  // the TestResult for the ad hoc test if no test is running.
632  TestResult * current_test_result();
633 
634  // Returns the TestResult for the ad hoc test.
635  const TestResult * ad_hoc_test_result() const { return &ad_hoc_test_result_; }
636 
637  // Sets the OS stack trace getter.
638  //
639  // Does nothing if the input and the current OS stack trace getter
640  // are the same; otherwise, deletes the old getter and makes the
641  // input the current getter.
642  void set_os_stack_trace_getter(OsStackTraceGetterInterface * getter);
643 
644  // Returns the current OS stack trace getter if it is not NULL;
645  // otherwise, creates an OsStackTraceGetter, makes it the current
646  // getter, and returns it.
647  OsStackTraceGetterInterface * os_stack_trace_getter();
648 
649  // Returns the current OS stack trace as an std::string.
650  //
651  // The maximum number of stack frames to be included is specified by
652  // the gtest_stack_trace_depth flag. The skip_count parameter
653  // specifies the number of top frames to be skipped, which doesn't
654  // count against the number of frames to be included.
655  //
656  // For example, if Foo() calls Bar(), which in turn calls
657  // CurrentOsStackTraceExceptTop(1), Foo() will be included in the
658  // trace but Bar() and CurrentOsStackTraceExceptTop() won't.
659  std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
660 
661  // Finds and returns a TestCase with the given name. If one doesn't
662  // exist, creates one and returns it.
663  //
664  // Arguments:
665  //
666  // test_case_name: name of the test case
667  // type_param: the name of the test's type parameter, or NULL if
668  // this is not a typed or a type-parameterized test.
669  // set_up_tc: pointer to the function that sets up the test case
670  // tear_down_tc: pointer to the function that tears down the test case
671  TestCase * GetTestCase(const char * test_case_name,
672  const char * type_param,
673  Test::SetUpTestCaseFunc set_up_tc,
674  Test::TearDownTestCaseFunc tear_down_tc);
675 
676  // Adds a TestInfo to the unit test.
677  //
678  // Arguments:
679  //
680  // set_up_tc: pointer to the function that sets up the test case
681  // tear_down_tc: pointer to the function that tears down the test case
682  // test_info: the TestInfo object
684  Test::TearDownTestCaseFunc tear_down_tc,
685  TestInfo * test_info)
686  {
687  // In order to support thread-safe death tests, we need to
688  // remember the original working directory when the test program
689  // was first invoked. We cannot do this in RUN_ALL_TESTS(), as
690  // the user may have changed the current directory before calling
691  // RUN_ALL_TESTS(). Therefore we capture the current directory in
692  // AddTestInfo(), which is called to register a TEST or TEST_F
693  // before main() is reached.
694  if (original_working_dir_.IsEmpty())
695  {
698  << "Failed to get the current working directory.";
699  }
700 
701  GetTestCase(test_info->test_case_name(),
702  test_info->type_param(),
703  set_up_tc,
704  tear_down_tc)->AddTestInfo(test_info);
705  }
706 
707 #if GTEST_HAS_PARAM_TEST
708  // Returns ParameterizedTestCaseRegistry object used to keep track of
709  // value-parameterized tests and instantiate and register them.
710  internal::ParameterizedTestCaseRegistry & parameterized_test_registry()
711  {
712  return parameterized_test_registry_;
713  }
714 #endif // GTEST_HAS_PARAM_TEST
715 
716  // Sets the TestCase object for the test that's currently running.
717  void set_current_test_case(TestCase * a_current_test_case)
718  {
719  current_test_case_ = a_current_test_case;
720  }
721 
722  // Sets the TestInfo object for the test that's currently running. If
723  // current_test_info is NULL, the assertion results will be stored in
724  // ad_hoc_test_result_.
725  void set_current_test_info(TestInfo * a_current_test_info)
726  {
727  current_test_info_ = a_current_test_info;
728  }
729 
730  // Registers all parameterized tests defined using TEST_P and
731  // INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
732  // combination. This method can be called more then once; it has guards
733  // protecting from registering the tests more then once. If
734  // value-parameterized tests are disabled, RegisterParameterizedTests is
735  // present but does nothing.
736  void RegisterParameterizedTests();
737 
738  // Runs all tests in this UnitTest object, prints the result, and
739  // returns true if all tests are successful. If any exception is
740  // thrown during a test, this test is considered to be failed, but
741  // the rest of the tests will still be run.
742  bool RunAllTests();
743 
744  // Clears the results of all tests, except the ad hoc tests.
746  {
748  }
749 
750  // Clears the results of ad-hoc test assertions.
752  {
753  ad_hoc_test_result_.Clear();
754  }
755 
756  // Adds a TestProperty to the current TestResult object when invoked in a
757  // context of a test or a test case, or to the global property set. If the
758  // result already contains a property with the same key, the value will be
759  // updated.
760  void RecordProperty(const TestProperty & test_property);
761 
763  {
764  HONOR_SHARDING_PROTOCOL,
765  IGNORE_SHARDING_PROTOCOL
766  };
767 
768  // Matches the full name of each test against the user-specified
769  // filter to decide whether the test should run, then records the
770  // result in each TestCase and TestInfo object.
771  // If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
772  // based on sharding variables in the environment.
773  // Returns the number of tests that should run.
774  int FilterTests(ReactionToSharding shard_tests);
775 
776  // Prints the names of the tests matching the user-specified filter flag.
777  void ListTestsMatchingFilter();
778 
779  const TestCase * current_test_case() const { return current_test_case_; }
780  TestInfo * current_test_info() { return current_test_info_; }
781  const TestInfo * current_test_info() const { return current_test_info_; }
782 
783  // Returns the vector of environments that need to be set-up/torn-down
784  // before/after the tests are run.
785  std::vector<Environment *> & environments() { return environments_; }
786 
787  // Getters for the per-thread Google Test trace stack.
788  std::vector<TraceInfo> & gtest_trace_stack()
789  {
790  return *(gtest_trace_stack_.pointer());
791  }
792  const std::vector<TraceInfo> & gtest_trace_stack() const
793  {
794  return gtest_trace_stack_.get();
795  }
796 
797 #if GTEST_HAS_DEATH_TEST
798  void InitDeathTestSubprocessControlInfo()
799  {
800  internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
801  }
802  // Returns a pointer to the parsed --gtest_internal_run_death_test
803  // flag, or NULL if that flag was not specified.
804  // This information is useful only in a death test child process.
805  // Must not be called before a call to InitGoogleTest.
806  const InternalRunDeathTestFlag * internal_run_death_test_flag() const
807  {
808  return internal_run_death_test_flag_.get();
809  }
810 
811  // Returns a pointer to the current death test factory.
812  internal::DeathTestFactory * death_test_factory()
813  {
814  return death_test_factory_.get();
815  }
816 
817  void SuppressTestEventsIfInSubprocess();
818 
819  friend class ReplaceDeathTestFactory;
820 #endif // GTEST_HAS_DEATH_TEST
821 
822  // Initializes the event listener performing XML output as specified by
823  // UnitTestOptions. Must not be called before InitGoogleTest.
824  void ConfigureXmlOutput();
825 
826 #if GTEST_CAN_STREAM_RESULTS_
827  // Initializes the event listener for streaming test results to a socket.
828  // Must not be called before InitGoogleTest.
829  void ConfigureStreamingOutput();
830 #endif
831 
832  // Performs initialization dependent upon flag values obtained in
833  // ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
834  // ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
835  // this function is also called from RunAllTests. Since this function can be
836  // called more than once, it has to be idempotent.
837  void PostFlagParsingInit();
838 
839  // Gets the random seed used at the start of the current test iteration.
840  int random_seed() const { return random_seed_; }
841 
842  // Gets the random number generator.
843  internal::Random * random() { return &random_; }
844 
845  // Shuffles all test cases, and the tests within each test case,
846  // making sure that death tests are still run first.
847  void ShuffleTests();
848 
849  // Restores the test cases and tests to their order before the first shuffle.
850  void UnshuffleTests();
851 
852  // Returns the value of GTEST_FLAG(catch_exceptions) at the moment
853  // UnitTest::Run() starts.
854  bool catch_exceptions() const { return catch_exceptions_; }
855 
856 private:
857  friend class ::testing::UnitTest;
858 
859  // Used by UnitTest::Run() to capture the state of
860  // GTEST_FLAG(catch_exceptions) at the moment it starts.
861  void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
862 
863  // The UnitTest object that owns this implementation object.
864  UnitTest * const parent_;
865 
866  // The working directory when the first TEST() or TEST_F() was
867  // executed.
869 
870  // The default test part result reporters.
871  DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
873  default_per_thread_test_part_result_reporter_;
874 
875  // Points to (but doesn't own) the global test part result reporter.
876  TestPartResultReporterInterface * global_test_part_result_repoter_;
877 
878  // Protects read and write access to global_test_part_result_reporter_.
879  internal::Mutex global_test_part_result_reporter_mutex_;
880 
881  // Points to (but doesn't own) the per-thread test part result reporter.
883  per_thread_test_part_result_reporter_;
884 
885  // The vector of environments that need to be set-up/torn-down
886  // before/after the tests are run.
887  std::vector<Environment *> environments_;
888 
889  // The vector of TestCases in their original order. It owns the
890  // elements in the vector.
891  std::vector<TestCase *> test_cases_;
892 
893  // Provides a level of indirection for the test case list to allow
894  // easy shuffling and restoring the test case order. The i-th
895  // element of this vector is the index of the i-th test case in the
896  // shuffled order.
897  std::vector<int> test_case_indices_;
898 
899 #if GTEST_HAS_PARAM_TEST
900  // ParameterizedTestRegistry object used to register value-parameterized
901  // tests.
902  internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
903 
904  // Indicates whether RegisterParameterizedTests() has been called already.
905  bool parameterized_tests_registered_;
906 #endif // GTEST_HAS_PARAM_TEST
907 
908  // Index of the last death test case registered. Initially -1.
909  int last_death_test_case_;
910 
911  // This points to the TestCase for the currently running test. It
912  // changes as Google Test goes through one test case 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  TestCase * current_test_case_;
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 iff 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  internal::scoped_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
964 #endif // GTEST_HAS_DEATH_TEST
965 
966  // A per-thread stack of traces created by the SCOPED_TRACE() macro.
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 {
980  return UnitTest::GetInstance()->impl();
981 }
982 
983 #if GTEST_USES_SIMPLE_RE
984 
985 // Internal helper functions for implementing the simple regular
986 // expression matcher.
987 GTEST_API_ bool IsInSet(char ch, const char * str);
988 GTEST_API_ bool IsAsciiDigit(char ch);
989 GTEST_API_ bool IsAsciiPunct(char ch);
990 GTEST_API_ bool IsRepeat(char ch);
991 GTEST_API_ bool IsAsciiWhiteSpace(char ch);
992 GTEST_API_ bool IsAsciiWordChar(char ch);
993 GTEST_API_ bool IsValidEscape(char ch);
994 GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
995 GTEST_API_ bool ValidateRegex(const char * regex);
996 GTEST_API_ bool MatchRegexAtHead(const char * regex, const char * str);
997 GTEST_API_ bool MatchRepetitionAndRegexAtHead(
998  bool escaped, char ch, char repeat, const char * regex, const char * str);
999 GTEST_API_ bool MatchRegexAnywhere(const char * regex, const char * str);
1000 
1001 #endif // GTEST_USES_SIMPLE_RE
1002 
1003 // Parses the command line for Google Test flags, without initializing
1004 // other parts of Google Test.
1005 GTEST_API_ void ParseGoogleTestFlagsOnly(int * argc, char ** argv);
1006 GTEST_API_ void ParseGoogleTestFlagsOnly(int * argc, wchar_t ** argv);
1007 
1008 #if GTEST_HAS_DEATH_TEST
1009 
1010 // Returns the message describing the last system error, regardless of the
1011 // platform.
1012 GTEST_API_ std::string GetLastErrnoDescription();
1013 
1014 # if GTEST_OS_WINDOWS
1015 // Provides leak-safe Windows kernel handle ownership.
1016 class AutoHandle
1017 {
1018 public:
1019  AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
1020  explicit AutoHandle(HANDLE handle) : handle_(handle) {}
1021 
1022  ~AutoHandle() { Reset(); }
1023 
1024  HANDLE Get() const { return handle_; }
1025  void Reset() { Reset(INVALID_HANDLE_VALUE); }
1026  void Reset(HANDLE handle)
1027  {
1028  if (handle != handle_)
1029  {
1030  if (handle_ != INVALID_HANDLE_VALUE)
1031  { ::CloseHandle(handle_); }
1032 
1033  handle_ = handle;
1034  }
1035  }
1036 
1037 private:
1038  HANDLE handle_;
1039 
1040  GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
1041 };
1042 # endif // GTEST_OS_WINDOWS
1043 
1044 // Attempts to parse a string into a positive integer pointed to by the
1045 // number parameter. Returns true if that is possible.
1046 // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
1047 // it here.
1048 template <typename Integer>
1049 bool ParseNaturalNumber(const ::std::string & str, Integer * number)
1050 {
1051  // Fail fast if the given string does not begin with a digit;
1052  // this bypasses strtoXXX's "optional leading whitespace and plus
1053  // or minus sign" semantics, which are undesirable here.
1054  if (str.empty() || !IsDigit(str[0]))
1055  {
1056  return false;
1057  }
1058 
1059  errno = 0;
1060 
1061  char * end;
1062  // BiggestConvertible is the largest integer type that system-provided
1063  // string-to-number conversion routines can return.
1064 
1065 # if GTEST_OS_WINDOWS && !defined(__GNUC__)
1066 
1067  // MSVC and C++ Builder define __int64 instead of the standard long long.
1068  typedef unsigned __int64 BiggestConvertible;
1069  const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
1070 
1071 # else
1072 
1073  typedef unsigned long long BiggestConvertible; // NOLINT
1074  const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
1075 
1076 # endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
1077 
1078  const bool parse_success = *end == '\0' && errno == 0;
1079 
1080  // TODO(vladl@google.com): Convert this to compile time assertion when it is
1081  // available.
1082  GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
1083 
1084  const Integer result = static_cast<Integer>(parsed);
1085 
1086  if (parse_success && static_cast<BiggestConvertible>(result) == parsed)
1087  {
1088  *number = result;
1089  return true;
1090  }
1091 
1092  return false;
1093 }
1094 #endif // GTEST_HAS_DEATH_TEST
1095 
1096 // TestResult contains some private methods that should be hidden from
1097 // Google Test user but are required for testing. This class allow our tests
1098 // to access them.
1099 //
1100 // This class is supplied only for the purpose of testing Google Test's own
1101 // constructs. Do not use it in user tests, either directly or indirectly.
1102 class TestResultAccessor
1103 {
1104 public:
1105  static void RecordProperty(TestResult * test_result,
1106  const std::string & xml_element,
1107  const TestProperty & property)
1108  {
1109  test_result->RecordProperty(xml_element, property);
1110  }
1111 
1112  static void ClearTestPartResults(TestResult * test_result)
1113  {
1114  test_result->ClearTestPartResults();
1115  }
1116 
1117  static const std::vector<testing::TestPartResult> & test_part_results(
1118  const TestResult & test_result)
1119  {
1120  return test_result.test_part_results();
1121  }
1122 };
1123 
1124 #if GTEST_CAN_STREAM_RESULTS_
1125 
1126 // Streams test results to the given port on the given host machine.
1127 class StreamingListener : public EmptyTestEventListener
1128 {
1129 public:
1130  // Abstract base class for writing strings to a socket.
1131  class AbstractSocketWriter
1132  {
1133  public:
1134  virtual ~AbstractSocketWriter() {}
1135 
1136  // Sends a string to the socket.
1137  virtual void Send(const string & message) = 0;
1138 
1139  // Closes the socket.
1140  virtual void CloseConnection() {}
1141 
1142  // Sends a string and a newline to the socket.
1143  void SendLn(const string & message)
1144  {
1145  Send(message + "\n");
1146  }
1147  };
1148 
1149  // Concrete class for actually writing strings to a socket.
1150  class SocketWriter : public AbstractSocketWriter
1151  {
1152  public:
1153  SocketWriter(const string & host, const string & port)
1154  : sockfd_(-1), host_name_(host), port_num_(port)
1155  {
1156  MakeConnection();
1157  }
1158 
1159  virtual ~SocketWriter()
1160  {
1161  if (sockfd_ != -1)
1162  { CloseConnection(); }
1163  }
1164 
1165  // Sends a string to the socket.
1166  virtual void Send(const string & message)
1167  {
1168  GTEST_CHECK_(sockfd_ != -1)
1169  << "Send() can be called only when there is a connection.";
1170 
1171  const int len = static_cast<int>(message.length());
1172 
1173  if (write(sockfd_, message.c_str(), len) != len)
1174  {
1175  GTEST_LOG_(WARNING)
1176  << "stream_result_to: failed to stream to "
1177  << host_name_ << ":" << port_num_;
1178  }
1179  }
1180 
1181  private:
1182  // Creates a client socket and connects to the server.
1183  void MakeConnection();
1184 
1185  // Closes the socket.
1186  void CloseConnection()
1187  {
1188  GTEST_CHECK_(sockfd_ != -1)
1189  << "CloseConnection() can be called only when there is a connection.";
1190 
1191  close(sockfd_);
1192  sockfd_ = -1;
1193  }
1194 
1195  int sockfd_; // socket file descriptor
1196  const string host_name_;
1197  const string port_num_;
1198 
1199  GTEST_DISALLOW_COPY_AND_ASSIGN_(SocketWriter);
1200  }; // class SocketWriter
1201 
1202  // Escapes '=', '&', '%', and '\n' characters in str as "%xx".
1203  static string UrlEncode(const char * str);
1204 
1205  StreamingListener(const string & host, const string & port)
1206  : socket_writer_(new SocketWriter(host, port)) { Start(); }
1207 
1208  explicit StreamingListener(AbstractSocketWriter * socket_writer)
1209  : socket_writer_(socket_writer) { Start(); }
1210 
1211  void OnTestProgramStart(const UnitTest & /* unit_test */)
1212  {
1213  SendLn("event=TestProgramStart");
1214  }
1215 
1216  void OnTestProgramEnd(const UnitTest & unit_test)
1217  {
1218  // Note that Google Test current only report elapsed time for each
1219  // test iteration, not for the entire test program.
1220  SendLn("event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
1221 
1222  // Notify the streaming server to stop.
1223  socket_writer_->CloseConnection();
1224  }
1225 
1226  void OnTestIterationStart(const UnitTest & /* unit_test */, int iteration)
1227  {
1228  SendLn("event=TestIterationStart&iteration=" +
1229  StreamableToString(iteration));
1230  }
1231 
1232  void OnTestIterationEnd(const UnitTest & unit_test, int /* iteration */)
1233  {
1234  SendLn("event=TestIterationEnd&passed=" +
1235  FormatBool(unit_test.Passed()) + "&elapsed_time=" +
1236  StreamableToString(unit_test.elapsed_time()) + "ms");
1237  }
1238 
1239  void OnTestCaseStart(const TestCase & test_case)
1240  {
1241  SendLn(std::string("event=TestCaseStart&name=") + test_case.name());
1242  }
1243 
1244  void OnTestCaseEnd(const TestCase & test_case)
1245  {
1246  SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed())
1247  + "&elapsed_time=" + StreamableToString(test_case.elapsed_time())
1248  + "ms");
1249  }
1250 
1251  void OnTestStart(const TestInfo & test_info)
1252  {
1253  SendLn(std::string("event=TestStart&name=") + test_info.name());
1254  }
1255 
1256  void OnTestEnd(const TestInfo & test_info)
1257  {
1258  SendLn("event=TestEnd&passed=" +
1259  FormatBool((test_info.result())->Passed()) +
1260  "&elapsed_time=" +
1261  StreamableToString((test_info.result())->elapsed_time()) + "ms");
1262  }
1263 
1264  void OnTestPartResult(const TestPartResult & test_part_result)
1265  {
1266  const char * file_name = test_part_result.file_name();
1267 
1268  if (file_name == NULL)
1269  { file_name = ""; }
1270 
1271  SendLn("event=TestPartResult&file=" + UrlEncode(file_name) +
1272  "&line=" + StreamableToString(test_part_result.line_number()) +
1273  "&message=" + UrlEncode(test_part_result.message()));
1274  }
1275 
1276 private:
1277  // Sends the given message and a newline to the socket.
1278  void SendLn(const string & message) { socket_writer_->SendLn(message); }
1279 
1280  // Called at the start of streaming to notify the receiver what
1281  // protocol we are using.
1282  void Start() { SendLn("gtest_streaming_protocol_version=1.0"); }
1283 
1284  string FormatBool(bool value) { return value ? "1" : "0"; }
1285 
1286  const scoped_ptr<AbstractSocketWriter> socket_writer_;
1287 
1288  GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener);
1289 }; // class StreamingListener
1290 
1291 #endif // GTEST_CAN_STREAM_RESULTS_
1292 
1293 } // namespace internal
1294 } // namespace testing
1295 
1296 #endif // GTEST_SRC_GTEST_INTERNAL_INL_H_
GTEST_API_ bool g_help_flag
UnitTestImpl * GetUnitTestImpl()
internal::SetUpTestCaseFunc SetUpTestCaseFunc
void RecordProperty(const std::string &xml_element, const TestProperty &test_property)
static const std::vector< testing::TestPartResult > & test_part_results(const TestResult &test_result)
int GetRandomSeedFromFlag(Int32 random_seed_flag)
TimeInMillis elapsed_time() const
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
const TestResult * ad_hoc_test_result() const
GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms)
E GetElementOr(const std::vector< E > &v, int i, E default_value)
const char kAlsoRunDisabledTestsFlag[]
int * count
const char kListTestsFlag[]
#define GTEST_API_
void set_current_test_info(TestInfo *a_current_test_info)
class testing::internal::GTestFlagSaver GTEST_ATTRIBUTE_UNUSED_
std::vector< Environment * > & environments()
const char kStreamResultToFlag[]
TypeWithSize< 4 >::Int Int32
int GetNextRandomSeed(int seed)
const char kFilterFlag[]
const std::vector< TestPartResult > & test_part_results() const
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty)
TypeWithSize< 4 >::UInt UInt32
GTEST_API_ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id)
#define GTEST_NO_INLINE_
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms)
void set_current_test_case(TestCase *a_current_test_case)
internal::TearDownTestCaseFunc TearDownTestCaseFunc
static void ClearTestPartResults(TestResult *test_result)
GTEST_API_ bool ShouldShard(const char *total_shards_str, const char *shard_index_str, bool in_subprocess_for_death_test)
GTEST_API_ std::string CodePointToUtf8(UInt32 code_point)
const char kBreakOnFailureFlag[]
name
Definition: setup.py:38
#define GTEST_FLAG(name)
def default_value(type_)
const char kRandomSeedFlag[]
std::string StreamableToString(const T &streamable)
const char kShuffleFlag[]
bool write(ros_opcua_srvs::Write::Request &req, ros_opcua_srvs::Write::Response &res)
const char kColorFlag[]
GTEST_DECLARE_bool_(death_test_use_fork)
const std::vector< TraceInfo > & gtest_trace_stack() const
message
Definition: server.py:50
void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc, TestInfo *test_info)
UInt32 Generate(UInt32 range)
GTEST_API_ const TypeId kTestTypeIdInGoogleTest
handle
Definition: client.py:58
static void RecordProperty(TestResult *test_result, const std::string &xml_element, const TestProperty &property)
const TestCase * GetTestCase(int i) const
GTEST_API_ FilePath GetCurrentExecutableName()
GTEST_API_ TimeInMillis GetTimeInMillis()
bool Passed() const
const char * test_case_name() const
const char kRepeatFlag[]
GTEST_API_ std::string WideStringToUtf8(const wchar_t *str, int num_chars)
void ShuffleRange(internal::Random *random, int begin, int end, std::vector< E > *v)
int CountIf(const Container &c, Predicate predicate)
internal::UnitTestImpl * impl()
const char kStackTraceDepthFlag[]
const char kCatchExceptionsFlag[]
bool operator()(const TestProperty &test_property) const
static void ClearTestCaseResult(TestCase *test_case)
GTEST_API_ void ParseGoogleTestFlagsOnly(int *argc, char **argv)
void Shuffle(internal::Random *random, std::vector< E > *v)
std::vector< TraceInfo > & gtest_trace_stack()
TimeInMillis elapsed_time() const
const TestResult * result() const
static UnitTest * GetInstance()
const char * type_param() const
TypeWithSize< 8 >::Int TimeInMillis
void ForEach(const Container &c, Functor functor)
#define GTEST_CHECK_(condition)
GTEST_API_ Int32 Int32FromEnvOrDie(const char *env_var, Int32 default_val)
void WriteToShardStatusFileIfNeeded()
const char kOutputFlag[]
#define GTEST_LOG_(severity)
const char kPrintTimeFlag[]
const char kThrowOnFailureFlag[]
static void Delete(T *x)
GTEST_API_ bool ParseInt32Flag(const char *str, const char *flag, Int32 *value)
FilePath original_working_dir_
#define GTEST_LOCK_EXCLUDED_(locks)


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:12