testcase/filesystem : Test more negative cases of setvbuf()
1. Fail to file open
2. Invalid mode check
3. If a buffer pointer is provided, then it must have a non-zero size
4. Reuse buffer
5. EBUSY test
IMXRT1050-EVKB log :
[tc_libc_stdio_setvbuf] PASS
@@ -2445,12 +2445,44 @@ static void tc_libc_stdio_setvbuf(void)
char buffer[64];
char *filename = VFS_FILE_PATH;
int ret;
+ int fp_fd;
/* setvbuf_test: DEFAULT buffering */
fp = fopen(filename, "w");
TC_ASSERT_NEQ("fopen", fp, NULL);
+ /* setvbuf_test: fail to file open */
+
+ fp_fd = fp->fs_fd;
+ fp->fs_fd = ERROR;
+ ret = setvbuf(fp, buffer, _IOFBF, 64);
+ fp->fs_fd = fp_fd;
+ TC_ASSERT_LEQ_CLEANUP("setvbuf", ret, 0, fclose(fp));
+ TC_ASSERT_EQ_CLEANUP("setvbuf", errno, EBADF, fclose(fp));
+
+ /* setvbuf_test: Invalid mode check */
+
+ ret = setvbuf(fp, NULL, ERROR, 0);
+ TC_ASSERT_LEQ_CLEANUP("setvbuf", ret, 0, fclose(fp));
+ TC_ASSERT_EQ_CLEANUP("setvbuf", errno, EINVAL, fclose(fp));
+
+ /* setvbuf_test: EINVAL error check
+ * In case that if a buffer pointer is provided and the buffer size is zero
+ */
+
+ ret = setvbuf(fp, buffer, _IOFBF, 0);
+ TC_ASSERT_LEQ_CLEANUP("setvbuf", ret, 0, fclose(fp));
+ TC_ASSERT_EQ_CLEANUP("setvbuf", errno, EINVAL, fclose(fp));
+
+ /* setvbuf_test: EBUSY test */
+
+ fp->fs_bufpos++;
+ ret = setvbuf(fp, NULL, _IOFBF, 64);
+ fp->fs_bufpos = fp->fs_bufstart;
+ TC_ASSERT_LEQ_CLEANUP("setvbuf", ret, 0, fclose(fp));
+ TC_ASSERT_EQ_CLEANUP("setvbuf", errno, EBUSY, fclose(fp));
+
/* setvbuf_test: NO buffering */
ret = setvbuf(fp, NULL, _IONBF, 0);
@@ -2458,6 +2490,11 @@ static void tc_libc_stdio_setvbuf(void)
/* setvbuf_test: FULL buffering */
+ ret = setvbuf(fp, NULL, _IOFBF, 0);
+ TC_ASSERT_LEQ_CLEANUP("setvbuf", ret, 0, fclose(fp));
+
+ /* setvbuf_test: Reuse full buffering */
+
ret = setvbuf(fp, NULL, _IOFBF, 0);
TC_ASSERT_LEQ_CLEANUP("setvbuf", ret, 0, fclose(fp));
ret = setvbuf(fp, NULL, _IONBF, 0);
@@ -2475,8 +2512,8 @@ static void tc_libc_stdio_setvbuf(void)
ret = setvbuf(fp, buffer, _IOFBF, 64);
TC_ASSERT_LEQ_CLEANUP("setvbuf", ret, 0, fclose(fp));
ret = setvbuf(fp, NULL, _IONBF, 0);
+ TC_ASSERT_LEQ_CLEANUP("setvbuf", ret, 0, fclose(fp));
fclose(fp);
- TC_ASSERT_LEQ("setvbuf", ret, 0);
TC_SUCCESS_RESULT();
}
