multi_ut.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "mem.h"
  2. #include "multi.h"
  3. #include <library/cpp/testing/unittest/registar.h>
  4. Y_UNIT_TEST_SUITE(TestMultiInput) {
  5. struct TTestCase {
  6. TMemoryInput Input1;
  7. TMemoryInput Input2;
  8. TMultiInput MultiInput;
  9. TTestCase(const TStringBuf in1, const TStringBuf in2)
  10. : Input1(in1)
  11. , Input2(in2)
  12. , MultiInput(&Input1, &Input2)
  13. {
  14. }
  15. void TestReadToResult(char c, size_t expectedRetval,
  16. const TString& expectedValue,
  17. const TString& initValue = "") {
  18. TString t = initValue;
  19. UNIT_ASSERT_VALUES_EQUAL(MultiInput.ReadTo(t, c), expectedRetval);
  20. UNIT_ASSERT_VALUES_EQUAL(t, expectedValue);
  21. }
  22. };
  23. Y_UNIT_TEST(TestReadTo) {
  24. TString t;
  25. TTestCase simpleCase("0123456789abc", "defghijk");
  26. simpleCase.TestReadToResult('7', 8, "0123456");
  27. simpleCase.TestReadToResult('f', 8, "89abcde");
  28. simpleCase.TestReadToResult('z', 5, "ghijk");
  29. }
  30. Y_UNIT_TEST(TestReadToBetweenStreams) {
  31. TTestCase case1("0123456789abc", "defghijk");
  32. case1.TestReadToResult('c', 13, "0123456789ab");
  33. case1.TestReadToResult('k', 8, "defghij");
  34. case1.TestReadToResult('z', 0, "TRASH", "TRASH");
  35. TTestCase case2("0123456789abc", "defghijk");
  36. case2.TestReadToResult('d', 14, "0123456789abc");
  37. case2.TestReadToResult('j', 6, "efghi");
  38. case2.TestReadToResult('k', 1, "", "TRASH");
  39. TTestCase case3("0123456789abc", "defghijk");
  40. case3.TestReadToResult('e', 15, "0123456789abcd");
  41. case3.TestReadToResult('j', 5, "fghi");
  42. case3.TestReadToResult('k', 1, "", "TRASH");
  43. }
  44. } // Y_UNIT_TEST_SUITE(TestMultiInput)