ares-test-main.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <signal.h>
  2. #include <stdlib.h>
  3. #include "ares-test.h"
  4. int main(int argc, char* argv[]) {
  5. std::vector<char*> gtest_argv = {argv[0]};
  6. for (int ii = 1; ii < argc; ii++) {
  7. if (strcmp(argv[ii], "-v") == 0) {
  8. ares::test::verbose = true;
  9. } else if ((strcmp(argv[ii], "-p") == 0) && (ii + 1 < argc)) {
  10. ii++;
  11. ares::test::mock_port = atoi(argv[ii]);
  12. } else if (strcmp(argv[ii], "-4") == 0) {
  13. ares::test::families = ares::test::ipv4_family;
  14. ares::test::families_modes = ares::test::ipv4_family_both_modes;
  15. } else if (strcmp(argv[ii], "-6") == 0) {
  16. ares::test::families = ares::test::ipv6_family;
  17. ares::test::families_modes = ares::test::ipv6_family_both_modes;
  18. } else {
  19. gtest_argv.push_back(argv[ii]);
  20. }
  21. }
  22. int gtest_argc = gtest_argv.size();
  23. gtest_argv.push_back(nullptr);
  24. ::testing::InitGoogleTest(&gtest_argc, gtest_argv.data());
  25. #ifdef WIN32
  26. WORD wVersionRequested = MAKEWORD(2, 2);
  27. WSADATA wsaData;
  28. WSAStartup(wVersionRequested, &wsaData);
  29. #else
  30. signal(SIGPIPE, SIG_IGN);
  31. #endif
  32. int rc = RUN_ALL_TESTS();
  33. #ifdef WIN32
  34. WSACleanup();
  35. #endif
  36. return rc;
  37. }