gtest_main.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef OPENSSL_HEADER_CRYPTO_TEST_GTEST_MAIN_H
16 #define OPENSSL_HEADER_CRYPTO_TEST_GTEST_MAIN_H
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 
21 #include <gtest/gtest.h>
22 
23 #include <openssl/crypto.h>
24 #include <openssl/err.h>
25 
26 #if defined(OPENSSL_WINDOWS)
28 #include <winsock2.h>
30 #else
31 #include <signal.h>
32 #endif
33 
34 
36 
38  public:
41 
42  void OnTestEnd(const testing::TestInfo &test_info) override {
43  if (test_info.result()->Failed()) {
44  // The test failed. Print any errors left in the error queue.
46  } else {
47  // The test succeeded, so any failed operations are expected. Clear the
48  // error queue without printing.
50  }
51  }
52 };
53 
54 // SetupGoogleTest should be called by the test runner after
55 // testing::InitGoogleTest has been called and before RUN_ALL_TESTS.
56 inline void SetupGoogleTest() {
58 
59 #if defined(OPENSSL_WINDOWS)
60  // Initialize Winsock.
61  WORD wsa_version = MAKEWORD(2, 2);
62  WSADATA wsa_data;
63  int wsa_err = WSAStartup(wsa_version, &wsa_data);
64  if (wsa_err != 0) {
65  fprintf(stderr, "WSAStartup failed: %d\n", wsa_err);
66  exit(1);
67  }
68  if (wsa_data.wVersion != wsa_version) {
69  fprintf(stderr, "Didn't get expected version: %x\n", wsa_data.wVersion);
70  exit(1);
71  }
72 #else
73  // Some tests create pipes. We check return values, so avoid being killed by
74  // |SIGPIPE|.
75  signal(SIGPIPE, SIG_IGN);
76 #endif
77 
80 }
81 
83 
84 
85 #endif // OPENSSL_HEADER_CRYPTO_TEST_GTEST_MAIN_H
testing::UnitTest::listeners
TestEventListeners & listeners()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4746
testing::TestInfo
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:695
demumble_test.stdout
stdout
Definition: demumble_test.py:38
CRYPTO_library_init
#define CRYPTO_library_init
Definition: boringssl_prefix_symbols.h:1175
check_version.warning
string warning
Definition: check_version.py:46
ERR_print_errors_fp
#define ERR_print_errors_fp
Definition: boringssl_prefix_symbols.h:1437
ErrorTestEventListener::OnTestEnd
void OnTestEnd(const testing::TestInfo &test_info) override
Definition: gtest_main.h:42
testing::TestEventListeners::Append
void Append(TestEventListener *listener)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4548
python_utils.port_server.stderr
stderr
Definition: port_server.py:51
ErrorTestEventListener::ErrorTestEventListener
ErrorTestEventListener()
Definition: gtest_main.h:39
signal
static void signal(notification *n)
Definition: alts_tsi_handshaker_test.cc:107
BSSL_NAMESPACE_END
#define BSSL_NAMESPACE_END
Definition: base.h:480
err.h
crypto.h
OPENSSL_MSVC_PRAGMA
OPENSSL_MSVC_PRAGMA(warning(disable:4702))
Definition: e_aes.c:69
testing::TestInfo::result
const TestResult * result() const
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:761
push
int push(void *desc, unsigned char *buf, unsigned len)
Definition: bloaty/third_party/zlib/test/infcover.c:463
BSSL_NAMESPACE_BEGIN
Definition: trust_token_test.cc:45
ErrorTestEventListener
Definition: gtest_main.h:37
ERR_clear_error
#define ERR_clear_error
Definition: boringssl_prefix_symbols.h:1413
testing::UnitTest::GetInstance
static UnitTest * GetInstance()
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:4616
testing::EmptyTestEventListener
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1141
testing::TestResult::Failed
bool Failed() const
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:2207
SetupGoogleTest
void SetupGoogleTest()
Definition: gtest_main.h:56
ErrorTestEventListener::~ErrorTestEventListener
~ErrorTestEventListener() override
Definition: gtest_main.h:40


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:00