winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

CurlConnectionManagerTests.cpp (1802B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 
      4 #include "ReportingHandler.h"
      5 #include "connection/Connection.h"
      6 #include "connection/CurlConnection.h"
      7 #include "connection/CurlConnectionManager.h"
      8 
      9 #include <catch2/catch_test_macros.hpp>
     10 #include <curl/curl.h>
     11 
     12 using namespace SFS;
     13 using namespace SFS::details;
     14 
     15 #define TEST(...) TEST_CASE("[CurlConnectionManagerTests] " __VA_ARGS__)
     16 
     17 TEST("Testing expected values in curl_version_info_data")
     18 {
     19     curl_version_info_data* ver = curl_version_info(CURLVERSION_NOW);
     20     REQUIRE(ver != nullptr);
     21     CHECK(ver->features & CURL_VERSION_SSL);
     22 
     23     // Checking thread safety is on
     24     CHECK(ver->features & CURL_VERSION_THREADSAFE);
     25 
     26     // For thread safety we need the DNS resolutions to be asynchronous (which happens because of c-ares)
     27     CHECK(ver->features & CURL_VERSION_ASYNCHDNS);
     28 }
     29 
     30 TEST("Testing CurlConnectionManager()")
     31 {
     32     ReportingHandler handler;
     33     CurlConnectionManager curlConnectionManager(handler);
     34 
     35     // Check that the CurlConnectionManager generates a CurlConnection object
     36     std::unique_ptr<Connection> Connection = curlConnectionManager.MakeConnection({});
     37     REQUIRE(Connection != nullptr);
     38     REQUIRE(dynamic_cast<CurlConnection*>(Connection.get()) != nullptr);
     39 
     40     // Having many CurlConnectionManager objects should not cause any issues, curl is smart enough to
     41     // handle multiple initialization and cleanup calls
     42     CurlConnectionManager curlConnectionManager2(handler);
     43     auto Connection2 = curlConnectionManager2.MakeConnection({});
     44 
     45     CurlConnectionManager curlConnectionManager3(handler);
     46     auto Connection3 = curlConnectionManager3.MakeConnection({});
     47     auto Connection4 = curlConnectionManager3.MakeConnection({});
     48 }