00001 #include "nMessageMock.h"
00002 #include "tPolynomialMarshaler.h"
00003
00004 #include <cppunit/extensions/HelperMacros.h>
00005 #include <cppunit/extensions/TestFactoryRegistry.h>
00006
00007 class tPolynomialMarshalerTest : public CppUnit::TestFixture {
00008 private:
00009 tPolynomialMarshaler<nMessageMock> marshalerA;
00010 tPolynomialMarshaler<nMessageMock> marshalerB;
00011 tPolynomialMarshaler<nMessageMock> marshalerC;
00012
00013 std::string dataInA;
00014 std::string dataInB;
00015 std::string dataInC;
00016
00017 public:
00018 CPPUNIT_TEST_SUITE( tPolynomialMarshalerTest );
00019 CPPUNIT_TEST( testParsing );
00020 CPPUNIT_TEST( testConstructor );
00021 CPPUNIT_TEST( testMarshaling );
00022
00023 CPPUNIT_TEST_SUITE_END();
00024
00025 public:
00026 void setUp() {
00027 dataInA = "3:5";
00028 dataInB = "3;5:7;9";
00029 dataInC = "1;2;3:4;5;6";
00030
00031
00032
00033 marshalerA.setConstant(3.0, 0);
00034 marshalerA.setVariant(5.0, 0);
00035
00036
00037
00038
00039 marshalerB.setConstant(3.0, 0);
00040 marshalerB.setConstant(5.0, 1);
00041 marshalerB.setVariant(7.0, 0);
00042 marshalerB.setVariant(9.0, 1);
00043
00044
00045
00046
00047 marshalerC.setConstant(1.0, 0);
00048 marshalerC.setConstant(2.0, 1);
00049 marshalerC.setConstant(3.0, 2);
00050 marshalerC.setVariant(4.0, 0);
00051 marshalerC.setVariant(5.0, 1);
00052 marshalerC.setVariant(6.0, 2);
00053 }
00054
00055 void tearDown() {
00056
00057 }
00058
00059 void testParsing() {
00060 tPolynomialMarshaler<nMessageMock> marshalerParsed;
00061
00062 marshalerParsed.parse(dataInB);
00063 CPPUNIT_ASSERT( marshalerB == marshalerParsed );
00064
00065 marshalerParsed.parse(dataInA);
00066 CPPUNIT_ASSERT( marshalerA == marshalerParsed );
00067
00068 marshalerParsed.parse(dataInC);
00069 CPPUNIT_ASSERT( marshalerC == marshalerParsed );
00070 }
00071
00072 void testConstructor() {
00073
00074 tPolynomialMarshaler<nMessageMock> marshalerCopyA(marshalerA);
00075 CPPUNIT_ASSERT( marshalerA == marshalerCopyA );
00076 tPolynomialMarshaler<nMessageMock> marshalerCopyB(marshalerB);
00077 CPPUNIT_ASSERT( marshalerB == marshalerCopyB );
00078 tPolynomialMarshaler<nMessageMock> marshalerCopyC(marshalerC);
00079 CPPUNIT_ASSERT( marshalerC == marshalerCopyC );
00080
00081
00082 tPolynomialMarshaler<nMessageMock> marshalerParsedA(dataInA);
00083 CPPUNIT_ASSERT( marshalerA == marshalerParsedA );
00084 tPolynomialMarshaler<nMessageMock> marshalerParsedB(dataInB);
00085 CPPUNIT_ASSERT( marshalerB == marshalerParsedB );
00086 tPolynomialMarshaler<nMessageMock> marshalerParsedC(dataInC);
00087 CPPUNIT_ASSERT( marshalerC == marshalerParsedC );
00088
00089
00090 tPolynomial<nMessageMock> tPolynomialA1("3");
00091 tPolynomial<nMessageMock> tPolynomialA2("5");
00092 tPolynomialMarshaler<nMessageMock> marshalerDuoPolynomialA(tPolynomialA1, tPolynomialA2);
00093 CPPUNIT_ASSERT( marshalerA == marshalerDuoPolynomialA );
00094 tPolynomial<nMessageMock> tPolynomialB1("3;5");
00095 tPolynomial<nMessageMock> tPolynomialB2("7;9");
00096 tPolynomialMarshaler<nMessageMock> marshalerDuoPolynomialB(tPolynomialB1, tPolynomialB2);
00097 CPPUNIT_ASSERT( marshalerB == marshalerDuoPolynomialB );
00098 tPolynomial<nMessageMock> tPolynomialC1("1;2;3");
00099 tPolynomial<nMessageMock> tPolynomialC2("4;5;6");
00100 tPolynomialMarshaler<nMessageMock> marshalerDuoPolynomialC(tPolynomialC1, tPolynomialC2);
00101 CPPUNIT_ASSERT( marshalerC == marshalerDuoPolynomialC );
00102 }
00103
00104 void testMarshaling() {
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 float inputData[] = {7, 5, 3};
00145 float expectedDataA[] = {3, 5};
00146 float expectedDataB[] = {38, 95, 60, 27};
00147 float expectedDataC[] = {162, 553, 652, 507, 207, 54};
00148 tPolynomial<nMessageMock> inputPolynomial(inputData, sizeof(inputData)/sizeof(inputData[0]));
00149 tPolynomial<nMessageMock> expectedA(expectedDataA, sizeof(expectedDataA)/sizeof(expectedDataA[0]));
00150 tPolynomial<nMessageMock> expectedB(expectedDataB, sizeof(expectedDataB)/sizeof(expectedDataB[0]));
00151 tPolynomial<nMessageMock> expectedC(expectedDataC, sizeof(expectedDataC)/sizeof(expectedDataC[0]));
00152
00153 float tData[] = {0, 1};
00154 tPolynomial<nMessageMock> t( tData, 2 );
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 CPPUNIT_ASSERT ( expectedA == marshalerA.marshal(inputPolynomial) );
00194 CPPUNIT_ASSERT ( expectedB == marshalerB.marshal(inputPolynomial) );
00195 CPPUNIT_ASSERT ( expectedC == marshalerC.marshal(inputPolynomial) );
00196 tPolynomial<nMessageMock> tp3 = inputPolynomial.adaptToNewReferenceVarValue(4);
00197
00198 std::cout << std::endl;
00199 std::cout << tp3.toString() << std::endl;
00200 std::cout << marshalerB.toString() << std::endl;
00201 std::cout << expectedB.adaptToNewReferenceVarValue(4).toString() << std::endl;
00202 std::cout << marshalerB.marshal(tp3).toString() << std::endl;
00203 CPPUNIT_ASSERT ( expectedB.adaptToNewReferenceVarValue(4) == marshalerB.marshal(tp3) );
00204
00205 }
00206
00211 void testMarshalingWithBase()
00212 {
00213 float inputData[] = {7, 5, 3};
00214 tPolynomial<nMessageMock> inputPolynomialAt0(inputData, sizeof(inputData)/sizeof(inputData[0]));
00215 tPolynomial<nMessageMock> inputPolynomialAt3(inputPolynomialAt0.adaptToNewReferenceVarValue(3));
00216
00217 tPolynomial<nMessageMock> marshaledResultAt0 = marshalerB.marshal(inputPolynomialAt0);
00218 tPolynomial<nMessageMock> marshaledResultAt3 = marshalerB.marshal(inputPolynomialAt3);
00219
00220
00221 std::cout << "at 0 : " << marshaledResultAt0(5) << " at 3 " << marshaledResultAt3(5) << std::endl;
00222 CPPUNIT_ASSERT ( marshaledResultAt0(5) == marshaledResultAt3(5) );
00223
00224 }
00225
00226 };
00227
00228 CPPUNIT_TEST_SUITE_REGISTRATION( tPolynomialMarshalerTest );