TestUtil.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #ifdef ENABLE_MESSAGE_DIGEST
  43. // Returns hex digest of contents of file denoted by filename.
  44. std::string fileHexDigest
  45. (const std::shared_ptr<MessageDigest>& ctx, const std::string& filename);
  46. #endif // ENABLE_MESSAGE_DIGEST
  47. WrDiskCacheEntry::DataCell* createDataCell(int64_t goff,
  48. const char* data,
  49. size_t offset = 0);
  50. std::shared_ptr<RequestGroup> findReservedGroup
  51. (const std::shared_ptr<RequestGroupMan>& rgman, a2_gid_t gid);
  52. std::shared_ptr<RequestGroup> getReservedGroup
  53. (const std::shared_ptr<RequestGroupMan>& rgman, size_t index);
  54. std::shared_ptr<RequestGroup> createRequestGroup(int32_t pieceLength,
  55. int64_t totalLength,
  56. const std::string& path,
  57. const std::string& uri,
  58. const std::shared_ptr<Option>& opt);
  59. std::shared_ptr<DownloadResult> createDownloadResult
  60. (error_code::Value result, const std::string& uri);
  61. namespace {
  62. template<typename V, typename T>
  63. bool derefFind(const V& v, const T& t)
  64. {
  65. for(auto i : v) {
  66. if(*i == *t) {
  67. return true;
  68. }
  69. }
  70. return false;
  71. }
  72. } // namespace
  73. } // namespace aria2