/usr/src/rpm/BUILD/libirobot-create-0.1/tests/common.hh

Go to the documentation of this file.
00001 // Copyright (C) 2008 by Thomas Moulard, the University of Southern California
00002 // (USC), and iLab at USC.
00003 //
00004 // This file is part of the iRobot Create library.
00005 //
00006 // libirobot-create is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // libirobot-create is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with libirobot-create.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 #ifndef IROBOT_CREATE_TESTS_COMMON_HH
00020 # define IROBOT_CREATE_TESTS_COMMON_HH
00021 # include "irobot-create.hh"
00022 # include <sstream>
00023 
00024 # include "config.h"
00025 
00026 static const int TEST_FAILED = 10;
00027 static const int TEST_SUCCEED = 0;
00028 
00029 # define GENERATE_TEST()                                \
00030   int                                                   \
00031   main (int argc, char** argv)                          \
00032   {                                                     \
00033     if (argc == 2                                       \
00034         && std::string (argv[1]) == "--version")        \
00035       {                                                 \
00036         std::cout << PACKAGE_STRING << std::endl;       \
00037         return 0;                                       \
00038       }                                                 \
00039                                                         \
00040     std::stringstream stream;                           \
00041     int status = 0;                                     \
00042     try                                                 \
00043       {                                                 \
00044         iRobot::Create robot (stream);                  \
00045         status = run_test (robot, stream);              \
00046       }                                                 \
00047     catch (std::runtime_error& e)                       \
00048       {                                                 \
00049         std::cerr << e.what () << std::endl;            \
00050         return 1;                                       \
00051       }                                                 \
00052     catch (...)                                         \
00053       {                                                 \
00054         std::cerr << "Unexpected error" << std::endl;   \
00055         return 2;                                       \
00056       }                                                 \
00057     std::cout << stream.str ();                         \
00058     return status;                                      \
00059   }
00060 
00061 #define CHECK_FAILURE(EXCEPTION, CMD)           \
00062   {                                             \
00063     bool failed = true;                         \
00064     try                                         \
00065       {                                         \
00066         CMD;                                    \
00067       }                                         \
00068     catch (EXCEPTION&)                          \
00069       {                                         \
00070         failed = false;                         \
00071       }                                         \
00072     catch (...)                                 \
00073       {}                                        \
00074     if (failed)                                 \
00075       return TEST_FAILED;                       \
00076   }
00077 
00078 #define CHECK_SENSOR_CHAR(PACKET, DATA, CONDITION)      \
00079   robot.sendSensorsCommand (PACKET);                    \
00080   stream.seekg (stream.tellp ());                       \
00081   stream.put (DATA);                                    \
00082   if (CONDITION)                                        \
00083     return TEST_FAILED
00084 
00085 #define CHECK_SENSOR_UCHAR(PACKET, DATA, CONDITION)      \
00086   CHECK_SENSOR_CHAR (PACKET, DATA, CONDITION)
00087 
00088 #endif 

Generated on Thu Aug 28 14:38:01 2008 for iRobot Create library by  doxygen 1.5.4