2018-12-15 17:22:05 +08:00
|
|
|
|
#include "tkc/fs.h"
|
|
|
|
|
#include "tkc/mem.h"
|
2018-04-27 18:12:12 +08:00
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
TEST(Fs, basic) {
|
|
|
|
|
char buff[128];
|
|
|
|
|
uint32_t size = 0;
|
|
|
|
|
const char* str = "hello world";
|
|
|
|
|
const char* filename = "test.bin";
|
|
|
|
|
|
2018-08-26 07:14:32 +08:00
|
|
|
|
file_write(filename, str, strlen(str));
|
|
|
|
|
char* ret = (char*)file_read(filename, &size);
|
|
|
|
|
ASSERT_EQ(file_read_part(filename, buff, sizeof(buff), 0), strlen(str));
|
2018-04-27 18:12:12 +08:00
|
|
|
|
ASSERT_EQ(strcmp(ret, str), 0);
|
|
|
|
|
ASSERT_EQ(size, strlen(str));
|
2018-08-26 07:14:32 +08:00
|
|
|
|
file_remove(filename);
|
2018-04-29 16:51:54 +08:00
|
|
|
|
TKMEM_FREE(ret);
|
2018-04-27 18:12:12 +08:00
|
|
|
|
}
|
2019-10-15 15:11:59 +08:00
|
|
|
|
|
|
|
|
|
TEST(Fs, eof) {
|
|
|
|
|
char buff[128];
|
|
|
|
|
uint32_t size = 0;
|
|
|
|
|
const char* str = "hello world";
|
|
|
|
|
const char* filename = "test.bin";
|
|
|
|
|
|
|
|
|
|
file_write(filename, str, strlen(str));
|
|
|
|
|
|
|
|
|
|
fs_file_t* f = fs_open_file(os_fs(), filename, "r");
|
2019-10-16 11:07:30 +08:00
|
|
|
|
memset(buff, 0x00, sizeof(buff));
|
2019-10-15 15:11:59 +08:00
|
|
|
|
fs_file_read(f, buff, sizeof(buff));
|
|
|
|
|
ASSERT_STREQ(buff, str);
|
|
|
|
|
ASSERT_EQ(fs_file_eof(f), TRUE);
|
|
|
|
|
fs_file_close(f);
|
|
|
|
|
|
|
|
|
|
file_remove(filename);
|
|
|
|
|
}
|