tesseract v5.3.3.20231005
googletest-throw-on-failure-test_.cc File Reference
#include "gtest/gtest.h"
#include <stdio.h>
#include <stdlib.h>
#include <exception>

Go to the source code of this file.

Functions

void TerminateHandler ()
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 52 of file googletest-throw-on-failure-test_.cc.

52 {
53#if GTEST_HAS_EXCEPTIONS
54 std::set_terminate(&TerminateHandler);
55#endif
56 testing::InitGoogleTest(&argc, argv);
57
58 // We want to ensure that people can use Google Test assertions in
59 // other testing frameworks, as long as they initialize Google Test
60 // properly and set the throw-on-failure mode. Therefore, we don't
61 // use Google Test's constructs for defining and running tests
62 // (e.g. TEST and RUN_ALL_TESTS) here.
63
64 // In the throw-on-failure mode with exceptions disabled, this
65 // assertion will cause the program to exit with a non-zero code.
66 EXPECT_EQ(2, 3);
67
68 // When not in the throw-on-failure mode, the control will reach
69 // here.
70 return 0;
71}
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:2043
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:6660

◆ TerminateHandler()

void TerminateHandler ( )

Definition at line 46 of file googletest-throw-on-failure-test_.cc.

46 {
47 fprintf(stderr, "%s\n", "Unhandled C++ exception terminating the program.");
48 fflush(nullptr);
49 exit(1);
50}