@@ -75,7 +75,16 @@ static void tests_spiffs_write(void)
7575 res = vfs_read (fd , r_buf , sizeof (r_buf ));
7676 TEST_ASSERT (res == sizeof (buf ));
7777 TEST_ASSERT_EQUAL_STRING (& buf [0 ], & r_buf [0 ]);
78- printf ("read buf: %s\n" , r_buf );
78+
79+ res = vfs_close (fd );
80+ TEST_ASSERT (res == 0 );
81+
82+ fd = vfs_open ("/test.txt" , O_RDONLY , 0 );
83+ TEST_ASSERT (fd >= 0 );
84+
85+ res = vfs_read (fd , r_buf , sizeof (r_buf ));
86+ TEST_ASSERT (res == sizeof (buf ));
87+ TEST_ASSERT_EQUAL_STRING (& buf [0 ], & r_buf [0 ]);
7988
8089 res = vfs_close (fd );
8190 TEST_ASSERT (res == 0 );
@@ -178,6 +187,56 @@ static void tests_spiffs_readdir(void)
178187 TEST_ASSERT (res >= 0 );
179188}
180189
190+ static void tests_spiffs_rename (void )
191+ {
192+ const char buf [] = "TESTSTRING" ;
193+ char r_buf [2 * sizeof (buf )];
194+
195+ int mp = vfs_mount (& spiffs_file_system , "/" , & spiffs_desc );
196+ TEST_ASSERT (mp >= 0 );
197+
198+ int fd = vfs_open ("/test.txt" , O_CREAT | O_RDWR , 0 );
199+ TEST_ASSERT (fd >= 0 );
200+
201+ int res = vfs_write (fd , buf , sizeof (buf ));
202+ TEST_ASSERT (res == sizeof (buf ));
203+
204+ res = vfs_lseek (fd , 0 , SEEK_SET );
205+ TEST_ASSERT (res == 0 );
206+
207+ res = vfs_read (fd , r_buf , sizeof (r_buf ));
208+ TEST_ASSERT (res == sizeof (buf ));
209+ TEST_ASSERT_EQUAL_STRING (& buf [0 ], & r_buf [0 ]);
210+
211+ res = vfs_close (fd );
212+ TEST_ASSERT (res == 0 );
213+
214+ res = vfs_rename ("/test.txt" , "/test1.txt" );
215+ TEST_ASSERT (res == 0 );
216+
217+ fd = vfs_open ("/test.txt" , O_RDONLY , 0 );
218+ TEST_ASSERT (fd < 0 );
219+
220+ fd = vfs_open ("/test1.txt" , O_RDONLY , 0 );
221+ TEST_ASSERT (fd >= 0 );
222+
223+ res = vfs_lseek (fd , 0 , SEEK_SET );
224+ TEST_ASSERT (res == 0 );
225+
226+ res = vfs_read (fd , r_buf , sizeof (r_buf ));
227+ TEST_ASSERT (res == sizeof (buf ));
228+ TEST_ASSERT_EQUAL_STRING (& buf [0 ], & r_buf [0 ]);
229+
230+ res = vfs_close (fd );
231+ TEST_ASSERT (res == 0 );
232+
233+ res = vfs_unlink ("/test1.txt" );
234+ TEST_ASSERT (res == 0 );
235+
236+ res = vfs_umount (mp );
237+ TEST_ASSERT (res >= 0 );
238+ }
239+
181240Test * tests_spiffs_tests (void )
182241{
183242 EMB_UNIT_TESTFIXTURES (fixtures ) {
@@ -186,6 +245,7 @@ Test *tests_spiffs_tests(void)
186245 new_TestFixture (tests_spiffs_write ),
187246 new_TestFixture (tests_spiffs_unlink ),
188247 new_TestFixture (tests_spiffs_readdir ),
248+ new_TestFixture (tests_spiffs_rename ),
189249 };
190250
191251 EMB_UNIT_TESTCALLER (spiffs_tests , NULL , NULL , fixtures );
0 commit comments