TestUtil.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "common.h"
  2. #include <string>
  3. #include <memory>
  4. #include "Cookie.h"
  5. #include "WrDiskCacheEntry.h"
  6. #include "GroupId.h"
  7. namespace aria2 {
  8. class MessageDigest;
  9. class RequestGroupMan;
  10. class RequestGroup;
  11. class Option;
  12. struct DownloadResult;
  13. void createFile(const std::string& filename, size_t length);
  14. std::string readFile(const std::string& path);
  15. class CookieSorter {
  16. public:
  17. bool operator()(const Cookie* lhs, const Cookie* rhs) const
  18. {
  19. if(lhs->getDomain() == rhs->getDomain()) {
  20. return lhs->getName() < rhs->getName();
  21. } else {
  22. return lhs->getDomain() < rhs->getDomain();
  23. }
  24. }
  25. };
  26. std::unique_ptr<Cookie> createCookie
  27. (const std::string& name,
  28. const std::string& value,
  29. const std::string& domain,
  30. bool hostOnly,
  31. const std::string& path,
  32. bool secure);
  33. std::unique_ptr<Cookie> createCookie
  34. (const std::string& name,
  35. const std::string& value,
  36. time_t expiryTime,
  37. const std::string& domain,
  38. bool hostOnly,
  39. const std::string& path,
  40. bool secure);
  41. std::string fromHex(const std::string& s);
  42. // Returns hex digest of contents of file denoted by filename.
  43. std::string fileHexDigest(MessageDigest* ctx, const std::string& filename);
  44. WrDiskCacheEntry::DataCell* createDataCell(int64_t goff,
  45. const char* data,
  46. size_t offset = 0);
  47. std::shared_ptr<RequestGroup> findReservedGroup
  48. (RequestGroupMan* rgman, a2_gid_t gid);
  49. std::shared_ptr<RequestGroup> getReservedGroup
  50. (RequestGroupMan* rgman, size_t index);
  51. std::shared_ptr<RequestGroup> createRequestGroup(int32_t pieceLength,
  52. int64_t totalLength,
  53. const std::string& path,
  54. const std::string& uri,
  55. const std::shared_ptr<Option>& opt);
  56. std::shared_ptr<DownloadResult> createDownloadResult
  57. (error_code::Value result, const std::string& uri);
  58. namespace {
  59. template<typename V, typename T>
  60. bool derefFind(const V& v, const T& t)
  61. {
  62. for(auto i : v) {
  63. if(*i == *t) {
  64. return true;
  65. }
  66. }
  67. return false;
  68. }
  69. } // namespace
  70. } // namespace aria2