選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

72 行
2.1 KiB

  1. /* Copyright (c) 2016, 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. #include <gtest/gtest.h>
  15. #include <stdio.h>
  16. #include <openssl/err.h>
  17. #include <openssl/crypto.h>
  18. #if defined(OPENSSL_WINDOWS)
  19. OPENSSL_MSVC_PRAGMA(warning(push, 3))
  20. #include <winsock2.h>
  21. OPENSSL_MSVC_PRAGMA(warning(pop))
  22. #endif
  23. namespace {
  24. class ErrorTestEventListener : public testing::EmptyTestEventListener {
  25. public:
  26. ErrorTestEventListener() {}
  27. ~ErrorTestEventListener() override {}
  28. void OnTestEnd(const testing::TestInfo &test_info) override {
  29. // If the test failed, print any errors left in the error queue.
  30. if (test_info.result()->Failed()) {
  31. ERR_print_errors_fp(stdout);
  32. }
  33. // Clean up the error queue for the next run.
  34. ERR_clear_error();
  35. }
  36. };
  37. } // namespace
  38. int main(int argc, char **argv) {
  39. CRYPTO_library_init();
  40. #if defined(OPENSSL_WINDOWS)
  41. // Initialize Winsock.
  42. WORD wsa_version = MAKEWORD(2, 2);
  43. WSADATA wsa_data;
  44. int wsa_err = WSAStartup(wsa_version, &wsa_data);
  45. if (wsa_err != 0) {
  46. fprintf(stderr, "WSAStartup failed: %d\n", wsa_err);
  47. return 1;
  48. }
  49. if (wsa_data.wVersion != wsa_version) {
  50. fprintf(stderr, "Didn't get expected version: %x\n", wsa_data.wVersion);
  51. return 1;
  52. }
  53. #endif
  54. testing::InitGoogleTest(&argc, argv);
  55. testing::UnitTest::GetInstance()->listeners().Append(
  56. new ErrorTestEventListener);
  57. return RUN_ALL_TESTS();
  58. }