tesseract v5.3.3.20231005
testing::UnitTest Class Reference

#include <gtest.h>

Public Member Functions

int Run () GTEST_MUST_USE_RESULT_
 
const char * original_working_dir () const
 
const TestSuitecurrent_test_suite () const GTEST_LOCK_EXCLUDED_(mutex_)
 
const TestCase * current_test_case () const GTEST_LOCK_EXCLUDED_(mutex_)
 
const TestInfocurrent_test_info () const GTEST_LOCK_EXCLUDED_(mutex_)
 
int random_seed () const
 
internal::ParameterizedTestSuiteRegistryparameterized_test_registry () GTEST_LOCK_EXCLUDED_(mutex_)
 
int successful_test_suite_count () const
 
int failed_test_suite_count () const
 
int total_test_suite_count () const
 
int test_suite_to_run_count () const
 
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 skipped_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 TestSuiteGetTestSuite (int i) const
 
const TestCase * GetTestCase (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)
 
std::set< std::string > * internal::GetIgnoredParameterizedTestSuites ()
 
internal::UnitTestImpl * internal::GetUnitTestImpl ()
 
void internal::ReportFailureInUnknownLocation (TestPartResult::Type result_type, const std::string &message)
 

Detailed Description

Definition at line 1274 of file gtest.h.

Member Function Documentation

◆ ad_hoc_test_result()

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

Definition at line 5242 of file gtest.cc.

5242 {
5243 return *impl()->ad_hoc_test_result();
5244}

◆ current_test_case()

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

Definition at line 5460 of file gtest.cc.

5461 {
5462 internal::MutexLock lock(&mutex_);
5463 return impl_->current_test_suite();
5464}
GTestMutexLock MutexLock
Definition: gtest-port.h:1886

◆ current_test_info()

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

Definition at line 5469 of file gtest.cc.

5470 {
5471 internal::MutexLock lock(&mutex_);
5472 return impl_->current_test_info();
5473}

◆ current_test_suite()

const TestSuite * testing::UnitTest::current_test_suite ( ) const

Definition at line 5452 of file gtest.cc.

5453 {
5454 internal::MutexLock lock(&mutex_);
5455 return impl_->current_test_suite();
5456}

◆ disabled_test_count()

int testing::UnitTest::disabled_test_count ( ) const

Definition at line 5193 of file gtest.cc.

5193 {
5194 return impl()->disabled_test_count();
5195}

◆ elapsed_time()

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

Definition at line 5215 of file gtest.cc.

5215 {
5216 return impl()->elapsed_time();
5217}

◆ Failed()

bool testing::UnitTest::Failed ( ) const

Definition at line 5225 of file gtest.cc.

5225{ return impl()->Failed(); }

◆ failed_test_case_count()

int testing::UnitTest::failed_test_case_count ( ) const

Definition at line 5163 of file gtest.cc.

5163 {
5164 return impl()->failed_test_suite_count();
5165}

◆ failed_test_count()

int testing::UnitTest::failed_test_count ( ) const

Definition at line 5185 of file gtest.cc.

5185{ return impl()->failed_test_count(); }

◆ failed_test_suite_count()

int testing::UnitTest::failed_test_suite_count ( ) const

Definition at line 5143 of file gtest.cc.

5143 {
5144 return impl()->failed_test_suite_count();
5145}

◆ GetInstance()

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

Definition at line 5123 of file gtest.cc.

5123 {
5124 // CodeGear C++Builder insists on a public destructor for the
5125 // default implementation. Use this implementation to keep good OO
5126 // design with private destructor.
5127
5128#if defined(__BORLANDC__)
5129 static UnitTest* const instance = new UnitTest;
5130 return instance;
5131#else
5132 static UnitTest instance;
5133 return &instance;
5134#endif // defined(__BORLANDC__)
5135}

◆ GetTestCase()

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

Definition at line 5235 of file gtest.cc.

5235 {
5236 return impl()->GetTestCase(i);
5237}

◆ GetTestSuite()

const TestSuite * testing::UnitTest::GetTestSuite ( int  i) const

Definition at line 5229 of file gtest.cc.

5229 {
5230 return impl()->GetTestSuite(i);
5231}

◆ listeners()

TestEventListeners & testing::UnitTest::listeners ( )

