io_ut.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <library/cpp/openssl/method/io.h>
  2. #include <library/cpp/testing/unittest/registar.h>
  3. class TTestIO : public NOpenSSL::TAbstractIO {
  4. public:
  5. int Write(const char* data, size_t dlen, size_t* written) override {
  6. Y_UNUSED(data);
  7. *written = dlen;
  8. return 1;
  9. }
  10. int Read(char* data, size_t dlen, size_t* readbytes) override {
  11. Y_UNUSED(data);
  12. Y_UNUSED(dlen);
  13. *readbytes = 0;
  14. return 0;
  15. }
  16. int Puts(const char* buf) override {
  17. if (buf == nullptr) {
  18. return 0;
  19. }
  20. return strlen(buf);
  21. }
  22. int Gets(char* buf, int size) override {
  23. Y_UNUSED(buf);
  24. Y_UNUSED(size);
  25. return 0;
  26. }
  27. void Flush() override {
  28. }
  29. };
  30. Y_UNIT_TEST_SUITE(IO) {
  31. Y_UNIT_TEST(AbstractIO) {
  32. static const char s[] = "12345";
  33. TTestIO test;
  34. UNIT_ASSERT(BIO_write(test, s, sizeof(s)) == sizeof(s));
  35. UNIT_ASSERT(BIO_puts(test, s) == strlen(s));
  36. char buf[128];
  37. UNIT_ASSERT(BIO_read(test, buf, sizeof(buf)) == 0);
  38. UNIT_ASSERT(BIO_gets(test, buf, sizeof(buf)) == 0);
  39. }
  40. }