structures_tests.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "cpr/cprtypes.h"
  2. #include <gtest/gtest.h>
  3. #include <string>
  4. #include <cpr/parameters.h>
  5. #include <cpr/payload.h>
  6. using namespace cpr;
  7. TEST(PayloadTests, UseStringVariableTest) {
  8. std::string value1 = "hello";
  9. std::string key2 = "key2";
  10. Payload payload{{"key1", value1}, {key2, "world"}};
  11. std::string expected = "key1=hello&key2=world";
  12. EXPECT_EQ(payload.GetContent(CurlHolder()), expected);
  13. }
  14. TEST(PayloadTests, DisableEncodingTest) {
  15. std::string key1 = "key1";
  16. std::string key2 = "key2§$%&/";
  17. std::string value1 = "hello.,.,";
  18. std::string value2 = "hello";
  19. Payload payload{{key1, value1}, {key2, value2}};
  20. payload.encode = false;
  21. std::string expected = key1 + '=' + value1 + '&' + key2 + '=' + value2;
  22. EXPECT_EQ(payload.GetContent(CurlHolder()), expected);
  23. }
  24. TEST(ParametersTests, UseStringVariableTest) {
  25. std::string value1 = "hello";
  26. std::string key2 = "key2";
  27. Parameters parameters{{"key1", value1}, {key2, "world"}};
  28. std::string expected = "key1=hello&key2=world";
  29. EXPECT_EQ(parameters.GetContent(CurlHolder()), expected);
  30. }
  31. TEST(ParametersTests, DisableEncodingTest) {
  32. std::string key1 = "key1";
  33. std::string key2 = "key2§$%&/";
  34. std::string value1 = "hello.,.,";
  35. std::string value2 = "hello";
  36. Parameters parameters{{key1, value1}, {key2, value2}};
  37. parameters.encode = false;
  38. std::string expected = key1 + '=' + value1 + '&' + key2 + '=' + value2;
  39. EXPECT_EQ(parameters.GetContent(CurlHolder()), expected);
  40. }
  41. TEST(UrlToAndFromString, UrlTests) {
  42. std::string s{"https://github.com/whoshuu/cpr"};
  43. cpr::Url url = s;
  44. EXPECT_EQ(s, url.str());
  45. }
  46. int main(int argc, char** argv) {
  47. ::testing::InitGoogleTest(&argc, argv);
  48. return RUN_ALL_TESTS();
  49. }