00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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