test/test_buffer.cpp

changeset 569
cb63f3d1236a
parent 568
8eda32d09e3d
equal deleted inserted replaced
568:8eda32d09e3d 569:cb63f3d1236a
775 775
776 TEST_F(BufferRead, GetEof) { 776 TEST_F(BufferRead, GetEof) {
777 buf.pos = buf.size; 777 buf.pos = buf.size;
778 EXPECT_EQ(cxBufferGet(&buf), EOF); 778 EXPECT_EQ(cxBufferGet(&buf), EOF);
779 } 779 }
780
781 TEST_F(BufferRead, ReadWithinBounds) {
782 buf.pos = 2;
783 char target[4];
784 auto read = cxBufferRead(&target, 1, 4, &buf);
785 ASSERT_EQ(read, 4);
786 EXPECT_EQ(memcmp(&target, "me d", 4), 0);
787 EXPECT_EQ(buf.pos, 6);
788 }
789
790 TEST_F(BufferRead, ReadOutOfBounds) {
791 buf.pos = 6;
792 char target[4];
793 auto read = cxBufferRead(&target, 1, 4, &buf);
794 ASSERT_EQ(read, 3);
795 EXPECT_EQ(memcmp(&target, "ata", 3), 0);
796 EXPECT_EQ(buf.pos, 9);
797 }
798
799 TEST_F(BufferRead, ReadOutOfBoundsMultibyte) {
800 buf.pos = 6;
801 char target[4];
802 target[2] = '\0';
803 auto read = cxBufferRead(&target, 2, 2, &buf);
804 ASSERT_EQ(read, 1);
805 EXPECT_EQ(memcmp(&target, "at\0", 3), 0);
806 EXPECT_EQ(buf.pos, 8);
807 }
808
809 TEST_F(BufferRead, ReadEof) {
810 buf.pos = 9;
811 char target[4];
812 auto read = cxBufferRead(&target, 1, 1, &buf);
813 ASSERT_EQ(read, 0);
814 EXPECT_EQ(buf.pos, 9);
815 }

mercurial