TestUtil.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. }
  22. else {
  23. return lhs->getDomain() < rhs->getDomain();
  24. }
  25. }
  26. };
  27. std::unique_ptr<Cookie> createCookie(const std::string& name,
  28. const std::string& value,
  29. const std::string& domain, bool hostOnly,
  30. const std::string& path, bool secure);
  31. std::unique_ptr<Cookie> createCookie(const std::string& name,
  32. const std::string& value,
  33. time_t expiryTime,
  34. const std::string& domain, bool hostOnly,
  35. const std::string& path, bool secure);
  36. std::string fromHex(const std::string& s);
  37. // Returns hex digest of contents of file denoted by filename.
  38. std::string fileHexDigest(MessageDigest* ctx, const std::string& filename);
  39. WrDiskCacheEntry::DataCell* createDataCell(int64_t goff, const char* data,
  40. size_t offset = 0);
  41. std::shared_ptr<RequestGroup> findReservedGroup(RequestGroupMan* rgman,
  42. a2_gid_t gid);
  43. std::shared_ptr<RequestGroup> getReservedGroup(RequestGroupMan* rgman,
  44. size_t index);
  45. std::shared_ptr<RequestGroup>
  46. createRequestGroup(int32_t pieceLength, int64_t totalLength,
  47. const std::string& path, const std::string& uri,
  48. const std::shared_ptr<Option>& opt);
  49. std::shared_ptr<DownloadResult> createDownloadResult(error_code::Value result,
  50. const std::string& uri);
  51. namespace {
  52. template <typename V, typename T> bool derefFind(const V& v, const T& t)
  53. {
  54. for (auto i : v) {
  55. if (*i == *t) {
  56. return true;
  57. }
  58. }
  59. return false;
  60. }
  61. } // namespace
  62. } // namespace aria2