Skip to content

Commit ce8ea66

Browse files
authored
Merge pull request #4 from JoyStream/development
development to master
2 parents aa1fdea + 26eefd3 commit ce8ea66

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

src/char_array_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
char_array_buffer::char_array_buffer(char *begin, char *end) {
66
// end pointer should be one location past the last element in the array
77

8-
if(begin == end || begin > end || begin == nullptr || end == nullptr) {
8+
if(begin > end || begin == nullptr || end == nullptr) {
99
throw std::runtime_error("stream buffer initialized with invalid pointers");
1010
}
1111

test/test_main.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,32 @@ struct Stream {
2727
InputWireStream reader() { return InputWireStream(&buffer); }
2828
};
2929

30+
TEST(protocol_wire_test, zero_size_char_array_buffer) {
31+
char data[] = { 0x11 };
32+
char data_to_write[] = {0, 1, 2, 3};
33+
char output;
34+
35+
// Empty Array
36+
char_array_buffer buff(data, data);
37+
38+
// No data available
39+
EXPECT_EQ(buff.in_avail(), 0);
40+
41+
// Cannot seek into the buffer
42+
EXPECT_EQ(buff.pubseekpos(1, std::ios::in), std::streamoff(-1));
43+
44+
// Get EOF when trying to read from buffer
45+
EXPECT_EQ(buff.sgetc(), EOF);
46+
EXPECT_EQ(buff.sgetc(), std::streamoff(-1));
47+
48+
// Bytes read should be zero when trying to read from stream
49+
EXPECT_EQ(buff.sgetn(&output, 1), std::streamsize(0));
50+
51+
// Cannot write into the buffer
52+
EXPECT_EQ(buff.sputc(0x00), std::streamoff(-1));
53+
EXPECT_EQ(buff.sputn(data_to_write, sizeof(data_to_write)), std::streamsize(0));
54+
}
55+
3056
TEST(protocol_wire_test, char_array_buffer) {
3157
char data[] = {0, 0, 0, 0, 0};
3258
char_array_buffer buff(data, data + sizeof(data));

0 commit comments

Comments
 (0)