From e9332e41d6508bd143df2e1e2fa31e8434011552 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 25 Apr 2006 21:31:55 +0000 Subject: Added hidden --test-detector command line option to make it easy to test the detector on your config file (to be removed before the next release) svn-id: r22158 --- base/gameDetector.cpp | 5 ++ base/main.cpp | 127 +++++++++++++++++++++++++++++--------------------- 2 files changed, 80 insertions(+), 52 deletions(-) (limited to 'base') diff --git a/base/gameDetector.cpp b/base/gameDetector.cpp index dbe9e7fb16..4c7efa90bd 100644 --- a/base/gameDetector.cpp +++ b/base/gameDetector.cpp @@ -382,6 +382,11 @@ Common::String GameDetector::parseCommandLine(Common::StringMap &settings, int a END_OPTION + // HACK FIXME TODO: This switch is intentionally *not* documented! + DO_LONG_OPTION_CMD("test-detector") + return "test-detector"; + END_OPTION + DO_OPTION('c', "config") END_OPTION diff --git a/base/main.cpp b/base/main.cpp index 48b00a0aef..00e5b8b49f 100644 --- a/base/main.cpp +++ b/base/main.cpp @@ -51,7 +51,7 @@ #endif -//#define DETECTOR_TESTING_HACK +#define DETECTOR_TESTING_HACK #ifdef DETECTOR_TESTING_HACK #include "backends/fs/fs.h" @@ -237,6 +237,77 @@ static int runGame(const Plugin *plugin, OSystem &system, const Common::String & return result; } +#ifdef DETECTOR_TESTING_HACK +static void runDetectorTest() { + // HACK: The following code can be used to test the detection code of our + // engines. Basically, it loops over all targets, and calls the detector + // for the given path. It then prints out the result and also checks + // whether the result agrees with the settings of the target. + + const Common::ConfigManager::DomainMap &domains = ConfMan.getGameDomains(); + Common::ConfigManager::DomainMap::const_iterator iter = domains.begin(); + int success = 0, failure = 0; + for (iter = domains.begin(); iter != domains.end(); ++iter) { + Common::String name(iter->_key); + Common::String gameid(iter->_value.get("gameid")); + Common::String path(iter->_value.get("path")); + printf("Looking at target '%s', gameid '%s', path '%s' ...\n", + name.c_str(), gameid.c_str(), path.c_str()); + if (path.empty()) { + printf(" ... no path specified, skipping\n"); + continue; + } + if (gameid.empty()) { + gameid = name; + } + + FilesystemNode dir(path); + + if (!dir.isValid() || !dir.isDirectory()) { + printf(" ... invalid path, skipping\n"); + continue; + } + + FSList files = dir.listDir(FilesystemNode::kListAll); + DetectedGameList candidates(PluginManager::instance().detectGames(files)); + + bool gameidDiffers = false; + for (DetectedGameList::iterator x = candidates.begin(); x != candidates.end(); ++x) { + gameidDiffers |= scumm_stricmp(gameid.c_str(), x->gameid.c_str()); + } + + if (candidates.empty()) { + printf(" FAILURE: No games detected\n"); + failure++; + } else if (candidates.size() > 1) { + if (gameidDiffers) { + printf(" FAILURE: Multiple games detected, some/all with wrong gameid\n"); + } else { + printf(" FAILURE: Multiple games detected, but all have the same gameid\n"); + } + failure++; + } else if (gameidDiffers) { + printf(" FAILURE: Wrong gameid detected\n"); + failure++; + } else { + printf(" SUCCESS: Game was detected correctly\n"); + success++; + } + + for (DetectedGameList::iterator x = candidates.begin(); x != candidates.end(); ++x) { + printf(" gameid '%s', desc '%s', language '%s', platform '%s'\n", + x->gameid.c_str(), + x->description.c_str(), + Common::getLanguageCode(x->language), + Common::getPlatformCode(x->platform)); + } + } + int total = domains.size(); + printf("Detector test run: %d fail, %d success, %d skipped, out of %d\n", + failure, success, total - failure - success, total); +} +#endif + extern "C" int scummvm_main(int argc, char *argv[]) { Common::String specialDebug; Common::String command; @@ -294,58 +365,10 @@ extern "C" int scummvm_main(int argc, char *argv[]) { #ifdef DETECTOR_TESTING_HACK - // HACK: The following code can be used to test the detection code of our - // engines. Basically, it loops over all targets, and calls the detector - // for the given path. It then prints out the result and also checks - // whether the result agrees with the settings of the target. - - const Common::ConfigManager::DomainMap &domains = ConfMan.getGameDomains(); - Common::ConfigManager::DomainMap::const_iterator iter = domains.begin(); - for (iter = domains.begin(); iter != domains.end(); ++iter) { - Common::String name(iter->_key); - Common::String gameid(iter->_value.get("gameid")); - Common::String path(iter->_value.get("path")); - printf("Looking at target '%s', gameid '%s', path '%s' ...\n", - name.c_str(), gameid.c_str(), path.c_str()); - if (path.empty()) { - printf(" ... no path specified, skipping\n"); - continue; - } - if (gameid.empty()) { - gameid = name; - } - - FilesystemNode dir(path); - - if (!dir.isValid() || !dir.isDirectory()) { - printf(" ... invalid path, skipping\n"); - continue; - } - - FSList files = dir.listDir(FilesystemNode::kListAll); - DetectedGameList candidates(PluginManager::instance().detectGames(files)); - - if (candidates.empty()) { - printf(" FAILURE: No games detected\n"); - } else if (candidates.size() > 1) { - printf(" FAILURE: Multiple games detected\n"); - } else if (scumm_stricmp(gameid.c_str(), candidates.begin()->gameid.c_str())) { - printf(" FAILURE: Wrong gameid detected\n"); - } else { - printf(" SUCCESS: Game was detected correctly\n"); - } - - for (DetectedGameList::iterator x = candidates.begin(); x != candidates.end(); ++x) { - printf(" gameid '%s', desc '%s', language '%s', platform '%s'\n", - x->gameid.c_str(), - x->description.c_str(), - Common::getLanguageCode(x->language), - Common::getPlatformCode(x->platform)); - } + else if (command == "test-detector") { + runDetectorTest(); + return 0; } - - return 0; - #endif -- cgit v1.2.3