1 /*
2  * Copyright (c) 2024 Linumiz
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <errno.h>
8 #include <stdio.h>
9 #include <zephyr/kernel.h>
10 #include <zephyr/sys/__assert.h>
11 #include <zephyr/ztest.h>
12 #include <zephyr/ztest_error_hook.h>
13 #include <ff.h>
14 #include <zephyr/fs/fs.h>
15 
16 #define FATFS_MNTP	"/RAM:"
17 #define TEST_FILE	FATFS_MNTP"/testfile.txt"
18 
19 static FATFS fat_fs;
20 
21 static struct fs_mount_t fatfs_mnt = {
22 	.type = FS_FATFS,
23 	.mnt_point = FATFS_MNTP,
24 	.fs_data = &fat_fs,
25 };
26 
27 ZTEST_SUITE(libc_stdio, NULL, NULL, NULL, NULL, NULL);
28 
29 /**
30  * @brief Test for remove API
31  *
32  * @details Test deletes a file through remove API.
33  */
ZTEST(libc_stdio,test_remove)34 ZTEST(libc_stdio, test_remove)
35 {
36 	struct fs_file_t file;
37 
38 	fs_file_t_init(&file);
39 
40 	zassert_ok(fs_mount(&fatfs_mnt), "Error in mount file system\n");
41 	zassert_equal(fs_open(&file, TEST_FILE, FS_O_CREATE), 0,
42 		      "Error creating file\n");
43 	zassert_ok(fs_close(&file), "Error closing file\n");
44 	zassert_ok(remove(TEST_FILE), "Error removing file: %d\n", errno);
45 	zassert_equal(remove(""), -1, "Error Invalid path removed\n");
46 	zassert_equal(remove(NULL), -1, "Error Invalid path removed\n");
47 	zassert_ok(fs_unmount(&fatfs_mnt), "Error while unmount file system\n");
48 }
49