length_ut.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "length.h"
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <util/generic/string.h>
  4. Y_UNIT_TEST_SUITE(TestLengthIO) {
  5. Y_UNIT_TEST(TestLengthLimitedInput) {
  6. char buf[16];
  7. TStringStream s1("abcd");
  8. TLengthLimitedInput l1(&s1, 2);
  9. UNIT_ASSERT_VALUES_EQUAL(l1.Load(buf, 3), 2);
  10. UNIT_ASSERT_VALUES_EQUAL(l1.Read(buf, 1), 0);
  11. }
  12. Y_UNIT_TEST(TestCountingInput) {
  13. char buf[16];
  14. TStringStream s1("abc\ndef\n");
  15. TCountingInput l1(&s1);
  16. TString s;
  17. l1.ReadLine(s);
  18. UNIT_ASSERT_VALUES_EQUAL(l1.Counter(), 4);
  19. l1.Load(buf, 1);
  20. UNIT_ASSERT_VALUES_EQUAL(l1.Counter(), 5);
  21. l1.Skip(1);
  22. UNIT_ASSERT_VALUES_EQUAL(l1.Counter(), 6);
  23. l1.ReadLine(s);
  24. UNIT_ASSERT_VALUES_EQUAL(l1.Counter(), 8);
  25. }
  26. Y_UNIT_TEST(TestCountingOutput) {
  27. TStringStream s1;
  28. TCountingOutput l1(&s1);
  29. l1.Write('1');
  30. UNIT_ASSERT_VALUES_EQUAL(l1.Counter(), 1);
  31. l1.Write(TString("abcd"));
  32. UNIT_ASSERT_VALUES_EQUAL(l1.Counter(), 5);
  33. TString buf("aaa");
  34. IOutputStream::TPart parts[] = {{buf.data(), buf.size()}, {buf.data(), buf.size()}, {buf.data(), buf.size()}};
  35. l1.Write(parts, 3);
  36. UNIT_ASSERT_VALUES_EQUAL(l1.Counter(), 14);
  37. }
  38. } // Y_UNIT_TEST_SUITE(TestLengthIO)