Revert "Imported Upstream version 1.17.1"
[platform/upstream/c-ares.git] / test / ares-test.h
index e92bf3b..a00e53a 100644 (file)
@@ -2,13 +2,13 @@
 #ifndef ARES_TEST_H
 #define ARES_TEST_H
 
+#include "ares.h"
+
 #include "dns-proto.h"
+
 // Include ares internal file for DNS protocol constants
 #include "nameser.h"
 
-#include "ares_setup.h"
-#include "ares.h"
-
 #include "gtest/gtest.h"
 #include "gmock/gmock.h"
 
@@ -36,17 +36,6 @@ namespace test {
 
 extern bool verbose;
 extern int mock_port;
-extern const std::vector<int> both_families;
-extern const std::vector<int> ipv4_family;
-extern const std::vector<int> ipv6_family;
-
-extern const std::vector<std::pair<int, bool>> both_families_both_modes;
-extern const std::vector<std::pair<int, bool>> ipv4_family_both_modes;
-extern const std::vector<std::pair<int, bool>> ipv6_family_both_modes;
-
-// Which parameters to use in tests
-extern std::vector<int> families;
-extern std::vector<std::pair<int, bool>> families_modes;
 
 // Process all pending work on ares-owned file descriptors, plus
 // optionally the given set-of-FDs + work function.
@@ -136,7 +125,7 @@ class DefaultChannelModeTest
 // Mock DNS server to allow responses to be scripted by tests.
 class MockServer {
  public:
-  MockServer(int family, int port);
+  MockServer(int family, int port, int tcpport = 0);
   ~MockServer();
 
   // Mock method indicating the processing of a particular <name, RRtype>
@@ -279,30 +268,6 @@ struct NameInfoResult {
 };
 std::ostream& operator<<(std::ostream& os, const NameInfoResult& result);
 
-struct AddrInfoDeleter {
-  void operator() (ares_addrinfo *ptr) {
-    if (ptr) ares_freeaddrinfo(ptr);
-  }
-};
-
-// C++ wrapper for struct ares_addrinfo.
-using AddrInfo = std::unique_ptr<ares_addrinfo, AddrInfoDeleter>;
-
-std::ostream& operator<<(std::ostream& os, const AddrInfo& result);
-
-// Structure that describes the result of an ares_addrinfo_callback invocation.
-struct AddrInfoResult {
-  AddrInfoResult() : done_(false), status_(-1), timeouts_(0) {}
-  // Whether the callback has been invoked.
-  bool done_;
-  // Explicitly provided result information.
-  int status_;
-  int timeouts_;
-  // Contents of the ares_addrinfo structure, if provided.
-  AddrInfo ai_;
-};
-std::ostream& operator<<(std::ostream& os, const AddrInfoResult& result);
-
 // Standard implementation of ares callbacks that fill out the corresponding
 // structures.
 void HostCallback(void *data, int status, int timeouts,
@@ -311,8 +276,6 @@ void SearchCallback(void *data, int status, int timeouts,
                     unsigned char *abuf, int alen);
 void NameInfoCallback(void *data, int status, int timeouts,
                       char *node, char *service);
-void AddrInfoCallback(void *data, int status, int timeouts,
-                      struct ares_addrinfo *res);
 
 // Retrieve the name servers used by a channel.
 std::vector<std::string> GetNameServers(ares_channel channel);
@@ -348,40 +311,7 @@ class TempFile : public TransientFile {
   const char* filename() const { return filename_.c_str(); }
 };
 
-#ifdef _WIN32
-extern "C" {
-
-static int setenv(const char *name, const char *value, int overwrite)
-{
-  char  *buffer;
-  size_t buf_size;
-
-  if (name == NULL)
-    return -1;
-
-  if (value == NULL)
-    value = ""; /* For unset */
-
-  if (!overwrite && getenv(name) != NULL) {
-    return -1;
-  }
-
-  buf_size = strlen(name) + strlen(value) + 1 /* = */ + 1 /* NULL */;
-  buffer   = (char *)malloc(buf_size);
-  _snprintf(buffer, buf_size, "%s=%s", name, value);
-  _putenv(buffer);
-  free(buffer);
-  return 0;
-}
-
-static int unsetenv(const char *name)
-{
-  return setenv(name, NULL, 1);
-}
-
-} /* extern "C" */
-#endif
-
+#ifndef WIN32
 // RAII class for a temporary environment variable value.
 class EnvValue {
  public:
@@ -405,6 +335,7 @@ class EnvValue {
   bool restore_;
   std::string original_;
 };
+#endif
 
 
 #ifdef HAVE_CONTAINER
@@ -446,46 +377,6 @@ int RunInContainer(ContainerFilesystem* fs, const std::string& hostname,
 
 #endif
 
-/* Assigns virtual IO functions to a channel. These functions simply call
- * the actual system functions.
- */
-class VirtualizeIO {
-public:
-  VirtualizeIO(ares_channel);
-  ~VirtualizeIO();
-
-  static const ares_socket_functions default_functions;
-private:
-  ares_channel channel_;
-};
-
-/*
- * Slightly white-box macro to generate two runs for a given test case:
- * One with no modifications, and one with all IO functions set to use
- * the virtual io structure.
- * Since no magic socket setup or anything is done in the latter case
- * this should probably only be used for test with very vanilla IO
- * requirements.
- */
-#define VCLASS_NAME(casename, testname) Virt##casename##_##testname
-#define VIRT_NONVIRT_TEST_F(casename, testname)                                 \
-  class VCLASS_NAME(casename, testname) : public casename {                     \
-  public:                                                                       \
-    VCLASS_NAME(casename, testname)() {}                                        \
-    void InnerTestBody();                                                       \
-  };                                                                            \
-  GTEST_TEST_(casename, testname, VCLASS_NAME(casename, testname),              \
-              ::testing::internal::GetTypeId<casename>()) {                     \
-    InnerTestBody();                                                            \
-  }                                                                             \
-  GTEST_TEST_(casename, testname##_virtualized,                                 \
-              VCLASS_NAME(casename, testname),                                  \
-              ::testing::internal::GetTypeId<casename>()) {                     \
-    VirtualizeIO vio(channel_);                                                 \
-    InnerTestBody();                                                            \
-  }                                                                             \
-  void VCLASS_NAME(casename, testname)::InnerTestBody()
-
 }  // namespace test
 }  // namespace ares