proxygen
MoveToFbStringTest Class Reference
Inheritance diagram for MoveToFbStringTest:

Protected Member Functions

void SetUp () override
 
std::unique_ptr< IOBufmakeBuf ()
 
void check (std::unique_ptr< IOBuf > &buf)
 

Protected Attributes

int elementSize_
 
int elementCount_
 
bool shared_
 
BufType type_
 
std::unique_ptr< IOBufbuf_
 
std::unique_ptr< IOBufbuf2_
 
std::vector< std::unique_ptr< uint8_t[]> > ownedBuffers_
 

Detailed Description

Definition at line 852 of file IOBufTest.cpp.

Member Function Documentation

void MoveToFbStringTest::check ( std::unique_ptr< IOBuf > &  buf)
inlineprotected

Definition at line 907 of file IOBufTest.cpp.

References folly::IOBuf::computeChainDataLength(), folly::IOBuf::countChainElements(), EXPECT_EQ, EXPECT_FALSE, folly::IOBuf::isChained(), folly::IOBuf::length(), and folly::IOBuf::moveToFbString().

907  {
908  fbstring str = buf->moveToFbString();
909  EXPECT_EQ(elementCount_ * elementSize_, str.size());
910  EXPECT_EQ(elementCount_ * elementSize_, strspn(str.c_str(), "x"));
911  EXPECT_EQ(0, buf->length());
912  EXPECT_EQ(1, buf->countChainElements());
914  EXPECT_FALSE(buf->isChained());
915  }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
fbstring moveToFbString()
Definition: IOBuf.cpp:968
bool isChained() const
Definition: IOBuf.h:760
size_t countChainElements() const
Definition: IOBuf.cpp:493
std::size_t length() const
Definition: IOBuf.h:533
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
basic_fbstring< char > fbstring
Definition: FBString.h:2904
std::unique_ptr<IOBuf> MoveToFbStringTest::makeBuf ( )
inlineprotected

Definition at line 874 of file IOBufTest.cpp.

References folly::IOBuf::append(), CREATE, data, folly::gen::move, TAKE_OWNERSHIP_CUSTOM, TAKE_OWNERSHIP_MALLOC, testFreeFn(), type_, uint8_t, USER_OWNED, and folly::IOBuf::writableData().

874  {
875  unique_ptr<IOBuf> buf;
876  switch (type_) {
877  case CREATE:
878  buf = IOBuf::create(elementSize_);
879  buf->append(elementSize_);
880  break;
881  case TAKE_OWNERSHIP_MALLOC: {
882  void* data = malloc(elementSize_);
883  if (!data) {
884  throw std::bad_alloc();
885  }
886  buf = IOBuf::takeOwnership(data, elementSize_);
887  break;
888  }
889  case TAKE_OWNERSHIP_CUSTOM: {
890  uint8_t* data = new uint8_t[elementSize_];
891  buf = IOBuf::takeOwnership(data, elementSize_, testFreeFn);
892  break;
893  }
894  case USER_OWNED: {
895  unique_ptr<uint8_t[]> data(new uint8_t[elementSize_]);
896  buf = IOBuf::wrapBuffer(data.get(), elementSize_);
897  ownedBuffers_.emplace_back(std::move(data));
898  break;
899  }
900  default:
901  throw std::invalid_argument("unexpected buffer type parameter");
902  }
903  memset(buf->writableData(), 'x', elementSize_);
904  return buf;
905  }
void testFreeFn(void *buffer, void *ptr)
Definition: IOBufTest.cpp:595
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::vector< std::unique_ptr< uint8_t[]> > ownedBuffers_
Definition: IOBufTest.cpp:923
uint8_t * writableData()
Definition: IOBuf.h:509
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
void append(std::size_t amount)
Definition: IOBuf.h:689
void MoveToFbStringTest::SetUp ( )
inlineoverrideprotected

Definition at line 855 of file IOBufTest.cpp.

References EXPECT_EQ, i, makeBuf(), and type_.

855  {
856  elementSize_ = std::get<0>(GetParam());
857  elementCount_ = std::get<1>(GetParam());
858  shared_ = std::get<2>(GetParam());
859  type_ = std::get<3>(GetParam());
860 
861  buf_ = makeBuf();
862  for (int i = 0; i < elementCount_ - 1; ++i) {
863  buf_->prependChain(makeBuf());
864  }
865  EXPECT_EQ(elementCount_, buf_->countChainElements());
866  EXPECT_EQ(elementCount_ * elementSize_, buf_->computeChainDataLength());
867  if (shared_) {
868  buf2_ = buf_->clone();
869  EXPECT_EQ(elementCount_, buf2_->countChainElements());
870  EXPECT_EQ(elementCount_ * elementSize_, buf2_->computeChainDataLength());
871  }
872  }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::unique_ptr< IOBuf > buf2_
Definition: IOBufTest.cpp:922
std::unique_ptr< IOBuf > makeBuf()
Definition: IOBufTest.cpp:874
std::unique_ptr< IOBuf > buf_
Definition: IOBufTest.cpp:921

Member Data Documentation

std::unique_ptr<IOBuf> MoveToFbStringTest::buf2_
protected

Definition at line 922 of file IOBufTest.cpp.

std::unique_ptr<IOBuf> MoveToFbStringTest::buf_
protected

Definition at line 921 of file IOBufTest.cpp.

int MoveToFbStringTest::elementCount_
protected

Definition at line 918 of file IOBufTest.cpp.

int MoveToFbStringTest::elementSize_
protected

Definition at line 917 of file IOBufTest.cpp.

std::vector<std::unique_ptr<uint8_t[]> > MoveToFbStringTest::ownedBuffers_
protected

Definition at line 923 of file IOBufTest.cpp.

bool MoveToFbStringTest::shared_
protected

Definition at line 919 of file IOBufTest.cpp.

BufType MoveToFbStringTest::type_
protected

Definition at line 920 of file IOBufTest.cpp.


The documentation for this class was generated from the following file: