56 lines
1.5 KiB
C++
56 lines
1.5 KiB
C++
/**
|
|
* RPC lowlevel writer
|
|
* - Writes messagepack
|
|
* -
|
|
*/
|
|
#include <di/rpc/lowlevel.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "tests/buffer.h"
|
|
|
|
#define TEST_DI_RPC_LL_MSG_DATA_SIZE 64
|
|
|
|
DI_BUFFER_DECL(buf1, TEST_DI_RPC_LL_MSG_DATA_SIZE);
|
|
|
|
|
|
/**
|
|
* Check if start calculates and initialises the mpack writer correctly
|
|
* so the lowlevel header is reserved and skipped when writing messagepack data
|
|
* - writer.size should be bufferSize - DI_RPC_LL_MSG_HDR_SIZE
|
|
* - writer.buffer should point to buffer + DI_RPC_LL_MSG_HDR_SIZE
|
|
*/
|
|
TEST(rpc_ll_rpc_writer, start)
|
|
{
|
|
mpack_writer_t writer;
|
|
|
|
di_buffer_init(&buf1, buf1_data, sizeof(buf1_data));
|
|
di_buffer_flush(&buf1);
|
|
|
|
EXPECT_EQ(TEST_DI_RPC_LL_MSG_DATA_SIZE, buf1.size);
|
|
EXPECT_EQ(DNOK, di_rpc_ll_rpc_writer_start(&writer, &buf1));
|
|
EXPECT_EQ(writer.size, TEST_DI_RPC_LL_MSG_DATA_SIZE - DI_RPC_LL_MSG_HDR_SIZE);
|
|
EXPECT_EQ(writer.buffer, (char *)(buf1.data + DI_RPC_LL_MSG_HDR_SIZE));
|
|
}
|
|
|
|
/**
|
|
* Check if rpc writer finishing in happy-flow writes the correct used size and
|
|
* writes the correct header with type DI_RPC_LL_MSG_TYPE_PLAIN
|
|
* 1. Initialize the writer with buffer of 64 bytes
|
|
* 2. Writes messagepack log:info
|
|
* 3. Finish writer
|
|
*/
|
|
TEST(rpc_ll_rpc_writer, finish)
|
|
{
|
|
mpack_writer_t writer;
|
|
|
|
di_buffer_init(&buf1, buf1_data, sizeof(buf1_data));
|
|
EXPECT_EQ(64U, buf1.size);
|
|
EXPECT_EQ(0, buf1.used);
|
|
di_buffer_flush(&buf1);
|
|
EXPECT_EQ(DNOK, di_rpc_ll_rpc_writer_start(&writer, &buf1));
|
|
|
|
di_rpc_ll_rpc_writer_finish(&writer, &buf1);
|
|
|
|
test_buffer_dump(&buf1);
|
|
}
|