Definition at line 5254 of file gtest.cc.

5254 {
5255 return *impl()->listeners();
5256}

◆ original_working_dir()

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

Definition at line 5446 of file gtest.cc.

5446 {
5447 return impl_->original_working_dir_.c_str();
5448}

◆ parameterized_test_registry()

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

Definition at line 5481 of file gtest.cc.

5481 {
5482 return impl_->parameterized_test_registry();
5483}

◆ Passed()

bool testing::UnitTest::Passed ( ) const

Definition at line 5221 of file gtest.cc.

5221{ return impl()->Passed(); }

◆ random_seed()

int testing::UnitTest::random_seed ( ) const

Definition at line 5476 of file gtest.cc.

5476{ return impl_->random_seed(); }

◆ reportable_disabled_test_count()

int testing::UnitTest::reportable_disabled_test_count ( ) const

Definition at line 5188 of file gtest.cc.

5188 {
5189 return impl()->reportable_disabled_test_count();
5190}

◆ reportable_test_count()

int testing::UnitTest::reportable_test_count ( ) const

Definition at line 5198 of file gtest.cc.

5198 {
5199 return impl()->reportable_test_count();
5200}

◆ Run()

int testing::UnitTest::Run ( )

Definition at line 5361 of file gtest.cc.

5361 {
5362 const bool in_death_test_child_process =
5363 internal::GTEST_FLAG(internal_run_death_test).length() > 0;
5364
5365 // Google Test implements this protocol for catching that a test
5366 // program exits before returning control to Google Test:
5367 //
5368 // 1. Upon start, Google Test creates a file whose absolute path
5369 // is specified by the environment variable
5370 // TEST_PREMATURE_EXIT_FILE.
5371 // 2. When Google Test has finished its work, it deletes the file.
5372 //
5373 // This allows a test runner to set TEST_PREMATURE_EXIT_FILE before
5374 // running a Google-Test-based test program and check the existence
5375 // of the file at the end of the test execution to see if it has
5376 // exited prematurely.
5377
5378 // If we are in the child process of a death test, don't
5379 // create/delete the premature exit file, as doing so is unnecessary
5380 // and will confuse the parent process. Otherwise, create/delete
5381 // the file upon entering/leaving this function. If the program
5382 // somehow exits before this function has a chance to return, the
5383 // premature-exit file will be left undeleted, causing a test runner
5384 // that understands the premature-exit-file protocol to report the
5385 // test as having failed.
5386 const internal::ScopedPrematureExitFile premature_exit_file(
5387 in_death_test_child_process
5388 ? nullptr
5389 : internal::posix::GetEnv("TEST_PREMATURE_EXIT_FILE"));
5390
5391 // Captures the value of GTEST_FLAG(catch_exceptions). This value will be
5392 // used for the duration of the program.
5393 impl()->set_catch_exceptions(GTEST_FLAG(catch_exceptions));
5394
5395#if GTEST_OS_WINDOWS
5396 // Either the user wants Google Test to catch exceptions thrown by the
5397 // tests or this is executing in the context of death test child
5398 // process. In either case the user does not want to see pop-up dialogs
5399 // about crashes - they are expected.
5400 if (impl()->catch_exceptions() || in_death_test_child_process) {
5401# if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
5402 // SetErrorMode doesn't exist on CE.
5403 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
5404 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
5405# endif // !GTEST_OS_WINDOWS_MOBILE
5406
5407# if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE
5408 // Death test children can be terminated with _abort(). On Windows,
5409 // _abort() can show a dialog with a warning message. This forces the
5410 // abort message to go to stderr instead.
5411 _set_error_mode(_OUT_TO_STDERR);
5412# endif
5413
5414# if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE
5415 // In the debug version, Visual Studio pops up a separate dialog
5416 // offering a choice to debug the aborted program. We need to suppress
5417 // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
5418 // executed. Google Test will notify the user of any unexpected
5419 // failure via stderr.
5420 if (!GTEST_FLAG(break_on_failure))
5421 _set_abort_behavior(
5422 0x0, // Clear the following flags:
5423 _WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump.
5424
5425 // In debug mode, the Windows CRT can crash with an assertion over invalid
5426 // input (e.g. passing an invalid file descriptor). The default handling
5427 // for these assertions is to pop up a dialog and wait for user input.
5428 // Instead ask the CRT to dump such assertions to stderr non-interactively.
5429 if (!IsDebuggerPresent()) {
5430 (void)_CrtSetReportMode(_CRT_ASSERT,
5431 _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
5432 (void)_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
5433 }
5434# endif
5435 }
5436#endif // GTEST_OS_WINDOWS
5437
5439 impl(),
5441 "auxiliary test code (environments or event listeners)") ? 0 : 1;
5442}
#define GTEST_FLAG(name)
Definition: gtest-port.h:2205
int RunAllTests()
Result HandleExceptionsInMethodIfSupported(T *object, Result(T::*method)(), const char *location)
Definition: gtest.cc:2615
const char * GetEnv(const char *name)
Definition: gtest-port.h:2103

◆ skipped_test_count()

int testing::UnitTest::skipped_test_count ( ) const

Definition at line 5180 of file gtest.cc.

5180 {
5181 return impl()->skipped_test_count();
5182}

◆ start_timestamp()

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

Definition at line 5210 of file gtest.cc.

5210 {
5211 return impl()->start_timestamp();
5212}

◆ successful_test_case_count()

int testing::UnitTest::successful_test_case_count ( ) const

Definition at line 5160 of file gtest.cc.

5160 {
5161 return impl()->successful_test_suite_count();
5162}

◆ successful_test_count()

int testing::UnitTest::successful_test_count ( ) const

Definition at line 5175 of file gtest.cc.

5175 {
5176 return impl()->successful_test_count();
5177}

◆ successful_test_suite_count()

int testing::UnitTest::successful_test_suite_count ( ) const

Definition at line 5138 of file gtest.cc.

5138 {
5139 return impl()->successful_test_suite_count();
5140}

◆ test_case_to_run_count()

int testing::UnitTest::test_case_to_run_count ( ) const

Definition at line 5169 of file gtest.cc.

5169 {
5170 return impl()->test_suite_to_run_count();
5171}

◆ test_suite_to_run_count()

int testing::UnitTest::test_suite_to_run_count ( ) const

Definition at line 5154 of file gtest.cc.

5154 {
5155 return impl()->test_suite_to_run_count();
5156}

◆ test_to_run_count()

int testing::UnitTest::test_to_run_count ( ) const

Definition at line 5206 of file gtest.cc.

5206{ return impl()->test_to_run_count(); }

◆ total_test_case_count()

int testing::UnitTest::total_test_case_count ( ) const

Definition at line 5166 of file gtest.cc.

5166 {
5167 return impl()->total_test_suite_count();
5168}

◆ total_test_count()

int testing::UnitTest::total_test_count ( ) const

Definition at line 5203 of file gtest.cc.

5203{ return impl()->total_test_count(); }

◆ total_test_suite_count()

int testing::UnitTest::total_test_suite_count ( ) const

Definition at line 5148 of file gtest.cc.

5148 {
5149 return impl()->total_test_suite_count();
5150}

Friends And Related Function Documentation

◆ AddGlobalTestEnvironment

Environment * AddGlobalTestEnvironment ( Environment env)
friend

Definition at line 1493 of file gtest.h.

1493 {
1494 return UnitTest::GetInstance()->AddEnvironment(env);
1495}
static UnitTest * GetInstance()
Definition: gtest.cc:5123

◆ internal::AssertHelper

friend class internal::AssertHelper
friend

Definition at line 1436 of file gtest.h.

◆ internal::GetIgnoredParameterizedTestSuites

std::set< std::string > * internal::GetIgnoredParameterizedTestSuites ( )
friend

◆ internal::GetUnitTestImpl

internal::UnitTestImpl * internal::GetUnitTestImpl ( )
friend

◆ internal::ReportFailureInUnknownLocation

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

◆ internal::StreamingListenerTest

friend class internal::StreamingListenerTest
friend

Definition at line 1437 of file gtest.h.

◆ internal::UnitTestRecordPropertyTestHelper

Definition at line 1438 of file gtest.h.

◆ ScopedTrace

friend class ScopedTrace
friend

Definition at line 1434 of file gtest.h.

◆ Test

friend class Test
friend

Definition at line 1435 of file gtest.h.


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