awtk/tests/istream_file_test.cc

31 lines
901 B
C++
Raw Normal View History

2020-09-09 11:12:19 +08:00
#include "tkc/fs.h"
#include "tkc/mem.h"
#include "gtest/gtest.h"
#include "streams/file/istream_file.h"
TEST(IStreamFile, readline) {
str_t str;
tk_istream_t* is = tk_istream_file_create("tests/testdata/test_lines.txt");
str_init(&str, 1024);
ASSERT_EQ(tk_istream_read_line_str(is, &str), RET_OK);
ASSERT_STREQ(str.str, "");
ASSERT_EQ(tk_istream_read_line_str(is, &str), RET_OK);
ASSERT_STREQ(str.str, "line2");
ASSERT_EQ(tk_istream_read_line_str(is, &str), RET_OK);
ASSERT_STREQ(str.str, "");
ASSERT_EQ(tk_istream_read_line_str(is, &str), RET_OK);
ASSERT_STREQ(str.str, "line4");
ASSERT_EQ(tk_istream_read_line_str(is, &str), RET_OK);
ASSERT_STREQ(str.str, "line5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
ASSERT_NE(tk_istream_read_line_str(is, &str), RET_OK);
object_unref(OBJECT(is));
}