00001 #include "ippOnScanReportBuilderTestCase.h"
00002 #include "ippdme/Misc/ippOnScanReportBuilder.h"
00003 #include "ippdme/Parser/ippResponseParser.h"
00004
00005 #include "ippMemoryLeakDetector.h"
00006 #include <fstream>
00007
00008
00009 void ippOnScanReportBuilderTestCase::test_single_point()
00010 {
00011
00012 ippOnScanReportCommandPtr _OnScanReportCmd = new ippOnScanReportCommand(10);
00013
00014 _OnScanReportCmd->append(ippOnScanReportCommand::Q);
00015 _OnScanReportCmd->append(ippOnScanReportCommand::Y);
00016 _OnScanReportCmd->append(ippOnScanReportCommand::ToolA);
00017
00018 ippOnScanReportBuilder _builder(_OnScanReportCmd);
00019 IPP_UTEST_ASSERT_EQUALS(0,_builder._values.size());
00020 IPP_UTEST_ASSERT(_builder.IsEmpty());
00021 IPP_UTEST_ASSERT(!_builder.IsNearlyFull());
00022
00023
00024 _builder.StartPoint();
00025 IPP_UTEST_ASSERT_EQUALS(3,_builder._values.size());
00026 _builder.setValue(ippOnScanReportCommand::X ,10.0);
00027 _builder.setValue(ippOnScanReportCommand::Y ,11.0);
00028 _builder.setValue(ippOnScanReportCommand::Z ,12.0);
00029 _builder.setValue(ippOnScanReportCommand::ToolA,20.0);
00030 _builder.setValue(ippOnScanReportCommand::ToolB,21.0);
00031 _builder.setValue(ippOnScanReportCommand::ToolC,22.0);
00032 _builder.setValues(ippOnScanReportCommand::IJK ,30.0,31.0,32.0);
00033 _builder.setValue(ippOnScanReportCommand::Q ,40.0);
00034 _builder.setValue(ippOnScanReportCommand::ER ,50.0);
00035 _builder.Commit();
00036 IPP_UTEST_ASSERT(!_builder.IsEmpty());
00037 IPP_UTEST_ASSERT(!_builder.IsNearlyFull());
00038 IPP_UTEST_ASSERT_EQUALS(3,_builder._values.size());
00039
00040 ippScanResponsePtr _response =_builder.FlushAndGetResponse(10);
00041 std::string txt = _response->getResponseString();
00042 IPP_UTEST_ASSERT(_builder.IsEmpty());
00043 IPP_UTEST_ASSERT(!_builder.IsNearlyFull());
00044 IPP_UTEST_ASSERT_EQUALS(0,_builder._values.size());
00045
00046
00047 IPP_UTEST_ASSERT_EQUALS(txt,"00010 # 40., 11., 20.\r\n");
00048
00049 }
00050 void ippOnScanReportBuilderTestCase::test_two_points()
00051 {
00052
00053 ippOnScanReportCommandPtr _OnScanReportCmd = new ippOnScanReportCommand(10);
00054
00055 _OnScanReportCmd->append(ippOnScanReportCommand::Q);
00056 _OnScanReportCmd->append(ippOnScanReportCommand::Y);
00057 _OnScanReportCmd->append(ippOnScanReportCommand::ToolA);
00058
00059 ippOnScanReportBuilder _builder(_OnScanReportCmd);
00060 IPP_UTEST_ASSERT_EQUALS(0,_builder._values.size());
00061 IPP_UTEST_ASSERT(_builder.IsEmpty());
00062 IPP_UTEST_ASSERT(!_builder.IsNearlyFull());
00063
00064
00065 _builder.StartPoint();
00066 IPP_UTEST_ASSERT_EQUALS(3,_builder._values.size());
00067 _builder.setValue(ippOnScanReportCommand::X ,10.0);
00068 _builder.setValue(ippOnScanReportCommand::Y ,11.0);
00069 _builder.setValue(ippOnScanReportCommand::Z ,12.0);
00070 _builder.setValue(ippOnScanReportCommand::ToolA,20.0);
00071 _builder.setValue(ippOnScanReportCommand::ToolB,21.0);
00072 _builder.setValue(ippOnScanReportCommand::ToolC,22.0);
00073 _builder.setValues(ippOnScanReportCommand::IJK ,30.0,31.0,32.0);
00074 _builder.setValue(ippOnScanReportCommand::Q ,40.0);
00075 _builder.setValue(ippOnScanReportCommand::ER ,50.0);
00076 _builder.Commit();
00077 IPP_UTEST_ASSERT(!_builder.IsEmpty());
00078 IPP_UTEST_ASSERT(!_builder.IsNearlyFull());
00079 IPP_UTEST_ASSERT_EQUALS(3,_builder._values.size());
00080
00081
00082 _builder.StartPoint();
00083 IPP_UTEST_ASSERT_EQUALS(6,_builder._values.size());
00084 _builder.setValue(ippOnScanReportCommand::X ,90010.0);
00085 _builder.setValue(ippOnScanReportCommand::Y ,90011.0);
00086 _builder.setValue(ippOnScanReportCommand::Z ,90012.0);
00087 _builder.setValue(ippOnScanReportCommand::ToolA,90020.0);
00088 _builder.setValue(ippOnScanReportCommand::ToolB,90021.0);
00089 _builder.setValue(ippOnScanReportCommand::ToolC,90022.0);
00090 _builder.setValues(ippOnScanReportCommand::IJK ,90030.0,90031.0,90032.0);
00091 _builder.setValue(ippOnScanReportCommand::Q ,90040.0);
00092 _builder.setValue(ippOnScanReportCommand::ER ,90050.0);
00093 _builder.Commit();
00094
00095 IPP_UTEST_ASSERT(!_builder.IsEmpty());
00096 IPP_UTEST_ASSERT(!_builder.IsNearlyFull());
00097 IPP_UTEST_ASSERT_EQUALS(6,_builder._values.size());
00098
00099 ippScanResponsePtr _response =_builder.FlushAndGetResponse(10);
00100
00101 IPP_UTEST_ASSERT(_builder.IsEmpty());
00102 IPP_UTEST_ASSERT(!_builder.IsNearlyFull());
00103
00104
00105 std::string txt = _response->getResponseString();
00106
00107 IPP_UTEST_ASSERT_EQUALS(txt,"00010 # 40., 11., 20., 90040., 90011., 90020.\r\n");
00108
00109
00110 }
00111 void ippOnScanReportBuilderTestCase::test_IsNearlyFull()
00112 {
00113
00114 int old = ippOnScanReportBuilder::_max_number_of_values;
00115 ippOnScanReportBuilder::_max_number_of_values = 77;
00116
00117 ippOnScanReportCommandPtr _OnScanReportCmd = new ippOnScanReportCommand(10);
00118
00119 _OnScanReportCmd->append(ippOnScanReportCommand::Q);
00120 _OnScanReportCmd->append(ippOnScanReportCommand::IJK);
00121 _OnScanReportCmd->append(ippOnScanReportCommand::Y);
00122 _OnScanReportCmd->append(ippOnScanReportCommand::X);
00123 _OnScanReportCmd->append(ippOnScanReportCommand::Z);
00124 _OnScanReportCmd->append(ippOnScanReportCommand::ToolA);
00125
00126 ippOnScanReportBuilder _builder(_OnScanReportCmd);
00127
00128
00129 int nbResponses = 0;
00130 for (int i =0; i<20 ;i++) {
00131 _builder.StartPoint();
00132 _builder.setValues(ippOnScanReportCommand::IJK ,(1000+ i)+30.0,(1000+ i)+31.0,(1000+ i)+32.0);
00133 _builder.setValue(ippOnScanReportCommand::Q ,(1000+ i)+40.0);
00134 _builder.setValue(ippOnScanReportCommand::X ,(1000+ i)+10.0);
00135 _builder.setValue(ippOnScanReportCommand::Y ,(1000+ i)+11.0);
00136 _builder.setValue(ippOnScanReportCommand::Z ,(1000+ i)+12.0);
00137 _builder.setValue(ippOnScanReportCommand::ToolA,(1000+ i)+20.0);
00138 _builder.Commit();
00139 IPP_UTEST_ASSERT(!_builder.IsEmpty());
00140 if (_builder.IsNearlyFull()) {
00141 ippScanResponsePtr _response =_builder.FlushAndGetResponse(10);
00142 std::string txt = _response->getResponseString();
00143 nbResponses ++;
00144
00145 IPP_UTEST_ASSERT(_builder.IsEmpty());
00146 }
00147
00148 }
00149 if (!_builder.IsEmpty()) {
00150 ippScanResponsePtr _response =_builder.FlushAndGetResponse(10);
00151 std::string txt = _response->getResponseString();
00152 nbResponses ++;
00153
00154 }
00155 IPP_UTEST_ASSERT(_builder.IsEmpty());
00156
00157 IPP_UTEST_ASSERT_EQUALS(2,nbResponses );
00158
00159 ippOnScanReportBuilder::_max_number_of_values = old;
00160
00161
00162 }
00163
00164 void ippOnScanReportBuilderTestCase::test_very_large_response_bloc()
00165 {
00166
00167 int old = ippOnScanReportBuilder::_max_number_of_values;
00168 ippOnScanReportBuilder::_max_number_of_values = 1000;
00169
00170 ippOnScanReportCommandPtr _OnScanReportCmd = new ippOnScanReportCommand(10);
00171
00172 _OnScanReportCmd->append(ippOnScanReportCommand::Q);
00173 _OnScanReportCmd->append(ippOnScanReportCommand::Y);
00174 _OnScanReportCmd->append(ippOnScanReportCommand::IJK);
00175 _OnScanReportCmd->append(ippOnScanReportCommand::X);
00176 _OnScanReportCmd->append(ippOnScanReportCommand::Z);
00177 _OnScanReportCmd->append(ippOnScanReportCommand::ToolA);
00178 _OnScanReportCmd->append(ippOnScanReportCommand::ToolB);
00179 _OnScanReportCmd->append(ippOnScanReportCommand::ER);
00180
00181 ippOnScanReportBuilder _builder(_OnScanReportCmd);
00182
00183
00184 int nbResponses = 0;
00185 for (int i =0; i<10000 ;i++) {
00186
00187 _builder.StartPoint();
00188 _builder.setValue(ippOnScanReportCommand::Q ,(1000+ i)+40.0);
00189 _builder.setValue(ippOnScanReportCommand::X ,(1000+ i)+10.0);
00190 _builder.setValue(ippOnScanReportCommand::Y ,(1000+ i)+11.0);
00191 _builder.setValue(ippOnScanReportCommand::Z ,(1000+ i)+12.0);
00192 _builder.setValue(ippOnScanReportCommand::ToolA,(1000+ i)+20.0);
00193 _builder.setValue(ippOnScanReportCommand::ToolA,(1000+ i)+21.0);
00194 _builder.setValue(ippOnScanReportCommand::ER ,(1000+ i)+50.0);
00195 _builder.setValues(ippOnScanReportCommand::IJK ,(1000+ i)+30.0,(1000+ i)+31.0,(1000+ i)+32.0);
00196 _builder.Commit();
00197
00198 IPP_UTEST_ASSERT(!_builder.IsEmpty());
00199 if (_builder.IsNearlyFull()) {
00200 ippScanResponsePtr _response =_builder.FlushAndGetResponse(10);
00201 std::string txt = _response->getResponseString();
00202 nbResponses ++;
00203 IPP_UTEST_ASSERT(_builder.IsEmpty());
00204
00205 IPP_UTEST_ASSERT(_response->getDataSize() >=ippOnScanReportBuilder::_max_number_of_values );
00206 ippResponseParser parser;
00207 parser.setInput(txt.c_str());
00208 ippResponsePtr r_check = parser.parseResponse();
00209 IPP_UTEST_ASSERT(r_check.get()!=0);
00210
00211 }
00212
00213 }
00214 if (!_builder.IsEmpty()) {
00215 ippScanResponsePtr _response =_builder.FlushAndGetResponse(10);
00216 std::string txt = _response->getResponseString();
00217 nbResponses ++;
00218 }
00219 IPP_UTEST_ASSERT(_builder.IsEmpty());
00220
00221 ippOnScanReportBuilder::_max_number_of_values = old;
00222
00223
00224 }
00225