Commit 1eebbf2d by Marcus Winter Committed by unknown

mtapi_network_c: buffer push/pop operations return number of bytes pushed

parent a71ceed0
......@@ -45,7 +45,7 @@ int embb_mtapi_network_buffer_push_back_int16(
}
memcpy(that->data + that->size, &value, 2);
that->size += 2;
return 1;
return 2;
}
int embb_mtapi_network_buffer_push_back_int32(
......@@ -56,7 +56,7 @@ int embb_mtapi_network_buffer_push_back_int32(
}
memcpy(that->data + that->size, &value, 4);
that->size += 4;
return 1;
return 4;
}
int embb_mtapi_network_buffer_push_back_rawdata(
......@@ -68,7 +68,7 @@ int embb_mtapi_network_buffer_push_back_rawdata(
}
memcpy(that->data + that->size, rawdata, size);
that->size += size;
return 1;
return size;
}
int embb_mtapi_network_buffer_pop_front_int8(
......
......@@ -25,8 +25,11 @@
*/
#include <embb_mtapi_network_test_buffer.h>
#include <embb_mtapi_network_buffer.h>
#include <embb/base/c/memory_allocation.h>
NetworkBufferTest::NetworkBufferTest() {
CreateUnit("mtapi network buffer test").Add(&NetworkBufferTest::TestBasic, this);
......@@ -34,20 +37,31 @@ NetworkBufferTest::NetworkBufferTest() {
void NetworkBufferTest::TestBasic() {
embb_mtapi_network_buffer_t buffer;
int err;
embb_mtapi_network_buffer_initialize(&buffer, 1024);
embb_mtapi_network_buffer_push_back_int8(&buffer, -1);
embb_mtapi_network_buffer_push_back_int16(&buffer, -2);
err = embb_mtapi_network_buffer_push_back_int8(&buffer, -1);
PT_EXPECT(err == 1);
err = embb_mtapi_network_buffer_push_back_int16(&buffer, -2);
PT_EXPECT(err == 2);
int8_t val8 = 0;
int result = embb_mtapi_network_buffer_pop_front_int8(&buffer, &val8);
PT_EXPECT(result == 1);
err = embb_mtapi_network_buffer_pop_front_int8(&buffer, &val8);
PT_EXPECT(err == 1);
PT_EXPECT(val8 == -1);
int32_t val32 = 0;
result = embb_mtapi_network_buffer_pop_front_int32(&buffer, &val32);
PT_EXPECT(result == 0);
err = embb_mtapi_network_buffer_pop_front_int32(&buffer, &val32);
PT_EXPECT(err == 0);
PT_EXPECT(val32 == 0);
int16_t val16 = 0;
result = embb_mtapi_network_buffer_pop_front_int16(&buffer, &val16);
PT_EXPECT(result == 2);
err = embb_mtapi_network_buffer_pop_front_int16(&buffer, &val16);
PT_EXPECT(err == 2);
PT_EXPECT(val16 == -2);
embb_mtapi_network_buffer_finalize(&buffer);
PT_EXPECT(embb_get_bytes_allocated() == 0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment