test utils::fgets_trunc() with buffer size of exactly the length of string

This commit is contained in:
Axel Kohlmeyer
2021-08-17 09:41:19 -04:00
parent e91185869d
commit f24054f7b3

View File

@ -119,13 +119,15 @@ TEST_F(FileOperationsTest, fgets_trunc)
FILE *fp = fopen("safe_file_read_test.txt", "rb");
ASSERT_NE(fp, nullptr);
// read line shorter than buffer
memset(buf, 0, MAX_BUF_SIZE);
ptr = utils::fgets_trunc(buf, MAX_BUF_SIZE, fp);
ASSERT_THAT(buf, StrEq("one line\n"));
ASSERT_NE(ptr,nullptr);
// read line of exactly the buffer length
memset(buf, 0, MAX_BUF_SIZE);
ptr = utils::fgets_trunc(buf, MAX_BUF_SIZE, fp);
ptr = utils::fgets_trunc(buf, sizeof("two_lines\n"), fp);
ASSERT_THAT(buf, StrEq("two_lines\n"));
ASSERT_NE(ptr,nullptr);