43 static const char FILE_NAME[] =
"fat_test.txt";
44 static const char FILE_NAME_UPPER[] =
"FAT_TEST.TXT";
45 static const char BOGUS_FILE_NAME[] =
"bogus.txt";
49 void error_checker (
const ErrorCode err) {
57 pwOut <<
"No print string yet for FatFS's error #" << err - FatFS::BEG_ERROR <<
" (raw = " << err <<
")\n";
59 pwOut <<
"Unknown error: " << err <<
'\n';
62 void clear_buffer (
File *file) {
64 file->m_driver->
flush(buffer);
71 PropWare::ErrorCode err;
73 err = testable->
open();
75 MESSAGE(
"Setup failed!");
81 if (NULL != testable) {
83 clear_buffer(testable);
89 TEST(ConstructorDestructor) {
93 ASSERT_NEQ_MSG(0, strcmp(FILE_NAME, FILE_NAME_UPPER));
95 ASSERT_EQ_MSG(0, strcmp(FILE_NAME_UPPER, testable->
get_name()));
96 ASSERT_EQ_MSG((
unsigned int) &
pwOut, (
unsigned int) testable->m_logger);
97 ASSERT_EQ_MSG((
unsigned int) g_fs->get_driver(), (
unsigned int) testable->m_driver);
98 ASSERT_EQ_MSG((
unsigned int) &g_fs->m_buf, (
unsigned int) testable->m_buf);
99 ASSERT_NEQ_MSG((
unsigned int) NULL, (
unsigned int) testable->m_buf->buf);
100 ASSERT_EQ_MSG((
unsigned int) &g_fs->m_dirMeta, (
unsigned int) testable->m_fsBufMeta);
101 ASSERT_EQ_MSG((
unsigned int) g_fs, (
unsigned int) testable->m_fs);
107 TEST(Exists_doesExist) {
110 PropWare::ErrorCode err;
111 const bool exists = testable->
exists(err);
117 TEST(Exists_doeesNotExist) {
119 ASSERT_FALSE(testable->
exists());
127 err = testable->
open();
129 ASSERT_EQ_MSG(0, err);
132 ASSERT_EQ_MSG((
unsigned int) &testable->m_contentMeta, (
unsigned int) testable->m_buf->meta);
133 ASSERT_NEQ_MSG(0, testable->m_buf->meta->nextTier2);
135 err = testable->
close();
137 ASSERT_EQ_MSG(0, err);
142 TEST(Open_NonExistantFile) {
150 PropWare::ErrorCode err;
156 ASSERT_EQ_MSG(0, err);
157 ASSERT_EQ_MSG(
'/', c);
163 PropWare::ErrorCode err;
166 for (
int i = 0; i < 1024; ++i) {
170 ASSERT_EQ_MSG(0, err);
172 ASSERT_EQ_MSG(i + 1, testable->
tell());
179 const int SEEK_ITERATIONS = 2048;
180 char stringBuffer[SEEK_ITERATIONS];
182 PropWare::ErrorCode err;
185 for (
int i = 0; i < SEEK_ITERATIONS - 1; ++i) {
189 ASSERT_EQ_MSG(0, err);
190 stringBuilder.put_char(c);
194 for (
int i = 0; i < 128; ++i) {
195 const int charIndex = rand() % (SEEK_ITERATIONS - 1);
198 ASSERT_EQ_MSG(0, err);
203 ASSERT_EQ_MSG(0, err);
204 ASSERT_EQ_MSG(stringBuilder.to_string()[charIndex], actual);
211 START(FatFileReaderTest);
213 PropWare::ErrorCode err;
216 if ((err = fs.mount())) {
218 failures = (uint8_t) -1;
223 RUN_TEST(ConstructorDestructor);
224 RUN_TEST(Exists_doesExist);
225 RUN_TEST(Exists_doeesNotExist);
227 RUN_TEST(Open_NonExistantFile);
228 RUN_TEST(SafeGetChar);
232 delete fs.get_driver();
virtual uint16_t get_sector_size() const =0
Return the size of a sector (also known as a "block") for the given storage device.
static void print_error_str(const Printer &printer, const ErrorCode err)
If an error occurs, this method can be used to determine what that error actually means...
Generic definitions and functions for the Parallax Propeller.
bool exists() const
Determine if a file exists (file does not have to be open)
int32_t get_length() const
Return the number of bytes (characters) in the file.
PropWare::ErrorCode safe_get_char(char &c)
Read a character from the file.
void print_error_str(const Printer *printer, const ErrorCode err) const
Print through UART an error string followed by entering an infinite loop.
const PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
PropWare::ErrorCode open()
Open the file.
Build a statically-sized string in RAM using the PropWare::Printer interface.
virtual PropWare::ErrorCode close()
Close a file - a required step in any workflow that includes opening a file.
const char * get_name() const
Determine the name of a file.
Basic file interface for opening and closing files.
A simple SD driver communicating over the SPI protocol.
PropWare::ErrorCode seek(const int32_t offset, const SeekDir way)
Sets the position of the next character to be read or written.
int32_t tell() const
Obtain the value of the file position indicator.
In-memory buffer containing a single block of data.
ErrorCode flush(Buffer *buffer) const
Flush the contents of a buffer and mark as unmodified.
Read a file on a FAT 16 or FAT 32 storage device.
static SPI * get_instance()
Best way to use SPI is through here, where you can get a shared instance of the SPI module (not threa...