TestUtil.h 2.2 KB

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