Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
testing::UnitTest Class Reference

#include <gtest.h>

Public Member Functions

int Run () GTEST_MUST_USE_RESULT_
 
const char * original_working_dir () const
 
const TestCasecurrent_test_case () const GTEST_LOCK_EXCLUDED_(mutex_)
 
const TestInfocurrent_test_info () const GTEST_LOCK_EXCLUDED_(mutex_)
 
int random_seed () const
 
internal::ParameterizedTestCaseRegistryparameterized_test_registry () GTEST_LOCK_EXCLUDED_(mutex_)
 
int successful_test_case_count () const
 
int failed_test_case_count () const
 
int total_test_case_count () const
 
int test_case_to_run_count () const
 
int successful_test_count () const
 
int failed_test_count () const
 
int reportable_disabled_test_count () const
 
int disabled_test_count () const
 
int reportable_test_count () const
 
int total_test_count () const
 
int test_to_run_count () const
 
TimeInMillis start_timestamp () const
 
TimeInMillis elapsed_time () const
 
bool Passed () const
 
bool Failed () const
 
const TestCaseGetTestCase (int i) const
 
const TestResultad_hoc_test_result () const
 
TestEventListenerslisteners ()
 

Static Public Member Functions

static UnitTestGetInstance ()
 

Friends

class ScopedTrace
 
class Test
 
class internal::AssertHelper
 
class internal::StreamingListenerTest
 
class internal::UnitTestRecordPropertyTestHelper
 
EnvironmentAddGlobalTestEnvironment (Environment *env)
 
internal::UnitTestImplinternal::GetUnitTestImpl ()
 
void internal::ReportFailureInUnknownLocation (TestPartResult::Type result_type, const std::string &message)
 

Detailed Description

Definition at line 1194 of file gtest.h.

Member Function Documentation

◆ ad_hoc_test_result()

const TestResult & testing::UnitTest::ad_hoc_test_result ( ) const

Definition at line 4471 of file gtest.cc.

4471 {
4472 return *impl()->ad_hoc_test_result();
4473}
const TestResult * ad_hoc_test_result() const
Here is the caller graph for this function:

◆ current_test_case()

const TestCase * testing::UnitTest::current_test_case ( ) const

Definition at line 4678 of file gtest.cc.

4679 {
4680 internal::MutexLock lock(&mutex_);
4681 return impl_->current_test_case();
4682}
const TestCase * current_test_case() const
GTestMutexLock MutexLock
void lock()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ current_test_info()

const TestInfo * testing::UnitTest::current_test_info ( ) const

Definition at line 4686 of file gtest.cc.

4687 {
4688 internal::MutexLock lock(&mutex_);
4689 return impl_->current_test_info();
4690}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disabled_test_count()

int testing::UnitTest::disabled_test_count ( ) const

Definition at line 4430 of file gtest.cc.

4430 {
4431 return impl()->disabled_test_count();
4432}
Here is the caller graph for this function:

◆ elapsed_time()

internal::TimeInMillis testing::UnitTest::elapsed_time ( ) const

Definition at line 4452 of file gtest.cc.

4452 {
4453 return impl()->elapsed_time();
4454}
Here is the caller graph for this function:

◆ Failed()

bool testing::UnitTest::Failed ( ) const

Definition at line 4461 of file gtest.cc.

4461{ return impl()->Failed(); }
Here is the caller graph for this function:

◆ failed_test_case_count()

int testing::UnitTest::failed_test_case_count ( ) const

Definition at line 4401 of file gtest.cc.

4401 {
4402 return impl()->failed_test_case_count();
4403}
int failed_test_case_count() const
Definition gtest.cc:749
Here is the caller graph for this function:

◆ failed_test_count()

int testing::UnitTest::failed_test_count ( ) const

Definition at line 4422 of file gtest.cc.

4422{ return impl()->failed_test_count(); }
Here is the caller graph for this function:

◆ GetInstance()

UnitTest * testing::UnitTest::GetInstance ( )
static

Definition at line 4374 of file gtest.cc.

4374 {
4375 // When compiled with MSVC 7.1 in optimized mode, destroying the
4376 // UnitTest object upon exiting the program messes up the exit code,
4377 // causing successful tests to appear failed. We have to use a
4378 // different implementation in this case to bypass the compiler bug.
4379 // This implementation makes the compiler happy, at the cost of
4380 // leaking the UnitTest object.
4381
4382 // CodeGear C++Builder insists on a public destructor for the
4383 // default implementation. Use this implementation to keep good OO
4384 // design with private destructor.
4385
4386#if (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
4387 static UnitTest* const instance = new UnitTest;
4388 return instance;
4389#else
4390 static UnitTest instance;
4391 return &instance;
4392#endif // (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
4393}
Here is the caller graph for this function:

