11 std::ofstream
output(
"testSaveEngineStatus.cout");
13 std::ostream &
output = std::cout;
18#define TEST_ORIGINAL_SAVE
23#define TEST_MISSING_FILES
24#define CREATE_OLD_SAVES
25#define VERIFY_OLD_SAVES
43 std::vector<double> ab(2);
52 output <<
"r(1) = " << r << std::endl;
55 output <<
"r(2) = " << r << std::endl;
58 output <<
"r(3) = " << r << std::endl;
59 for (
int i=0; i < 1001; i++) {
64 output <<
"r1005= " << r << std::endl;
72 output <<
"restored r(2) = " << r << std::endl;
74 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
77 output <<
"restored r(3) = " << r << std::endl;
78 for (
int i=0; i < 1001; i++) {
82 output <<
"restored r1005= " << r << std::endl;
84 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
91 output <<
"r(1) = " << r << std::endl;
94 output <<
"r(2) = " << r << std::endl;
97 output <<
"r(3) = " << r << std::endl;
99 for (
int i=0; i < 1001; i++) {
102 "This line inserted so clever compilers don't warn about not using d\n";
106 output <<
"r1005= " << r << std::endl;
114 output <<
"restored r(2) = " << r << std::endl;
116 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
119 output <<
"restored r(3) = " << r << std::endl;
120 for (
int i=0; i < 1001; i++) {
124 output <<
"restored r1005= " << r << std::endl;
126 output <<
"THIS DOES NOT MATCH REMEMBERED VALUE BUT THAT IS EXPECTED\n";
136 output <<
"r(1) = " << r << std::endl;
139 output <<
"r(2) = " << r << std::endl;
142 output <<
"r(3) = " << r << std::endl;
143 for (
int i=0; i < 1001; i++) {
148 output <<
"r1005= " << r << std::endl;
157 output <<
"restored r(2) = " << r << std::endl;
159 std::cout <<
"restored r(2) = " << r << std::endl;
160 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
162 output <<
"restored r(2) = " << r << std::endl;
163 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
168 output <<
"restored r(3) = " << r << std::endl;
169 for (
int i=0; i < 1001; i++) {
173 output <<
"restored r1005= " << r << std::endl;
175 std::cout <<
"restored r1005= " << r << std::endl;
176 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
178 output <<
"restored r1005= " << r << std::endl;
179 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
189 output <<
"r(1) = " << r << std::endl;
192 output <<
"r(2) = " << r << std::endl;
195 output <<
"r(3) = " << r << std::endl;
196 for (
int i=0; i < 1001; i++) {
201 output <<
"r1005 = " << r << std::endl;
204 output <<
"r1006 = " << r << std::endl;
207 output <<
"r1007 = " << r << std::endl;
216 output <<
"restored r(2) = " << r << std::endl;
219 std::cout <<
"restored r(2) = " << r << std::endl;
220 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
222 output <<
"restored r(2) = " << r << std::endl;
223 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
227 output <<
"restored r(3) = " << r << std::endl;
228 for (
int i=0; i < 1001; i++) {
232 output <<
"restored r1005= " << r << std::endl;
235 std::cout <<
"restored r1005= " << r << std::endl;
236 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
238 output <<
"restored r1005= " << r << std::endl;
239 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
243 output <<
"restored r1006= " << r << std::endl;
246 std::cout <<
"restored r1006= " << r << std::endl;
247 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
249 output <<
"restored r1006= " << r << std::endl;
250 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
254 output <<
"restored r1007= " << r << std::endl;
257 std::cout <<
"restored r1007= " << r << std::endl;
258 std::cout <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
260 output <<
"restored r1007= " << r << std::endl;
261 output <<
"????? THIS DOES NOT MATCH REMEMBERED VALUE!\n";
269template <
class E,
class D>
274 output <<
"File-not-found test restoring "<<D::distributionName()<<
":\n";
276 D::restoreEngineStatus(
"noSuchFile");
277 D::setTheEngine(old);
324template <
class E,
class D>
331 for (
int i=0; i<3; i++) r += D::shoot();
332 D::saveEngineStatus(filename);
333 if (r == -99999999.1) stat = 999;
335 D::setTheEngine(old);
343template <
class E,
class D>
352 for (
int i=0; i<3; i++) r += D::shoot();
353 D::saveEngineStatus();
356 double keyValue = D::shoot();
359 D::restoreEngineStatus(filename);
360 if (!
equals(D::shoot(), keyValue)) {
361 std::cout <<
"???? Value mismatch from file " << filename <<
"\n";
363 output <<
"???? Value mismatch from file " << filename <<
"\n";
369 D::restoreEngineStatus();
370 if (!
equals(D::shoot(),keyValue)) {
371 std::cout <<
"???? Value mismatch from new-format file \n";
373 output <<
"???? Value mismatch from new-format file \n";
378 D::setTheEngine(old);
390#ifdef TEST_ORIGINAL_SAVE
391 output <<
"=====================================\n";
393 output <<
"Original tests of static save/restore\n";
394 output <<
"=====================================\n\n";
396 output <<
"Using old method or HepRandom::saveEngineStatus:\n";
397 output <<
"All these tests should have a chance of failure.\n";
399 output << RandGauss:: getTheEngine()->name();
400 output << RandGaussQ::getTheEngine()->name();
407 output <<
"Using the class-specific RandGauss::saveEngineStatus:\n";
408 output <<
"All these tests should work properly.\n";
416#ifdef TEST_MISSING_FILES
417 output <<
"\n=======================================\n";
419 output <<
"Test of behavior when a file is missing \n";
420 output <<
"=======================================\n\n";
422 output <<
"Testing restoreEngineStatus with missing file:\n";
423 output <<
"Expect a number of <Failure to find or open> messages!\n";
427#ifdef CREATE_OLD_SAVES
441#ifdef VERIFY_OLD_SAVES
442 output <<
"\n==============================================\n";
444 output <<
" Verification that changes wont invalidate \n";
445 output <<
"invalidate engine saves from previous versions \n";
446 output <<
"==============================================\n\n";
461 output <<
"\n=============================================\n\n";
464 std::cout <<
"One or more problems detected: stat = " << stat <<
"\n";
465 output <<
"One or more problems detected: stat = " << stat <<
"\n";
467 output <<
"testSaveEngineStatus passed with no problems detected.\n";
470 if (stat == 0)
return 0;
471 if (stat > 0)
return -(stat|1);
static void restoreEngineStatus(const char filename[]="Config.conf")
static void saveEngineStatus(const char filename[]="Config.conf")
static void restoreEngineStatus(const char filename[]="Config.conf")
static void saveEngineStatus(const char filename[]="Config.conf")
static void restoreEngineStatus(const char filename[]="Config.conf")
static void saveEngineStatus(const char filename[]="Config.conf")
int saveEngine(const char *filename)
int checkSaveEngine(const char *filename)
bool equals(double a, double b)
bool equals01(const std::vector< double > &ab)
std::ofstream output("testSaveEngineStatus.cout")