huge work on FAT32, initial support for writing
This commit is contained in:
50
ext/sd/tests/TestCreate.cpp
Normal file
50
ext/sd/tests/TestCreate.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "Helper.h"
|
||||
|
||||
#include "../AccessHelper.h"
|
||||
#include "../fat32/FS.h"
|
||||
|
||||
// dd if=/dev/zero of=/tmp/ram/orig.fat32 bs=8192 count=4096
|
||||
// mkfs.vfat -F 32 -R 32 -s 8 orig.fat32
|
||||
// hexdump -v -C -n 512 orig.fat32
|
||||
|
||||
|
||||
|
||||
TEST(TestCreate, structure) {
|
||||
|
||||
FAT32::FSHeader header;
|
||||
|
||||
ASSERT_EQ(0x0B, (uint8_t*)&header.bytesPerSector - (uint8_t*)&header);
|
||||
ASSERT_EQ(0x0D, (uint8_t*)&header.sectorsPerCluster - (uint8_t*)&header);
|
||||
ASSERT_EQ(0x0E, (uint8_t*)&header.numReservedSectors - (uint8_t*)&header);
|
||||
ASSERT_EQ(0x10, (uint8_t*)&header.numberOfFATs - (uint8_t*)&header);
|
||||
ASSERT_EQ(0x15, (uint8_t*)&header.mediaDescriptor - (uint8_t*)&header);
|
||||
ASSERT_EQ(0x20, (uint8_t*)&header.sectorsInPartition - (uint8_t*)&header);
|
||||
ASSERT_EQ(0x24, (uint8_t*)&header.sectorsPerFAT - (uint8_t*)&header);
|
||||
ASSERT_EQ(0x2C, (uint8_t*)&header.rootDirFirstCluster - (uint8_t*)&header);
|
||||
|
||||
}
|
||||
|
||||
TEST (TestCreate, write) {
|
||||
|
||||
using BlockDev = AccessHelper<TestDevice>;
|
||||
|
||||
size_t size = 32*1024*1024;
|
||||
TestDevice dev(size);
|
||||
BlockDev bDev(dev);
|
||||
FAT32::FS<BlockDev> fs(bDev, 0);
|
||||
fs.setup(size);
|
||||
|
||||
const char* test = "This is a test";
|
||||
FAT32::FS<BlockDev>::File2 f1 = fs.create2("test1.txt");
|
||||
f1.write(strlen(test), (const uint8_t*)test, [](int percent) {});
|
||||
|
||||
FAT32::FS<BlockDev>::File2 f2 = fs.create2("test2.txt");
|
||||
f2.write(strlen(test), (const uint8_t*)test, [](int percent) {});
|
||||
|
||||
dev.toFile("/tmp/ram/1.fat32");
|
||||
|
||||
// mount -t vfat 1.fat32 /mnt/fat/ && ls -l /mnt/fat/ && cat /mnt/fat/test1.txt && umount /mnt/fat
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user