◆ GetTestCase()

const TestCase * testing::UnitTest::GetTestCase ( int i) const

Definition at line 4465 of file gtest.cc.

4465 {
4466 return impl()->GetTestCase(i);
4467}
const TestCase * GetTestCase(int i) const
Here is the caller graph for this function:

◆ listeners()

TestEventListeners & testing::UnitTest::listeners ( )

Definition at line 4483 of file gtest.cc.

4483 {
4484 return *impl()->listeners();
4485}
Here is the caller graph for this function:

◆ original_working_dir()

const char * testing::UnitTest::original_working_dir ( ) const

Definition at line 4672 of file gtest.cc.

4672 {
4673 return impl_->original_working_dir_.c_str();
4674}
const char * c_str() const
Here is the call graph for this function:

◆ parameterized_test_registry()

internal::ParameterizedTestCaseRegistry & testing::UnitTest::parameterized_test_registry ( )

Definition at line 4698 of file gtest.cc.

4699 {
4700 return impl_->parameterized_test_registry();
4701}
internal::ParameterizedTestCaseRegistry & parameterized_test_registry()
Here is the call graph for this function:

◆ Passed()

bool testing::UnitTest::Passed ( ) const

Definition at line 4457 of file gtest.cc.

4457{ return impl()->Passed(); }
Here is the caller graph for this function:

◆ random_seed()

int testing::UnitTest::random_seed ( ) const

Definition at line 4693 of file gtest.cc.

