awtk/tests/istream_file_test.cc

33 lines
948 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, "");
2020-09-09 11:18:41 +08:00
2020-09-09 11:12:19 +08:00
ASSERT_EQ(tk_istream_read_line_str(is, &str), RET_OK);
ASSERT_STREQ(str.str, "line2");
2020-09-09 11:18:41 +08:00
2020-09-09 11:12:19 +08:00
ASSERT_EQ(tk_istream_read_line_str(is, &str), RET_OK);
ASSERT_STREQ(str.str, "");
2020-09-09 11:18:41 +08:00
2020-09-09 11:12:19 +08:00
ASSERT_EQ(tk_istream_read_line_str(is, &str), RET_OK);
ASSERT_STREQ(str.str, "line4");
2020-09-09 11:18:41 +08:00
2020-09-09 11:12:19 +08:00
ASSERT_EQ(tk_istream_read_line_str(is, &str), RET_OK);
2020-09-09 11:18:41 +08:00
ASSERT_STREQ(str.str,
"line5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxx");
2020-09-09 11:12:19 +08:00
ASSERT_NE(tk_istream_read_line_str(is, &str), RET_OK);
2020-10-18 12:17:55 +08:00
str_reset(&str);
tk_object_unref(TK_OBJECT(is));
2020-09-09 11:12:19 +08:00
}