Go to the documentation of this file.00001
00029 #include <ros/ros.h>
00030
00031 #include <math.h>
00032 #include <cyberglove/xml_calibration_parser.h>
00033 #include <gtest/gtest.h>
00034
00035 #define TEST_EXPRESSION(a) EXPECT_EQ((a), meval::EvaluateMathExpression(#a))
00036
00037 using namespace ros;
00038 using namespace xml_calibration_parser;
00039
00040 std::string path_to_calibration = "test/cyberglove_test.cal";
00041
00042 float epsilon = 0.01f;
00043
00044 XmlCalibrationParser calib_parser;
00045
00046 TEST(LookupTable, testSimple)
00047 {
00048 float valtmp;
00049 valtmp = calib_parser.get_calibration_value(0.05f,"test1" );
00050 EXPECT_TRUE(fabs( valtmp - 50.0f ) < epsilon)
00051 << "Expected value : 50 "
00052 << "Received value : "<< valtmp;
00053
00054 valtmp = calib_parser.get_calibration_value(0.1f,"test1" );
00055 EXPECT_TRUE(fabs( valtmp - 100.0f ) < epsilon)
00056 << "Expected value : 100 "
00057 << "Received value : "<< valtmp;
00058
00059 valtmp = calib_parser.get_calibration_value(0.0f,"test1" );
00060 EXPECT_TRUE(fabs( valtmp - 0.0f ) < epsilon)
00061 << "Expected value : 0 "
00062 << "Received value : "<< valtmp;
00063
00064 valtmp = calib_parser.get_calibration_value(0.2f,"test1" );
00065 EXPECT_TRUE(fabs( valtmp - 200.0f ) < epsilon)
00066 << "Expected value : 200 "
00067 << "Received value : "<< valtmp;
00068 }
00069
00070 TEST(LookupTable, integrity)
00071 {
00072 std::vector<XmlCalibrationParser::JointCalibration> myCalib = calib_parser.getJointsCalibrations();
00073
00074 EXPECT_EQ(4, myCalib.size());
00075 for(unsigned int i = 0; i<myCalib.size() ; ++i)
00076 {
00077 EXPECT_EQ(2, myCalib[i].calibrations.size());
00078 }
00079 }
00080
00081 TEST(LookupTable, testCalibNotStartingAtZero)
00082 {
00083 float valtmp;
00084 valtmp = calib_parser.get_calibration_value(0.05f,"test2" );
00085 EXPECT_TRUE(fabs( valtmp - 35.0f ) < epsilon)
00086 << "Expected value : 35 "
00087 << "Received value : "<< valtmp;
00088
00089 valtmp = calib_parser.get_calibration_value(0.1f,"test2" );
00090 EXPECT_TRUE(fabs( valtmp - 60.0f ) < epsilon)
00091 << "Expected value : 60 "
00092 << "Received value : "<< valtmp;
00093
00094 valtmp = calib_parser.get_calibration_value(0.0f,"test2" );
00095 EXPECT_TRUE(fabs( valtmp - 10.0f ) < epsilon)
00096 << "Expected value : 10 "
00097 << "Received value : "<< valtmp;
00098
00099 valtmp = calib_parser.get_calibration_value(0.2f,"test2" );
00100 EXPECT_TRUE(fabs(valtmp - 110.0f ) < epsilon)
00101 << "Expected value : 110 "
00102 << "Received value : "<< valtmp;
00103 }
00104
00105 TEST(LookupTable, testRawNotStartingAtZero)
00106 {
00107 float valtmp;
00108 valtmp = calib_parser.get_calibration_value(0.15f,"test3" );
00109 EXPECT_TRUE(fabs( valtmp - 35.0f ) < epsilon)
00110 << "Expected value : 35 "
00111 << "Received value : "<< valtmp;
00112
00113 valtmp = calib_parser.get_calibration_value(0.2f,"test3" );
00114 EXPECT_TRUE(fabs( valtmp - 60.0f ) < epsilon)
00115 << "Expected value : 60 "
00116 << "Received value : "<< valtmp;
00117
00118 valtmp = calib_parser.get_calibration_value(0.1f,"test3" );
00119 EXPECT_TRUE(fabs( valtmp - 10.0f ) < epsilon)
00120 << "Expected value : 10 "
00121 << "Received value : "<< valtmp;
00122
00123 valtmp = calib_parser.get_calibration_value(0.3f,"test3" );
00124 EXPECT_TRUE(fabs(valtmp - 110.0f ) < epsilon)
00125 << "Expected value : 110 "
00126 << "Received value : "<< valtmp;
00127 }
00128
00129 TEST(LookupTable, tableNotOrdered)
00130 {
00131 float valtmp;
00132 valtmp = calib_parser.get_calibration_value(0.05f,"test4" );
00133 EXPECT_TRUE(fabs( valtmp - 35.0f ) < epsilon)
00134 << "Expected value : 35 "
00135 << "Received value : "<< valtmp;
00136
00137 valtmp = calib_parser.get_calibration_value(0.1f,"test4" );
00138 EXPECT_TRUE(fabs( valtmp - 10.0f ) < epsilon)
00139 << "Expected value : 10 "
00140 << "Received value : "<< valtmp;
00141
00142 valtmp = calib_parser.get_calibration_value(0.0f,"test4" );
00143 EXPECT_TRUE(fabs( valtmp - 60.0f ) < epsilon)
00144 << "Expected value : 60 "
00145 << "Received value : "<< valtmp;
00146
00147 valtmp = calib_parser.get_calibration_value(0.2f,"test4" );
00148 EXPECT_TRUE(fabs( valtmp + 40.0f) < epsilon)
00149 << "Expected value : -40 "
00150 << "Received value : "<< valtmp;
00151 }
00152
00153
00154 int main(int argc, char **argv){
00155
00156 calib_parser = XmlCalibrationParser(path_to_calibration);
00157
00158 testing::InitGoogleTest(&argc, argv);
00159 return RUN_ALL_TESTS();
00160
00161 }