2010-06-17 20:24:01 +00:00
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/stream.h"
|
|
|
|
|
2010-06-17 11:23:51 +00:00
|
|
|
#include "testbed/fs.h"
|
|
|
|
|
|
|
|
namespace Testbed {
|
2010-06-17 20:24:01 +00:00
|
|
|
/**
|
|
|
|
* This test does the following:
|
|
|
|
* 1) acquires the game-data path
|
2010-06-22 14:39:51 +00:00
|
|
|
* 2) In the game-root it navigates to "directory" and opens the file "file"
|
2010-06-17 20:24:01 +00:00
|
|
|
* The former two are directories while the latter is a text file used for game engine detection
|
|
|
|
*
|
|
|
|
* Both the directories contain the file testbed.conf each which has a message written in it.
|
|
|
|
* The code accesses the appropriate file using the fileSystem API, creates a read stream of it and
|
|
|
|
* compares the message contained in it, with what it expects.
|
|
|
|
*
|
|
|
|
*/
|
2010-06-22 14:39:51 +00:00
|
|
|
bool FStests::readDataFromFile(Common::FSNode &directory, const char *file) {
|
2010-06-17 20:24:01 +00:00
|
|
|
|
|
|
|
|
2010-06-22 14:39:51 +00:00
|
|
|
Common::FSDirectory nestedDir(directory);
|
2010-06-17 11:23:51 +00:00
|
|
|
|
2010-06-22 14:39:51 +00:00
|
|
|
Common::SeekableReadStream *readStream = nestedDir.createReadStreamForMember(file);
|
2010-06-17 20:24:01 +00:00
|
|
|
|
|
|
|
if (!readStream) {
|
|
|
|
printf("LOG:Can't open game file for reading\n");
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-17 11:23:51 +00:00
|
|
|
|
2010-06-17 20:24:01 +00:00
|
|
|
Common::String msg = readStream->readLine();
|
2010-06-21 19:09:19 +00:00
|
|
|
delete readStream;
|
2010-06-22 14:39:51 +00:00
|
|
|
printf("LOG: Message Extracted from %s : %s\n", file, msg.c_str());
|
|
|
|
|
2010-06-17 20:24:01 +00:00
|
|
|
|
|
|
|
Common::String expectedMsg = "It works!";
|
|
|
|
|
|
|
|
if (!msg.equals(expectedMsg)) {
|
|
|
|
printf("LOG: Can't read Correct data from file\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-22 14:39:51 +00:00
|
|
|
|
|
|
|
bool FStests::testReadFile() {
|
|
|
|
const Common::String &path = ConfMan.get("path");
|
|
|
|
Common::FSNode gameRoot(path);
|
|
|
|
|
|
|
|
if (!gameRoot.isDirectory()) {
|
|
|
|
printf("LOG:game Path should be a directory");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::FSList dirList;
|
|
|
|
gameRoot.getChildren(dirList);
|
|
|
|
|
|
|
|
const char *file[] = {"file.txt", "File.txt", "FILE.txt", "fILe.txt", "file."};
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < dirList.size(); i++) {
|
|
|
|
Common::String fileName = file[i];
|
|
|
|
if (!readDataFromFile(dirList[i], fileName.c_str())) {
|
|
|
|
printf("LOG : reading from %s failed", fileName.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileName.toLowercase();
|
|
|
|
|
|
|
|
if (!readDataFromFile(dirList[i], fileName.c_str())) {
|
|
|
|
printf("LOG : reading from %s failed", fileName.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileName.toUppercase();
|
|
|
|
|
|
|
|
if (!readDataFromFile(dirList[i], fileName.c_str())) {
|
|
|
|
printf("LOG : reading from %s failed", fileName.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-18 08:45:57 +00:00
|
|
|
/**
|
|
|
|
* 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");
|
2010-06-19 20:50:10 +00:00
|
|
|
|
|
|
|
Common::WriteStream *ws = fileToWrite.createWriteStream();
|
|
|
|
|
2010-06-21 19:09:19 +00:00
|
|
|
if (!ws) {
|
2010-06-18 08:45:57 +00:00
|
|
|
printf("LOG: Can't open writable file in game data dir\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ws->writeString("ScummVM Rocks!");
|
|
|
|
ws->flush();
|
2010-06-21 19:09:19 +00:00
|
|
|
delete ws;
|
2010-06-18 08:45:57 +00:00
|
|
|
|
|
|
|
Common::SeekableReadStream *rs = fileToWrite.createReadStream();
|
|
|
|
Common::String readFromFile = rs->readLine();
|
2010-06-21 19:09:19 +00:00
|
|
|
delete rs;
|
2010-06-18 08:45:57 +00:00
|
|
|
|
|
|
|
if (readFromFile.equals("ScummVM Rocks!")) {
|
|
|
|
// All good
|
|
|
|
printf("LOG: Data written and read correctly\n");
|
|
|
|
return true;
|
|
|
|
}
|
2010-06-21 19:09:19 +00:00
|
|
|
|
2010-06-18 08:45:57 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-17 20:24:01 +00:00
|
|
|
|
2010-06-19 20:50:10 +00:00
|
|
|
/**
|
|
|
|
* This test creates a savefile for the given testbed-state and could be reloaded using the saveFile API.
|
|
|
|
* It is intended to test saving and loading from savefiles.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
GFXtests::testSavingGame() {
|
|
|
|
Common::SaveFileManager saveFileMan = g_system->getSavefileManager();
|
|
|
|
}*/
|
|
|
|
|
2010-06-17 20:24:01 +00:00
|
|
|
FSTestSuite::FSTestSuite() {
|
2010-06-18 08:45:57 +00:00
|
|
|
addTest("openingFile", &FStests::testReadFile);
|
|
|
|
addTest("WritingFile", &FStests::testWriteFile);
|
2010-06-17 11:23:51 +00:00
|
|
|
}
|
|
|
|
const char *FSTestSuite::getName() const {
|
|
|
|
return "File System";
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Testbed
|