tesseract v5.3.3.20231005
gtest_assert_by_exception_test.cc File Reference
#include "gtest/gtest.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdexcept>

Go to the source code of this file.

Classes

class  ThrowListener
 

Functions

void Fail (const char *msg)
 
 TEST (Test, Test)
 
 TEST (Test, Test2)
 
int main (int argc, char **argv)
 

Variables

int kTestForContinuingTest = 0
 

Function Documentation

◆ Fail()

void Fail ( const char *  msg)

Definition at line 52 of file gtest_assert_by_exception_test.cc.

52 {
53 printf("FAILURE: %s\n", msg);
54 fflush(stdout);
55 exit(1);
56}

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 102 of file gtest_assert_by_exception_test.cc.

102 {
103 testing::InitGoogleTest(&argc, argv);
105
106 int result = RUN_ALL_TESTS();
107 if (result == 0) {
108 printf("RUN_ALL_TESTS returned %d\n", result);
109 Fail("Expected failure instead.");
110 }
111
112 if (kTestForContinuingTest == 0) {
113 Fail("Should have continued with other tests, but did not.");
114 }
115 return 0;
116}
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2489
void Fail(const char *msg)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:6660
void Append(TestEventListener *listener)
Definition: gtest.cc:5055
static UnitTest * GetInstance()
Definition: gtest.cc:5123
TestEventListeners & listeners()
Definition: gtest.cc:5254

◆ TEST() [1/2]

TEST ( Test  ,
Test   
)

Definition at line 64 of file gtest_assert_by_exception_test.cc.

64 {
65 // A successful assertion shouldn't throw.
66 try {
67 EXPECT_EQ(3, 3);
68 } catch(...) {
69 Fail("A successful assertion wrongfully threw.");
70 }
71
72 // A successful assertion shouldn't throw.
73 try {
74 EXPECT_EQ(3, 4);
75 } catch(...) {
76 Fail("A failed non-fatal assertion wrongfully threw.");
77 }
78
79 // A failed assertion should throw.
80 try {
81 AssertFalse();
82 } catch(const testing::AssertionException& e) {
83 if (strstr(e.what(), "Expected failure") != nullptr) throw;
84
85 printf("%s",
86 "A failed assertion did throw an exception of the right type, "
87 "but the message is incorrect. Instead of containing \"Expected "
88 "failure\", it is:\n");
89 Fail(e.what());
90 } catch(...) {
91 Fail("A failed assertion threw the wrong type of exception.");
92 }
93 Fail("A failed assertion should've thrown but didn't.");
94}
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:2043

◆ TEST() [2/2]

TEST ( Test  ,
Test2   
)

Definition at line 98 of file gtest_assert_by_exception_test.cc.

98 {
100}

Variable Documentation

◆ kTestForContinuingTest

int kTestForContinuingTest = 0

Definition at line 96 of file gtest_assert_by_exception_test.cc.