You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

79 lines
2.3 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. #endif
  26. namespace bssl {
  27. class ErrorTestEventListener : public testing::EmptyTestEventListener {
  28. public:
  29. ErrorTestEventListener() {}
  30. ~ErrorTestEventListener() override {}
  31. void OnTestEnd(const testing::TestInfo &test_info) override {
  32. // If the test failed, print any errors left in the error queue.
  33. if (test_info.result()->Failed()) {
  34. ERR_print_errors_fp(stdout);
  35. }
  36. // Clean up the error queue for the next run.
  37. ERR_clear_error();
  38. }
  39. };
  40. // SetupGoogleTest should be called by the test runner after
  41. // testing::InitGoogleTest has been called and before RUN_ALL_TESTS.
  42. inline void SetupGoogleTest() {
  43. CRYPTO_library_init();
  44. #if defined(OPENSSL_WINDOWS)
  45. // Initialize Winsock.
  46. WORD wsa_version = MAKEWORD(2, 2);
  47. WSADATA wsa_data;
  48. int wsa_err = WSAStartup(wsa_version, &wsa_data);
  49. if (wsa_err != 0) {
  50. fprintf(stderr, "WSAStartup failed: %d\n", wsa_err);
  51. exit(1);
  52. }
  53. if (wsa_data.wVersion != wsa_version) {
  54. fprintf(stderr, "Didn't get expected version: %x\n", wsa_data.wVersion);
  55. exit(1);
  56. }
  57. #endif
  58. testing::UnitTest::GetInstance()->listeners().Append(
  59. new ErrorTestEventListener);
  60. }
  61. } // namespace bssl
  62. #endif // OPENSSL_HEADER_CRYPTO_TEST_GTEST_MAIN_H