4693{ return impl_->random_seed(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reportable_disabled_test_count()

int testing::UnitTest::reportable_disabled_test_count ( ) const

Definition at line 4425 of file gtest.cc.

4425 {
4426 return impl()->reportable_disabled_test_count();
4427}
int reportable_disabled_test_count() const
Definition gtest.cc:775
Here is the caller graph for this function:

◆ reportable_test_count()

int testing::UnitTest::reportable_test_count ( ) const

Definition at line 4435 of file gtest.cc.

4435 {
4436 return impl()->reportable_test_count();
4437}
int reportable_test_count() const
Definition gtest.cc:786

◆ Run()

int testing::UnitTest::Run ( )

Definition at line 4592 of file gtest.cc.

4592 {
4593 const bool in_death_test_child_process =
4594 internal::GTEST_FLAG(internal_run_death_test).length() > 0;
4595
4596 // Google Test implements this protocol for catching that a test
4597 // program exits before returning control to Google Test:
4598 //
4599 // 1. Upon start, Google Test creates a file whose absolute path
4600 // is specified by the environment variable
4601 // TEST_PREMATURE_EXIT_FILE.
4602 // 2. When Google Test has finished its work, it deletes the file.
4603 //
4604 // This allows a test runner to set TEST_PREMATURE_EXIT_FILE before
4605 // running a Google-Test-based test program and check the existence
4606 // of the file at the end of the test execution to see if it has
4607 // exited prematurely.
4608
4609 // If we are in the child process of a death test, don't
4610 // create/delete the premature exit file, as doing so is unnecessary
4611 // and will confuse the parent process. Otherwise, create/delete
4612 // the file upon entering/leaving this function. If the program
4613 // somehow exits before this function has a chance to return, the
4614 // premature-exit file will be left undeleted, causing a test runner
4615 // that understands the premature-exit-file protocol to report the
4616 // test as having failed.
4617 const internal::ScopedPrematureExitFile premature_exit_file(
4618 in_death_test_child_process ?
4619 NULL : internal::posix::GetEnv("TEST_PREMATURE_EXIT_FILE"));
4620
4621 // Captures the value of GTEST_FLAG(catch_exceptions). This value will be
4622 // used for the duration of the program.
4623 impl()->set_catch_exceptions(GTEST_FLAG(catch_exceptions));
4624
4625#if GTEST_HAS_SEH
4626 // Either the user wants Google Test to catch exceptions thrown by the
4627 // tests or this is executing in the context of death test child
4628 // process. In either case the user does not want to see pop-up dialogs
4629 // about crashes - they are expected.
4630 if (impl()->catch_exceptions() || in_death_test_child_process) {
4631# if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
4632 // SetErrorMode doesn't exist on CE.
4633 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
4634 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
4635# endif // !GTEST_OS_WINDOWS_MOBILE
4636
4637# if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE
4638 // Death test children can be terminated with _abort(). On Windows,
4639 // _abort() can show a dialog with a warning message. This forces the
4640 // abort message to go to stderr instead.
4641 _set_error_mode(_OUT_TO_STDERR);
4642# endif
4643
4644# if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
4645 // In the debug version, Visual Studio pops up a separate dialog
4646 // offering a choice to debug the aborted program. We need to suppress
4647 // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
4648 // executed. Google Test will notify the user of any unexpected
4649 // failure via stderr.
4650 //
4651 // VC++ doesn't define _set_abort_behavior() prior to the version 8.0.
4652 // Users of prior VC versions shall suffer the agony and pain of
4653 // clicking through the countless debug dialogs.
4654 // TODO(vladl@google.com): find a way to suppress the abort dialog() in the
4655 // debug mode when compiled with VC 7.1 or lower.
4656 if (!GTEST_FLAG(break_on_failure))
4657 _set_abort_behavior(
4658 0x0, // Clear the following flags:
4659 _WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump.
4660# endif
4661 }
4662#endif // GTEST_HAS_SEH
4663
4665 impl(),
4667 "auxiliary test code (environments or event listeners)") ? 0 : 1;
4668}
#define GTEST_FLAG(name)
const char * GetEnv(const char *name)
Result HandleExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
Definition gtest.cc:2426
Here is the call graph for this function:

◆ start_timestamp()

internal::TimeInMillis testing::UnitTest::start_timestamp ( ) const

Definition at line 4447 of file gtest.cc.

4447 {
4448 return impl()->start_timestamp();
4449}

◆ successful_test_case_count()

int testing::UnitTest::successful_test_case_count ( ) const

Definition at line 4396 of file gtest.cc.

4396 {
4397 return impl()->successful_test_case_count();
4398}
int successful_test_case_count() const
Definition gtest.cc:744
Here is the call graph for this function:
Here is the caller graph for this function:

◆ successful_test_count()

int testing::UnitTest::successful_test_count ( ) const

Definition at line 4417 of file gtest.cc.

4417 {
4418 return impl()->successful_test_count();
4419}
int successful_test_count() const
Definition gtest.cc:765
Here is the caller graph for this function:

◆ test_case_to_run_count()

int testing::UnitTest::test_case_to_run_count ( ) const

Definition at line 4412 of file gtest.cc.

4412 {
4413 return impl()->test_case_to_run_count();
4414}
int test_case_to_run_count() const
Definition gtest.cc:760
Here is the caller graph for this function:

◆ test_to_run_count()

int testing::UnitTest::test_to_run_count ( ) const

Definition at line 4443 of file gtest.cc.

4443{ return impl()->test_to_run_count(); }
Here is the caller graph for this function:

◆ total_test_case_count()

int testing::UnitTest::total_test_case_count ( ) const

Definition at line 4406 of file gtest.cc.

4406 {
4407 return impl()->total_test_case_count();
4408}
int total_test_case_count() const
Definition gtest.cc:754
Here is the caller graph for this function:

◆ total_test_count()

int testing::UnitTest::total_test_count ( ) const

Definition at line 4440 of file gtest.cc.

4440{ return impl()->total_test_count(); }
Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ AddGlobalTestEnvironment

Environment * AddGlobalTestEnvironment ( Environment * env)
friend

Definition at line 1391 of file gtest.h.

1391 {
1392 return UnitTest::GetInstance()->AddEnvironment(env);
1393}
static UnitTest * GetInstance()
Definition gtest.cc:4374

◆ internal::AssertHelper

Definition at line 1335 of file gtest.h.

◆ internal::GetUnitTestImpl

◆ internal::ReportFailureInUnknownLocation

void internal::ReportFailureInUnknownLocation ( TestPartResult::Type result_type,
const std::string & message )
friend

◆ internal::StreamingListenerTest

friend class internal::StreamingListenerTest
friend

Definition at line 1336 of file gtest.h.

◆ internal::UnitTestRecordPropertyTestHelper

Definition at line 1337 of file gtest.h.

◆ ScopedTrace

friend class ScopedTrace
friend

Definition at line 1333 of file gtest.h.

◆ Test

friend class Test
friend

Definition at line 1334 of file gtest.h.


The documentation for this class was generated from the following files: