2010-06-26 13:07:13 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
2010-06-17 20:24:01 +00:00
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/stream.h"
|
2010-06-22 20:49:38 +00:00
|
|
|
#include "common/util.h"
|
2010-06-17 20:24:01 +00:00
|
|
|
|
2010-06-17 11:23:51 +00:00
|
|
|
#include "testbed/fs.h"
|
|
|
|
|
|
|
|
namespace Testbed {
|
2010-07-14 19:44:51 +00:00
|
|
|
|
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 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-25 20:26:54 +00:00
|
|
|
bool FStests::readDataFromFile(Common::FSDirectory *directory, const char *file) {
|
2010-07-14 14:12:42 +00:00
|
|
|
|
2010-06-25 20:26:54 +00:00
|
|
|
Common::SeekableReadStream *readStream = directory->createReadStreamForMember(file);
|
2010-06-17 20:24:01 +00:00
|
|
|
|
|
|
|
if (!readStream) {
|
2010-06-29 22:46:56 +00:00
|
|
|
Testsuite::logDetailedPrintf("Can't open game file for reading\n");
|
2010-06-17 20:24:01 +00:00
|
|
|
return false;
|
2010-07-14 14:12:42 +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
|
|
|
|
2010-07-14 19:44:51 +00:00
|
|
|
Testsuite::logDetailedPrintf("Message Extracted from %s/%s : %s\n", directory->getFSNode().getName().c_str(), file, msg.c_str());
|
2010-06-17 20:24:01 +00:00
|
|
|
|
|
|
|
Common::String expectedMsg = "It works!";
|
|
|
|
|
|
|
|
if (!msg.equals(expectedMsg)) {
|
2010-06-29 22:46:56 +00:00
|
|
|
Testsuite::logDetailedPrintf("Can't read Correct data from file\n");
|
2010-06-17 20:24:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-22 14:39:51 +00:00
|
|
|
bool FStests::testReadFile() {
|
|
|
|
const Common::String &path = ConfMan.get("path");
|
2010-06-25 20:26:54 +00:00
|
|
|
Common::FSDirectory gameRoot(path);
|
2010-06-22 20:49:38 +00:00
|
|
|
int numFailed = 0;
|
2010-07-14 14:12:42 +00:00
|
|
|
|
2010-06-25 20:26:54 +00:00
|
|
|
if (!gameRoot.getFSNode().isDirectory()) {
|
2010-06-29 22:46:56 +00:00
|
|
|
Testsuite::logDetailedPrintf("game Path should be a directory");
|
2010-06-22 14:39:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-07-14 14:12:42 +00:00
|
|
|
|
2010-06-22 20:49:38 +00:00
|
|
|
const char *dirList[] = {"test1" ,"Test2", "TEST3" , "tEST4", "test5"};
|
|
|
|
const char *file[] = {"file.txt", "File.txt", "FILE.txt", "fILe.txt", "file"};
|
2010-06-22 14:39:51 +00:00
|
|
|
|
2010-06-22 20:49:38 +00:00
|
|
|
for (unsigned int i = 0; i < ARRAYSIZE(dirList); i++) {
|
|
|
|
Common::String dirName = dirList[i];
|
2010-06-22 14:39:51 +00:00
|
|
|
Common::String fileName = file[i];
|
2010-07-14 14:12:42 +00:00
|
|
|
Common::FSDirectory *directory = gameRoot.getSubDirectory(dirName);
|
2010-06-22 20:49:38 +00:00
|
|
|
|
|
|
|
if (!readDataFromFile(directory, fileName.c_str())) {
|
2010-06-29 22:46:56 +00:00
|
|
|
Testsuite::logDetailedPrintf("Reading from %s/%s failed\n", dirName.c_str(), fileName.c_str());
|
2010-06-22 20:49:38 +00:00
|
|
|
numFailed++;
|
2010-06-22 14:39:51 +00:00
|
|
|
}
|
2010-07-14 14:12:42 +00:00
|
|
|
|
2010-06-22 20:49:38 +00:00
|
|
|
dirName.toLowercase();
|
2010-06-22 14:39:51 +00:00
|
|
|
fileName.toLowercase();
|
2010-07-30 20:10:30 +00:00
|
|
|
delete directory;
|
2010-07-14 14:12:42 +00:00
|
|
|
directory = gameRoot.getSubDirectory(dirName);
|
|
|
|
|
2010-06-22 20:49:38 +00:00
|
|
|
if (!readDataFromFile(directory, fileName.c_str())) {
|
2010-06-29 22:46:56 +00:00
|
|
|
Testsuite::logDetailedPrintf("Reading from %s/%s failed\n", dirName.c_str(), fileName.c_str());
|
2010-06-22 20:49:38 +00:00
|
|
|
numFailed++;
|
2010-06-22 14:39:51 +00:00
|
|
|
}
|
2010-07-14 14:12:42 +00:00
|
|
|
|
2010-06-22 20:49:38 +00:00
|
|
|
dirName.toUppercase();
|
2010-06-22 14:39:51 +00:00
|
|
|
fileName.toUppercase();
|
2010-07-30 20:10:30 +00:00
|
|
|
delete directory;
|
2010-07-14 14:12:42 +00:00
|
|
|
directory = gameRoot.getSubDirectory(dirName);
|
|
|
|
|
2010-06-22 20:49:38 +00:00
|
|
|
if (!readDataFromFile(directory, fileName.c_str())) {
|
2010-06-29 22:46:56 +00:00
|
|
|
Testsuite::logDetailedPrintf("Reading from %s/%s failed\n", dirName.c_str(), fileName.c_str());
|
2010-06-22 20:49:38 +00:00
|
|
|
numFailed++;
|
2010-06-22 14:39:51 +00:00
|
|
|
}
|
2010-07-30 20:10:30 +00:00
|
|
|
delete directory;
|
2010-06-22 14:39:51 +00:00
|
|
|
}
|
2010-07-14 14:12:42 +00:00
|
|
|
|
2010-06-29 22:46:56 +00:00
|
|
|
Testsuite::logDetailedPrintf("Failed %d out of 15\n", numFailed);
|
2010-06-22 20:49:38 +00:00
|
|
|
return false;
|
2010-06-22 14:39:51 +00:00
|
|
|
}
|
|
|
|
|
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-07-14 14:12:42 +00:00
|
|
|
|
2010-06-19 20:50:10 +00:00
|
|
|
Common::WriteStream *ws = fileToWrite.createWriteStream();
|
2010-07-14 14:12:42 +00:00
|
|
|
|
2010-06-21 19:09:19 +00:00
|
|
|
if (!ws) {
|
2010-06-29 22:46:56 +00:00
|
|
|
Testsuite::logDetailedPrintf("Can't open writable file in game data dir\n");
|
2010-06-18 08:45:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
2010-07-14 14:12:42 +00:00
|
|
|
|
2010-06-18 08:45:57 +00:00
|
|
|
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
|
2010-06-29 22:46:56 +00:00
|
|
|
Testsuite::logDetailedPrintf("Data written and read correctly\n");
|
2010-06-18 08:45:57 +00:00
|
|
|
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-22 20:49:38 +00:00
|
|
|
|
2010-06-19 20:50:10 +00:00
|
|
|
|
2010-06-17 20:24:01 +00:00
|
|
|
FSTestSuite::FSTestSuite() {
|
2010-08-07 20:35:50 +00:00
|
|
|
// FS tests depend on Game Data files.
|
|
|
|
// If those are not found. Disable this testsuite.
|
2010-07-10 19:24:12 +00:00
|
|
|
const Common::String &path = ConfMan.get("path");
|
|
|
|
Common::FSNode gameRoot(path);
|
|
|
|
|
|
|
|
Common::FSNode gameIdentificationFile = gameRoot.getChild("TESTBED");
|
|
|
|
if (!gameIdentificationFile.exists()) {
|
|
|
|
logPrintf("WARNING! : Game Data not found. Skipping FS tests\n");
|
2010-08-07 20:35:50 +00:00
|
|
|
_isGameDataFound = false;
|
2010-08-07 16:17:12 +00:00
|
|
|
Testsuite::enable(false);
|
2010-07-10 19:24:12 +00:00
|
|
|
}
|
2010-08-07 20:35:50 +00:00
|
|
|
addTest("ReadingFile", &FStests::testReadFile, false);
|
|
|
|
addTest("WritingFile", &FStests::testWriteFile, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FSTestSuite::enable(bool flag) {
|
|
|
|
Testsuite::enable(_isGameDataFound & flag);
|
2010-07-10 19:24:12 +00:00
|
|
|
}
|
|
|
|
|
2010-06-17 11:23:51 +00:00
|
|
|
} // End of namespace Testbed
|