file seek support, new test cases, AVI use file seek

This commit is contained in:
2021-02-25 07:42:27 +01:00
parent f04742a1b0
commit c89f599112
6 changed files with 189 additions and 38 deletions

View File

@@ -26,7 +26,7 @@ TEST(TestCreate, structure) {
}
TEST (TestCreat, writeRead) {
TEST (TestCreate, writeRead) {
using BlockDev = AccessHelper<TestDevice>;
using FS = FAT32::FS<BlockDev>;
@@ -96,7 +96,7 @@ TEST (TestCreat, writeRead) {
}
TEST (TestCreat, init) {
TEST (TestCreate, init) {
using BlockDev = AccessHelper<TestDevice>;
using FS = FAT32::FS<BlockDev>;
@@ -135,7 +135,7 @@ TEST (TestCreat, init) {
}
TEST (TestCreat, getOrCreateFile) {
TEST (TestCreate, getOrCreateFile) {
using BlockDev = AccessHelper<TestDevice>;
using FS = FAT32::FS<BlockDev>;

55
ext/sd/tests/TestSeek.cpp Normal file
View File

@@ -0,0 +1,55 @@
#include <gtest/gtest.h>
#include "Helper.h"
#include "../AccessHelper.h"
#include "../fat32/FS.h"
TEST (TestSeek, seek1) {
using BlockDev = AccessHelper<TestDevice>;
using FS = FAT32::FS<BlockDev>;
size_t size = 32*1024*1024;
TestDevice dev(size);
BlockDev bDev(dev);
FS fs(bDev, 0);
ASSERT_FALSE(fs.isValid()); // filesystem must not be considered valid, header contains only zeros
fs.setup(size, true); // initialize the filesystem
ASSERT_TRUE(fs.isValid()); // must be considered valid now
auto testData = [] (const uint32_t pos) {
return (uint8_t) (pos * 21 + 13);
};
// create a file
FS::File f1 = fs.getOrCreateFile("test.txt");
static constexpr uint32_t testSize = 16*1024;
uint8_t d1[testSize];
for (int i = 0; i < testSize; ++i) {
d1[i] = testData(i);
}
ASSERT_EQ(testSize, f1.write(testSize, d1));
// re-open the file
FS::File f2 = fs.getOrCreateFile("test.txt");
for (int i = 0; i < 1024; ++i) {
uint8_t tmp = 0;
f2.read(1, &tmp);
ASSERT_EQ(testData(i), tmp);
}
for (int i = 0; i < 100; ++i) {
uint32_t pos = rand() % testSize;
f2.seekTo(pos);
uint8_t tmp = 0;
f2.read(1, &tmp);
uint8_t expected = testData(pos);
ASSERT_EQ(expected, tmp);
}
}