mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
30 lines
902 B
C++
30 lines
902 B
C++
#include "gtest/gtest.h"
|
|
#include "streams/mem/ostream_mem.h"
|
|
#include "streams/buffered/ostream_buffered.h"
|
|
|
|
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, "");
|
|
ASSERT_EQ(tk_ostream_buffered_get_size(os), 4u);
|
|
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");
|
|
|
|
ASSERT_EQ(tk_ostream_buffered_get_size(os), 8u);
|
|
ASSERT_EQ(tk_ostream_flush(os), RET_OK);
|
|
ASSERT_STREQ(buff, "1234abcdabcd");
|
|
|
|
tk_object_unref(TK_OBJECT(os));
|
|
tk_object_unref(TK_OBJECT(mem));
|
|
}
|