unit-wget.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <catch2/catch.hpp>
  2. #include <iostream>
  3. #include <thread>
  4. #include <gul/net/curl.h>
  5. template<typename callable_t>
  6. void split_path(std::string const &s, std::string const &delimiter, callable_t &&C )
  7. {
  8. size_t pos_start = 0, pos_end, delim_len = delimiter.length();
  9. while ((pos_end = s.find (delimiter, pos_start)) != std::string::npos)
  10. {
  11. std::string_view S( &s[pos_start], pos_end-pos_start);
  12. pos_start = pos_end + delim_len;
  13. C(S);
  14. }
  15. std::string_view S( &s[pos_start], s.size()-pos_start);
  16. C(S);
  17. }
  18. SCENARIO("Test download file")
  19. {
  20. gul::HTTP2 curl;
  21. curl.CURL_ADDITIONAL_FLAGS += " --insecure ";
  22. //curl.CURL_ADDITIONAL_FLAGS.clear();
  23. REQUIRE( gul::fs::exists( curl.CURL_PATH));
  24. auto path = curl.cache_file("https://ifconfig.me");
  25. #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
  26. #else
  27. std::system("find /tmp");
  28. #endif
  29. auto path2 = curl.get("https://ifconfig.me");
  30. REQUIRE(path == path2);
  31. REQUIRE(gul::fs::exists(path2));
  32. std::cout << path.string() << std::endl;
  33. }