4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
36 * \author Luca Ottaviano <lottaviano@develer.com>
38 * $test$: cp bertos/cfg/cfg_fat.h $cfgdir/
39 * $test$: echo "#undef CONFIG_FAT_USE_MKFS" >> $cfgdir/cfg_fat.h
40 * $test$: echo "#define CONFIG_FAT_USE_MKFS 1" >> $cfgdir/cfg_fat.h
47 #include "fatfs/diskio.h"
51 /* avoid compiler warnings... */
52 int fatfile_testSetup(void);
53 int fatfile_testTearDown(void);
54 int fatfile_testRun(void);
56 static FATFS file_system;
58 int fatfile_testSetup(void)
61 err = f_mount(0, &file_system);
64 err = f_mkfs(0, 0, 512);
69 int fatfile_testTearDown(void)
77 int fatfile_testRun(void)
82 int write[SIZE], read[SIZE];
84 fat_err = fatfile_open(&file_handler, "foo.txt", FA_WRITE | FA_CREATE_ALWAYS);
85 ASSERT(fat_err == FR_OK);
87 for (int i = 0; i < SIZE; ++i)
90 size_t count = kfile_write(&file_handler.fd, &i, sizeof(int));
91 ASSERT(count == sizeof(int));
93 /* test error function */
95 if (kfile_read(&file_handler.fd, &tmp, sizeof(int)) < sizeof(int))
96 ASSERT(kfile_error(&file_handler.fd) == FR_DENIED);
97 kfile_clearerr(&file_handler.fd);
98 ASSERT(file_handler.error_code == FR_OK);
102 err = kfile_close(&file_handler.fd);
105 fat_err = fatfile_open(&file_handler, "foo.txt", FA_READ);
106 ASSERT(fat_err == FR_OK);
108 for (int i = 0; i < SIZE; ++ i)
110 size_t count = kfile_read(&file_handler.fd, &read[i], sizeof(int));
111 ASSERT(count == sizeof(int));
112 /* check for correctness */
113 ASSERT(read[i] == write[i]);
115 /* test kfile_seek() */
116 ASSERT(kfile_seek(&file_handler.fd, -(sizeof(int) * SIZE * 2), KSM_SEEK_CUR) == 0);
117 ASSERT(kfile_seek(&file_handler.fd, sizeof(int), KSM_SEEK_END) == EOF);
119 ASSERT(kfile_close(&file_handler.fd) == 0);
121 fatfile_open(&file_handler, "foo.txt", FA_READ | FA_WRITE);
122 ASSERT((size_t)kfile_seek(&file_handler.fd, sizeof(int), KSM_SEEK_END) == sizeof(int) * (SIZE + 1));
123 ASSERT(kfile_seek(&file_handler.fd, -SIZE, KSM_SEEK_SET) == 0);