test/test_buffer.cpp

changeset 568
8eda32d09e3d
parent 567
f90a7cfe2480
child 569
cb63f3d1236a
equal deleted inserted replaced
567:f90a7cfe2480 568:8eda32d09e3d
744 EXPECT_FALSE(cxBufferEof(&buf)); 744 EXPECT_FALSE(cxBufferEof(&buf));
745 buf.pos = 0; 745 buf.pos = 0;
746 cxBufferWrite("test", 1, 5, &buf); 746 cxBufferWrite("test", 1, 5, &buf);
747 EXPECT_FALSE(cxBufferEof(&buf)); 747 EXPECT_FALSE(cxBufferEof(&buf));
748 } 748 }
749
750 class BufferRead : public ::testing::Test {
751 protected:
752 CxBuffer buf{};
753
754 void SetUp() override {
755 cxBufferInit(&buf, nullptr, 16, cxDefaultAllocator, CX_BUFFER_DEFAULT);
756 buf.capacity = 8; // artificially reduce capacity to check OOB writes
757 memset(buf.space, 0, 16);
758 memcpy(buf.space, "some data", 9);
759 buf.size = 9;
760 }
761
762 void TearDown() override {
763 cxBufferDestroy(&buf);
764 }
765 };
766
767 TEST_F(BufferRead, GetByte) {
768 buf.pos = 2;
769 EXPECT_EQ(cxBufferGet(&buf), 'm');
770 EXPECT_EQ(cxBufferGet(&buf), 'e');
771 EXPECT_EQ(cxBufferGet(&buf), ' ');
772 EXPECT_EQ(cxBufferGet(&buf), 'd');
773 EXPECT_EQ(buf.pos, 6);
774 }
775
776 TEST_F(BufferRead, GetEof) {
777 buf.pos = buf.size;
778 EXPECT_EQ(cxBufferGet(&buf), EOF);
779 }

mercurial