printf_ut.cpp 741 B

123456789101112131415161718192021222324252627282930313233
  1. #include "null.h"
  2. #include "printf.h"
  3. #include "str.h"
  4. #include <util/generic/string.h>
  5. #include <library/cpp/testing/unittest/registar.h>
  6. Y_UNIT_TEST_SUITE(TStreamPrintfTest) {
  7. Y_UNIT_TEST(TestPrintf) {
  8. TStringStream ss;
  9. UNIT_ASSERT_EQUAL(Printf(ss, "qw %s %d", "er", 1), 7);
  10. UNIT_ASSERT_EQUAL(ss.Str(), "qw er 1");
  11. }
  12. #ifdef __GNUC__
  13. #pragma GCC diagnostic ignored "-Wformat-zero-length"
  14. #endif // __GNUC__
  15. Y_UNIT_TEST(TestZeroString) {
  16. UNIT_ASSERT_EQUAL(Printf(Cnull, ""), 0);
  17. }
  18. Y_UNIT_TEST(TestLargePrintf) {
  19. TString s = NUnitTest::RandomString(1000000);
  20. TStringStream ss;
  21. Printf(ss, "%s", s.data());
  22. UNIT_ASSERT_EQUAL(ss.Str(), s);
  23. }
  24. }