Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #873, allow nullptr as an input with buffer constructor with an a… #883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Fw/Buffer/Buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ Buffer::Buffer(const Buffer& src) : Serializable(),
{}

Buffer::Buffer(U8* data, U32 size, U32 context) : Serializable(),
m_serialize_repr(data, size),
m_serialize_repr(),
m_bufferData(data),
m_size(size),
m_context(context)
{}
{
if(m_bufferData != NULL){
this->m_serialize_repr.setExtBuffer(m_bufferData, m_size);
}
}

Buffer& Buffer::operator=(const Buffer& src) {
// Ward against self-assignment
Expand Down
7 changes: 6 additions & 1 deletion Fw/Buffer/test/ut/TestBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ void test_basic() {
ASSERT_EQ(buffer_new.getContext(), 1234);
ASSERT_EQ(buffer, buffer_new);

// Creating empty buffer
Fw::Buffer testBuffer(nullptr,0);
ASSERT_EQ(testBuffer.getData(), nullptr);
ASSERT_EQ(testBuffer.getSize(), 0);

// Assignment operator with transitivity
Fw::Buffer buffer_assignment1, buffer_assignment2;
ASSERT_NE(buffer_assignment1.getData(), data);
Expand Down Expand Up @@ -133,4 +138,4 @@ TEST(Nominal, Serialization) {
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
}