test-type.cpp

Go to the documentation of this file.
00001 /*
00002  * test-type.cpp
00003  *
00004  * Copyright (C) 2009  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  * Simple test for the gamepad-type API.
00008  */
00009 
00010 // includes --------------------------------------------------------------------
00011 #include <iostream>
00012 
00013 #include "gamepad/gamepad-type.h"
00014 #include "perf/perf.h"
00015 
00016 
00017 
00018 ////////////////////////////////////////////////////////////////////////////////
00019 //
00020 //      static helper methods
00021 //
00022 ////////////////////////////////////////////////////////////////////////////////
00023 
00024 static void
00025 doTest
00026 (
00027 IN const char * path
00028 )
00029 {
00030         ASSERT(path, "null");
00031 
00032         // open a named stream folder for this path
00033         smart_ptr<nstream::Manager> mgr = nstream::getFilesystemManager(path);
00034         ASSERT(mgr, "null");
00035 
00036         smart_ptr<nstream::Folder> folder = mgr->getRoot();
00037         ASSERT(folder, "null");
00038 
00039         // load files!
00040         gamepad::gamepad_type_map_t map;
00041         gamepad::addGamepadTypesInFolderToMap(folder, map);
00042 
00043         // iterate
00044         for (gamepad::gamepad_type_map_t::iterator i = map.begin();
00045              i != map.end(); ++i) {
00046                 gamepad::Type * gt = i->second;
00047                 ASSERT(gt, "null gamepad type object in map?");
00048                 gt->dump();
00049         }
00050 }
00051 
00052 
00053 
00054 ////////////////////////////////////////////////////////////////////////////////
00055 //
00056 //      entry point
00057 //
00058 ////////////////////////////////////////////////////////////////////////////////
00059 
00060 int
00061 main
00062 (
00063 IN int argc,
00064 IN const char * argv[]
00065 )
00066 {
00067         int retval = 0;
00068         ASSERT(2 == argc,
00069             "Usage: gamepad-type-test <gamepad-files-directory>");
00070         const char * path = argv[1];
00071 
00072         try {
00073                 perf::Timer timer("overall timer");
00074 
00075                 doTest(path);
00076 
00077         } catch (std::exception& e) {
00078                 DPRINTF("EXCEPTION: %s", e.what());
00079                 retval = 1;
00080         }
00081 
00082         perf::dumpTimingSummary(std::cerr);
00083 
00084         return retval;
00085 }
00086 
00087