2019-10-08 18:12:52 +08:00
|
|
|
|
#include "gtest/gtest.h"
|
2019-10-11 21:45:36 +08:00
|
|
|
|
#include "streams/mem/istream_mem.h"
|
|
|
|
|
#include "streams/buffered/istream_buffered.h"
|
2019-10-08 18:12:52 +08:00
|
|
|
|
|
|
|
|
|
TEST(IStreamBuffered, basic) {
|
|
|
|
|
char c = 0;
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
|
const char* str =
|
|
|
|
|
"1234567890qwertyutyuioyupisdfaasdfasdfjaserwqqerlqo20341qasdfasdfas34 q234134132";
|
|
|
|
|
tk_istream_t* mem = tk_istream_mem_create((uint8_t*)str, sizeof(str), 0, FALSE);
|
|
|
|
|
tk_istream_t* is = tk_istream_buffered_create(mem, 32);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(str); i++) {
|
2019-10-16 11:13:04 +08:00
|
|
|
|
if (i != 0) {
|
2021-12-08 15:20:36 +08:00
|
|
|
|
ASSERT_EQ(tk_object_get_prop_bool(TK_OBJECT(is), TK_STREAM_PROP_HAS_BUFFERED_DATA, FALSE),
|
|
|
|
|
TRUE);
|
2019-10-16 09:57:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 18:12:52 +08:00
|
|
|
|
ASSERT_EQ(tk_istream_read(is, (uint8_t*)&c, 1), 1);
|
|
|
|
|
ASSERT_EQ(c == str[i], true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-02 17:57:04 +08:00
|
|
|
|
tk_object_unref(TK_OBJECT(is));
|
|
|
|
|
tk_object_unref(TK_OBJECT(mem));
|
2019-10-08 18:12:52 +08:00
|
|
|
|
}
|