awtk/tests/ostream_buffered_test.cc

30 lines
902 B
C++
Raw Normal View History

2019-10-07 07:34:01 +08:00
#include "gtest/gtest.h"
2019-10-11 21:45:36 +08:00
#include "streams/mem/ostream_mem.h"
#include "streams/buffered/ostream_buffered.h"
2019-10-07 07:34:01 +08:00
TEST(OStreamBuffered, basic) {
char buff[32];
tk_ostream_t* mem = tk_ostream_mem_create((uint8_t*)buff, sizeof(buff), 0, FALSE);
tk_ostream_t* os = tk_ostream_buffered_create(mem);
memset(buff, 0x00, sizeof(buff));
ASSERT_EQ(tk_ostream_write(os, (uint8_t*)"1234", 4), 4);
ASSERT_STREQ(buff, "");
2021-09-16 16:06:55 +08:00
ASSERT_EQ(tk_ostream_buffered_get_size(os), 4u);
2019-10-07 07:34:01 +08:00
ASSERT_EQ(tk_ostream_flush(os), RET_OK);
ASSERT_STREQ(buff, "1234");
ASSERT_EQ(tk_ostream_write(os, (uint8_t*)"abcd", 4), 4);
ASSERT_EQ(tk_ostream_write(os, (uint8_t*)"abcd", 4), 4);
ASSERT_STREQ(buff, "1234");
2021-09-16 16:06:55 +08:00
ASSERT_EQ(tk_ostream_buffered_get_size(os), 8u);
2019-10-07 07:34:01 +08:00
ASSERT_EQ(tk_ostream_flush(os), RET_OK);
ASSERT_STREQ(buff, "1234abcdabcd");
tk_object_unref(TK_OBJECT(os));
tk_object_unref(TK_OBJECT(mem));
2019-10-07 07:34:01 +08:00
}