aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/testbed/fs.cpp40
-rw-r--r--engines/testbed/fs.h7
2 files changed, 44 insertions, 3 deletions
diff --git a/engines/testbed/fs.cpp b/engines/testbed/fs.cpp
index 8720494008..aa1022ff70 100644
--- a/engines/testbed/fs.cpp
+++ b/engines/testbed/fs.cpp
@@ -15,7 +15,7 @@ namespace Testbed {
* compares the message contained in it, with what it expects.
*
*/
-bool FStests::testOpenFile() {
+bool FStests::testReadFile() {
const Common::String &path = ConfMan.get("path");
Common::FSNode gameRoot(path);
@@ -53,9 +53,45 @@ bool FStests::testOpenFile() {
return true;
}
+/**
+ * This test creates a file testbed.out, writes a sample data and confirms if
+ * it is same by reading the file again.
+ */
+
+bool FStests::testWriteFile() {
+ const Common::String &path = ConfMan.get("path");
+ Common::FSNode gameRoot(path);
+
+ Common::FSNode fileToWrite = gameRoot.getChild("testbed.out");
+ if (!fileToWrite.isWritable()) {
+ printf("LOG: Can't open writable file in game data dir\n");
+ return false;
+ }
+
+ Common::WriteStream *ws = fileToWrite.createWriteStream();
+ if (!ws) {
+ printf("LOG: Can't create a write stream");
+ return false;
+ }
+
+ ws->writeString("ScummVM Rocks!");
+ ws->flush();
+
+ Common::SeekableReadStream *rs = fileToWrite.createReadStream();
+ Common::String readFromFile = rs->readLine();
+
+ if (readFromFile.equals("ScummVM Rocks!")) {
+ // All good
+ printf("LOG: Data written and read correctly\n");
+ return true;
+ }
+
+ return false;
+}
FSTestSuite::FSTestSuite() {
- addTest("openingFile", &FStests::testOpenFile);
+ addTest("openingFile", &FStests::testReadFile);
+ addTest("WritingFile", &FStests::testWriteFile);
}
const char *FSTestSuite::getName() const {
return "File System";
diff --git a/engines/testbed/fs.h b/engines/testbed/fs.h
index f1a3e8a37d..c421725407 100644
--- a/engines/testbed/fs.h
+++ b/engines/testbed/fs.h
@@ -7,10 +7,15 @@ namespace Testbed {
namespace FStests {
+// Note: These tests require a game-data directory
+// So would work if game-path is set in the launcher or invoked as ./scummvm --path="path-to-testbed-data" testbed
+// from commandline
+
// Helper functions for FS tests
// will contain function declarations for FS tests
-bool testOpenFile();
+bool testReadFile();
+bool testWriteFile();
// add more here
}