More thorough, unified tests for SDMC
This commit is contained in:
parent
b0527b4d47
commit
172e4e4c9a
102
source/test_fs.c
102
source/test_fs.c
@ -4,61 +4,67 @@
|
||||
|
||||
#include "output.h"
|
||||
|
||||
static FS_archive sdmcArchive;
|
||||
static void FS_TestSdmc()
|
||||
{
|
||||
FS_archive sdmcArchive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } };
|
||||
|
||||
// Open SDMC
|
||||
unsigned int openArchiveResult = FSUSER_OpenArchive(NULL, &sdmcArchive);
|
||||
print(GFX_TOP, "SDMC: Opening SDMC Archive - [%u]\n", openArchiveResult);
|
||||
|
||||
Handle dirHandle;
|
||||
FS_path dirPath = FS_makePath(PATH_CHAR, "/new_dir");
|
||||
|
||||
// Create Directory
|
||||
unsigned int createDirResult = FSUSER_CreateDirectory(NULL, sdmcArchive, dirPath);
|
||||
print(GFX_TOP, "SDMC: Creating Directory '%s' - [%u]\n", dirPath.data, createDirResult);
|
||||
|
||||
// Open Directory
|
||||
unsigned int openDirResult = FSUSER_OpenDirectory(NULL, &dirHandle, sdmcArchive, dirPath);
|
||||
print(GFX_TOP, "SDMC: Opening Directory '%s' - [%u]\n", dirPath.data, openDirResult);
|
||||
|
||||
Handle fileHandle;
|
||||
FS_path filePath = FS_makePath(PATH_CHAR, "/new_dir/new_file.txt");
|
||||
|
||||
// Open File
|
||||
unsigned int openFileResult = FSUSER_OpenFile(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_WRITE | FS_OPEN_CREATE, 0);
|
||||
print(GFX_TOP, "SDMC: Opening File '%s' - [%u]\n", filePath.data, openFileResult);
|
||||
|
||||
// Write File
|
||||
u32 bytesWritten;
|
||||
const char* stringWritten = "A string\n";
|
||||
unsigned int writeFileResult = FSFILE_Write(fileHandle, &bytesWritten, 0, stringWritten, strlen(stringWritten), FS_WRITE_FLUSH);
|
||||
print(GFX_TOP, "SDMC: Writing Data to File .. - [%u]\n", writeFileResult);
|
||||
|
||||
// Check File Size
|
||||
u64 fileSize;
|
||||
unsigned int getFileSizeResult = FSFILE_GetSize(fileHandle, &fileSize);
|
||||
print(GFX_TOP, "SDMC: Getting Size of File .. - [%u]\n", getFileSizeResult);
|
||||
|
||||
// Verify File Size
|
||||
print(GFX_TOP, "SDMC: Verifying Size with Written Bytes - %s\n", fileSize == bytesWritten ? "SUCCESS" : "FAILURE");
|
||||
|
||||
// Close File
|
||||
unsigned int closeFileResult = FSFILE_Close(fileHandle);
|
||||
print(GFX_TOP, "SDMC: Closing File .. - [%u]\n", closeFileResult);
|
||||
|
||||
// Close Directory
|
||||
unsigned int closeDirResult = FSDIR_Close(dirHandle);
|
||||
print(GFX_TOP, "SDMC: Closing Directory .. - [%u]\n", closeDirResult);
|
||||
|
||||
// Close SDMC
|
||||
unsigned int closeArchiveResult = FSUSER_CloseArchive(NULL, &sdmcArchive);
|
||||
print(GFX_TOP, "SDMC: Closing SDMC Archive - [%u]\n", closeArchiveResult);
|
||||
}
|
||||
|
||||
|
||||
void FS_TestAll()
|
||||
{
|
||||
FS_TestInit();
|
||||
FS_TestSdmcOpen();
|
||||
FS_TestSdmcOpenFile();
|
||||
FS_TestSdmcCreateDir();
|
||||
FS_TestSdmcClose();
|
||||
FS_TestExit();
|
||||
}
|
||||
|
||||
void FS_TestInit()
|
||||
{
|
||||
unsigned int initResult = fsInit();
|
||||
print(GFX_TOP, "fsInit - [%u]\n", initResult);
|
||||
}
|
||||
|
||||
void FS_TestSdmcOpen()
|
||||
{
|
||||
sdmcArchive = (FS_archive) { 0x00000009, { PATH_EMPTY, 1, (u8*) "" } };
|
||||
FS_TestSdmc();
|
||||
|
||||
unsigned int openResult = FSUSER_OpenArchive(NULL, &sdmcArchive);
|
||||
print(GFX_TOP, "FSUSER_OpenArchive - [%u]\n", openResult);
|
||||
}
|
||||
|
||||
void FS_TestSdmcOpenFile()
|
||||
{
|
||||
Handle fileHandleC, fileHandleW, fileHandleR;
|
||||
FS_path filePath = FS_makePath(PATH_CHAR, "/new_file.txt");
|
||||
|
||||
unsigned int openResultC = FSUSER_OpenFile(NULL, &fileHandleC, sdmcArchive, filePath, 2, 0);
|
||||
print(GFX_TOP, "FSUSER_OpenFile (create flag) - '%s' - [%u]\n", filePath.data, openResultC);
|
||||
svcCloseHandle(fileHandleC);
|
||||
|
||||
unsigned int openResultW = FSUSER_OpenFile(NULL, &fileHandleW, sdmcArchive, filePath, 1, 0);
|
||||
print(GFX_TOP, "FSUSER_OpenFile (write flag) - '%s' - [%u]\n", filePath.data, openResultW);
|
||||
svcCloseHandle(fileHandleW);
|
||||
}
|
||||
|
||||
void FS_TestSdmcCreateDir()
|
||||
{
|
||||
FS_path dirPath = FS_makePath(PATH_CHAR, "/new_dir");
|
||||
unsigned int createResult = FSUSER_CreateDirectory(NULL, sdmcArchive, dirPath);
|
||||
print(GFX_TOP, "FSUSER_CreateDirectory - '%s' - [%u]\n", dirPath.data, createResult);
|
||||
}
|
||||
|
||||
void FS_TestSdmcClose()
|
||||
{
|
||||
unsigned int closeResult = FSUSER_CloseArchive(NULL, &sdmcArchive);
|
||||
print(GFX_TOP, "FSUSER_CloseArchive - [%u]\n", closeResult);
|
||||
}
|
||||
|
||||
void FS_TestExit()
|
||||
{
|
||||
unsigned int exitResult = fsExit();
|
||||
print(GFX_TOP, "fsExit - [%u]", exitResult);
|
||||
}
|
||||
|
@ -2,20 +2,3 @@
|
||||
|
||||
void FS_TestAll();
|
||||
|
||||
|
||||
void FS_TestInit();
|
||||
|
||||
void FS_TestSdmcOpen();
|
||||
// FS_TestSdmcCreateFile();
|
||||
void FS_TestSdmcRenameFile();
|
||||
void FS_TestSdmcOpenFile();
|
||||
void FS_TestSdmcOpenFileDirectly();
|
||||
void FS_TestSdmcDeleteFile();
|
||||
void FS_TestSdmcCreateDir();
|
||||
// FS_TestSdmcRenameDir();
|
||||
void FS_TestSdmcOpenDir();
|
||||
// FS_TestSdmcDeleteDir();
|
||||
// FS_TestSdmcDeleteDirRecursively();
|
||||
void FS_TestSdmcClose();
|
||||
|
||||
void FS_TestExit();
|
||||
|
Loading…
x
Reference in New Issue
Block a user