Skip to content

Instantly share code, notes, and snippets.

@Subv
Last active August 29, 2015 14:11
Show Gist options
  • Save Subv/e98f5e2947fd25f86329 to your computer and use it in GitHub Desktop.
Save Subv/e98f5e2947fd25f86329 to your computer and use it in GitHub Desktop.
HWTests patch
diff --git a/source/tests/fs/fs_sdmc.cpp b/source/tests/fs/fs_sdmc.cpp
index 6ecb27a..26326b5 100644
--- a/source/tests/fs/fs_sdmc.cpp
+++ b/source/tests/fs/fs_sdmc.cpp
@@ -1,5 +1,7 @@
#include <memory>
+#include <string.h>
#include <3ds.h>
+#include "output.h"
#include "tests/test.h"
#include "tests/fs/fs_sdmc.h"
@@ -60,16 +62,26 @@ static bool TestFileRename(FS_archive sdmcArchive)
static bool TestFileWriteRead(FS_archive sdmcArchive)
{
Handle fileHandle;
+ Handle fileHandle2;
u32 bytesWritten;
u32 bytesRead;
u64 fileSize;
+ u32 bytesRead2;
+
const static FS_path filePath = FS_makePath(PATH_CHAR, "/test_file_write_read.txt");
+ const static FS_path filePath2 = FS_makePath(PATH_CHAR, "/test_file_write_read_2.txt");
const static char* stringWritten = "A string\n";
// Create file
FSUSER_OpenFile(NULL, &fileHandle, sdmcArchive, filePath, FS_OPEN_CREATE | FS_OPEN_WRITE, 0);
+ SoftAssert(FSUSER_OpenFile(NULL, &fileHandle2, sdmcArchive, filePath2, FS_OPEN_WRITE, 0) == 0);
+
+ std::unique_ptr<char> stringRead2(new char[10]);
+ SoftAssert(FSFILE_Read(fileHandle2, &bytesRead2, 0, stringRead2.get(), 10) == 0);
+ print(GFX_TOP, "Read %s from a write-only file", stringRead2.get());
+
// Write to file
SoftAssert(FSFILE_Write(fileHandle, &bytesWritten, 0, stringWritten, strlen(stringWritten)+1, FS_WRITE_FLUSH) == 0);
// Verify string size
@@ -77,12 +89,18 @@ static bool TestFileWriteRead(FS_archive sdmcArchive)
// Check file size
SoftAssert(FSFILE_GetSize(fileHandle, &fileSize) == 0);
+
+ print(GFX_TOP, "FileSize: %u, bytes written %u\n", u32(fileSize & 0xFFFFFFFF), bytesWritten);
+
// Verify file size
SoftAssert(fileSize == bytesWritten);
std::unique_ptr<char> stringRead(new char[fileSize]);
// Read from file
SoftAssert(FSFILE_Read(fileHandle, &bytesRead, 0, stringRead.get(), fileSize) == 0);
+
+ print(GFX_TOP, "Read %s from file, expected %s", stringRead.get(), stringWritten);
+
// Verify string contents
SoftAssert(strcmp(stringRead.get(), stringWritten) == 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment