aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorNeeraj Kumar2010-06-18 08:45:57 +0000
committerNeeraj Kumar2010-06-18 08:45:57 +0000
commit7b8693757c6c7631ca4f54d10761517c2bcb1792 (patch)
treefcde450b360affcfb0fbeab7f191baab6d3a1b92 /engines
parentfb210bd45fc5f02038f3c5602d9ba602fd60b1a0 (diff)
downloadscummvm-rg350-7b8693757c6c7631ca4f54d10761517c2bcb1792.tar.gz
scummvm-rg350-7b8693757c6c7631ca4f54d10761517c2bcb1792.tar.bz2
scummvm-rg350-7b8693757c6c7631ca4f54d10761517c2bcb1792.zip
added testcase for writing files in the filesystem
svn-id: r50009
Diffstat (limited to 'engines')
-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
}