pcdata_ut.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "pcdata.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. Y_UNIT_TEST_SUITE(TPcdata) {
  4. Y_UNIT_TEST(TestStress) {
  5. {
  6. ui64 key = 0x000017C0B76C4E87ull;
  7. TString res = EncodeHtmlPcdata(TStringBuf((const char*)&key, sizeof(key)));
  8. }
  9. for (size_t i = 0; i < 1000; ++i) {
  10. const TString s = NUnitTest::RandomString(i, i);
  11. UNIT_ASSERT_VALUES_EQUAL(DecodeHtmlPcdata(EncodeHtmlPcdata(s)), s);
  12. }
  13. }
  14. Y_UNIT_TEST(Test1) {
  15. const TString tests[] = {
  16. "qw&qw",
  17. "&<",
  18. ">&qw",
  19. "\'&aaa"};
  20. for (auto s : tests) {
  21. UNIT_ASSERT_VALUES_EQUAL(DecodeHtmlPcdata(EncodeHtmlPcdata(s)), s);
  22. }
  23. }
  24. Y_UNIT_TEST(Test2) {
  25. UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("&qqq"), "&amp;qqq");
  26. }
  27. Y_UNIT_TEST(TestEncodeHtmlPcdataAppend) {
  28. TString s;
  29. EncodeHtmlPcdataAppend("m&m", s);
  30. EncodeHtmlPcdataAppend("'s", s);
  31. UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's"), s);
  32. UNIT_ASSERT_VALUES_EQUAL("m&amp;m&#39;s", s);
  33. }
  34. Y_UNIT_TEST(TestStrangeAmpParameter) {
  35. UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's", true), "m&amp;m&#39;s");
  36. UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's"), "m&amp;m&#39;s"); //default
  37. UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's", false), "m&m&#39;s");
  38. }
  39. }