Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

86 строки
2.5 KiB

  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. #ifndef OPENSSL_HEADER_CRYPTO_TEST_GTEST_MAIN_H
  15. #define OPENSSL_HEADER_CRYPTO_TEST_GTEST_MAIN_H
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <gtest/gtest.h>
  19. #include <openssl/crypto.h>
  20. #include <openssl/err.h>
  21. #if defined(OPENSSL_WINDOWS)
  22. OPENSSL_MSVC_PRAGMA(warning(push, 3))
  23. #include <winsock2.h>
  24. OPENSSL_MSVC_PRAGMA(warning(pop))
  25. #else
  26. #include <signal.h>
  27. #endif
  28. BSSL_NAMESPACE_BEGIN
  29. class ErrorTestEventListener : public testing::EmptyTestEventListener {
  30. public:
  31. ErrorTestEventListener() {}
  32. ~ErrorTestEventListener() override {}
  33. void OnTestEnd(const testing::TestInfo &test_info) override {
  34. if (test_info.result()->Failed()) {
  35. // The test failed. Print any errors left in the error queue.
  36. ERR_print_errors_fp(stdout);
  37. } else {
  38. // The test succeeded, so any failed operations are expected. Clear the
  39. // error queue without printing.
  40. ERR_clear_error();
  41. }
  42. }
  43. };
  44. // SetupGoogleTest should be called by the test runner after
  45. // testing::InitGoogleTest has been called and before RUN_ALL_TESTS.
  46. inline void SetupGoogleTest() {
  47. CRYPTO_library_init();
  48. #if defined(OPENSSL_WINDOWS)
  49. // Initialize Winsock.
  50. WORD wsa_version = MAKEWORD(2, 2);
  51. WSADATA wsa_data;
  52. int wsa_err = WSAStartup(wsa_version, &wsa_data);
  53. if (wsa_err != 0) {
  54. fprintf(stderr, "WSAStartup failed: %d\n", wsa_err);
  55. exit(1);
  56. }
  57. if (wsa_data.wVersion != wsa_version) {
  58. fprintf(stderr, "Didn't get expected version: %x\n", wsa_data.wVersion);
  59. exit(1);
  60. }
  61. #else
  62. // Some tests create pipes. We check return values, so avoid being killed by
  63. // |SIGPIPE|.
  64. signal(SIGPIPE, SIG_IGN);
  65. #endif
  66. testing::UnitTest::GetInstance()->listeners().Append(
  67. new ErrorTestEventListener);
  68. }
  69. BSSL_NAMESPACE_END
  70. #endif // OPENSSL_HEADER_CRYPTO_TEST_GTEST_MAIN_H