00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027
00028 #include <string.h>
00029 #include "MessageService/MsgService.h"
00030 #include "LeakChecker/Lea.h"
00031 #include "LeakChecker/LeaLeakChecker.h"
00032 #include "Lattice/Lattice.h"
00033 #include "Navigation/NavGenLattice.h"
00034 #include "Navigation/NavGenTCollection.h"
00035 #include "Navigation/NavItr.h"
00036 #include "Navigation/NavItrT.h"
00037 #include "Navigation/NavKey.h"
00038 #include "Navigation/NavMask.h"
00039 #include "Navigation/NavPrimer.h"
00040 #include "Navigation/NavSet.h"
00041 #include "Navigation/test/NavTestPlanet.h"
00042 #include "Navigation/test/NavTestMoon.h"
00043 #include "Navigation/test/NavValidate.h"
00044 #include "TObjArray.h"
00045 #include "TCollection.h"
00046 #include "TList.h"
00047
00048
00049
00050 typedef Lattice::ID ID;
00051 typedef Lattice::VectorID VectorID;
00052 typedef NavMask::Mask_t Mask_t;
00053
00054
00055
00056
00057 static NavKey KeyPlanet_Name(TObject* obj) {
00058 return ((NavTestPlanet*)obj)->GetName();
00059 }
00060
00061 static NavKey KeyPlanet_NameSafe(const NavTestPlanet* obj) {
00062 return obj->GetName();
00063 }
00064
00065 static NavKey KeyMoon_NameSafe(const NavTestMoon* obj) {
00066 return obj->GetName();
00067 }
00068
00069 static NavKey KeyMoon_ParentSafe(const NavTestMoon* obj) {
00070 return obj->GetParent();
00071 }
00072
00073 static NavKey KeyPlanet_OrderSafe(const NavTestPlanet* obj) {
00074 return obj->GetOrder();
00075 }
00076
00077 static NavKey KeyPlanet_MassSafe(const NavTestPlanet* obj) {
00078 return obj->GetMass();
00079 }
00080
00081 static NavKey KeyPlanet_Order(TObject* obj) {
00082 return ((NavTestPlanet*)obj)->GetOrder();
00083 }
00084
00085 static NavKey KeyMoon_Parent(TObject* obj) {
00086 return ((NavTestMoon*)obj)->GetParent();
00087 }
00088
00089 static NavKey KeyMoon_Order(TObject* obj) {
00090 return ((NavTestMoon*)obj)->GetOrder();
00091 }
00092
00093 static NavKey SelPlanet(const NavTestPlanet* obj) {
00094 return ( obj->GetOrder() < 4
00095 || ( obj->GetOrder() > 6 && obj->GetOrder() < 9 ) );
00096 }
00097
00098
00099 class MoonKeyFunctor : public NavTestMoonKeyFunctor {
00100 public:
00101 MoonKeyFunctor(string lo = "",string hi = "");
00102 MoonKeyFunctor(const MoonKeyFunctor& that)
00103 : NavTestMoonKeyFunctor(that)
00104 { LEA_CTOR_NM("MoonKeyFunctor",this); *this = that; };
00105 ~MoonKeyFunctor(){ LEA_DTOR_NM("MoonKeyFunctor",this) }
00106 virtual NavTestMoonKeyFunctor* Clone() const { return
00107 new MoonKeyFunctor(*this); }
00108 virtual NavKey operator()(const NavTestMoon* obj) const;
00109 private:
00110 string fLoName;
00111 string fHiName;
00112 };
00113 MoonKeyFunctor::MoonKeyFunctor(string lo,string hi) :
00114 fLoName(lo),
00115 fHiName(hi)
00116 { LEA_CTOR_NM("MoonKeyFunctor",this) }
00117 NavKey MoonKeyFunctor::operator()(const NavTestMoon* obj) const {
00118 string name = obj->GetName();
00119 if ( fLoName != "" && name < fLoName ) return 0;
00120 if ( fHiName != "" && name > fHiName ) return 0;
00121 return 1;
00122 }
00123
00124 XXXITRIMP(TObject)
00125
00126 ClassImp(NavValidate)
00127
00128
00129
00130
00131 CVSID("$Id: NavValidate.cxx,v 1.17 2007/02/01 22:11:53 rhatcher Exp $");
00132
00133
00134
00135
00136
00137
00138 void NavValidate::EraseTestObjects() {
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 NavPrimer* primer = NavPrimer::Instance();
00157
00158 primer->DeleteAdoptedGenerators();
00159 fMoons->Delete();
00160 delete fMoons;
00161 LEA_DTOR_NM("TList",fMoons)
00162 fMoons = 0;
00163
00164 fPlanets->Delete();
00165 delete fPlanets;
00166 LEA_DTOR_NM("TList",fPlanets)
00167
00168 fPlanets = 0;
00169 }
00170
00171
00172
00173 TCollection* NavValidate::MakeTCollection(Int_t model ) const {
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 TList* tcol = new TList();
00198
00199 LEA_CTOR_NM("TList",tcol);
00200
00201 switch ( model ) {
00202
00203 case 0:
00204
00205
00206 tcol->Add( new NavTestPlanet("Mercury", 1, 0.055 ) );
00207 tcol->Add( new NavTestPlanet("Venus ", 2, 0.81 ) );
00208 tcol->Add( new NavTestPlanet("Earth", 3, 1.00 ) );
00209 tcol->Add( new NavTestPlanet("Mars", 4, 0.11 ) );
00210 tcol->Add( new NavTestPlanet("Jupiter", 5, 318.0 ) );
00211 tcol->Add( new NavTestPlanet("Saturn", 6, 95.0 ) );
00212 tcol->Add( new NavTestPlanet("Uranus", 7, 15.0 ) );
00213 tcol->Add( new NavTestPlanet("Neptune", 8, 17.0 ) );
00214 tcol->Add( new NavTestPlanet("Pluto", 9, 0.002 ) );
00215
00216 return tcol;
00217
00218 case 1:
00219
00220
00221 tcol->Add( new NavTestMoon("Moon", "Earth", 3 ) );
00222 tcol->Add( new NavTestMoon("Phobos", "Mars", 4 ) );
00223 tcol->Add( new NavTestMoon("Deimos", "Mars", 4 ) );
00224 tcol->Add( new NavTestMoon("Io", "Jupiter", 5 ) );
00225 tcol->Add( new NavTestMoon("Europa", "Jupiter", 5 ) );
00226 tcol->Add( new NavTestMoon("Ganymed", "Jupiter", 5 ) );
00227 tcol->Add( new NavTestMoon("Callist", "Jupiter", 5 ) );
00228 tcol->Add( new NavTestMoon("Titan", "Saturn", 6 ) );
00229 tcol->Add( new NavTestMoon("Ariel", "Uranus", 7 ) );
00230 tcol->Add( new NavTestMoon("Umbriel", "Uranus", 7 ) );
00231 tcol->Add( new NavTestMoon("Triton", "Neptune", 8 ) );
00232
00233 return tcol;
00234
00235 default:
00236
00237 MSG("Nav",Msg::kError) << "Unknown model" << model << endl;
00238
00239 tcol->Delete();
00240 delete tcol;
00241 LEA_DTOR_NM("TList",tcol)
00242
00243 return 0;
00244 }
00245 }
00246
00247
00248
00249 NavValidate::NavValidate() :
00250 fNumFail(0),
00251 fNumPass(0),
00252 fMoons(0),
00253 fPlanets(0)
00254 {
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 MSG("Nav",Msg::kVerbose) << "NavValidate ctor 1 at " << this
00269 << "\n";
00270
00271 }
00272
00273
00274
00275
00276 NavValidate::~NavValidate() {
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 MSG("Nav",Msg::kVerbose) << "NavValidate dtor at " << this << "\n";
00291
00292 }
00293
00294
00295
00296
00297 void NavValidate::PrepareTestObjects() {
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 fMoons = MakeTCollection(1);
00319 fPlanets = MakeTCollection(0);
00320
00321 NavPrimer* primer = NavPrimer::Instance();
00322
00323 primer->AdoptGenerator(
00324 new NavGenTCollection("NavTestPlanet", fPlanets) );
00325 primer->AdoptGenerator(
00326 new NavGenTCollection("NavTestMoon", fMoons) );
00327
00328 primer->AdoptGenerator(
00329 new NavGenLattice("NavTestPlanet", KeyPlanet_Order,
00330 "NavTestMoon", KeyMoon_Order, 0 ) );
00331 primer->AdoptGenerator(
00332 new NavGenLattice("NavTestPlanet", KeyPlanet_Name,
00333 "NavTestMoon", KeyMoon_Parent, 1 ) );
00334
00335 }
00336
00337
00338
00339 Bool_t NavValidate::RunAllTests() {
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 LeaLeakChecker* lea = LeaLeakChecker::Instance();
00360 lea->Reset();
00361
00362
00363
00364 Bool_t ok = kTRUE;
00365 Nav::SetLogLevel(Msg::kInfo);
00366
00367 for ( Int_t testNum = 1; testNum <= kNUMTESTS; testNum++ ) {
00368 if ( ! RunTest(testNum) ) ok = kFALSE;
00369 }
00370
00371
00372
00373 delete NavPrimer::Instance();
00374
00375 if ( lea->GetNumCreated() == 0 ) {
00376 MSG("Nav",Msg::kInfo) << "Warning: Leak checking disabled!!"
00377 << endl;
00378 }
00379 else if ( lea->GetNumActive() ) {
00380 MSG("Nav",Msg::kInfo) << "\nError, leaks detected! " << lea;
00381 ok = kFALSE;
00382 }
00383 else {
00384 MSG("Nav",Msg::kInfo) << "\nO.K., no leaks detected! " << lea;
00385 }
00386
00387 MSG("Nav",Msg::kInfo) << "\nOverall test status: "
00388 << ( ok ? "O.K.\n" : "failed!\n") << endl;
00389
00390 return ok;
00391 }
00392
00393
00394
00395
00396 Bool_t NavValidate::RunTest(Int_t testNum) {
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417 switch ( testNum ) {
00418 case 1: return Test_1();
00419 case 2: return Test_2();
00420 case 3: return Test_3();
00421 case 4: return Test_4();
00422 case 5: return Test_5();
00423 case 6: return Test_6();
00424 case 7: return Test_7();
00425 case 8: return Test_8();
00426 case 9: return Test_9();
00427 case 10: return Test_10();
00428 }
00429 MSG("Nav",Msg::kError) << "Undefined test: " << testNum << "\n";
00430 return kFALSE;
00431
00432 }
00433
00434
00435 Bool_t NavValidate::Test_1() {
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458 Bool_t ok = kTRUE;
00459
00460
00461
00462 TCollection* tcol = MakeTCollection();
00463 UInt_t tcolSize = tcol->Capacity();
00464 NavTestPlanetItr itr(tcol);
00465
00466 TIter rootIter(tcol);
00467 NavTestPlanetItr itr2(&rootIter);
00468 NavTestPlanetItr itr2a(rootIter);
00469
00470
00471
00472
00473 UInt_t size = itr.Size();
00474 if ( size != tcolSize
00475 || itr2.Size() != tcolSize
00476 || itr2a.Size() != tcolSize ) {
00477 MSG("Nav",Msg::kError)
00478 << "Set sizes are: " << size << "," << itr2.Size()
00479 << itr2a.Size() << " should be " << tcolSize << endl;
00480 ok = kFALSE;
00481 }
00482
00483
00484
00485 if ( ! itr.IsValid() ) {
00486 MSG("Nav",Msg::kError)
00487 << "Iterator not initialise to an object" << endl;
00488 ok = kFALSE;
00489 }
00490 else if ( strcmp( itr.Ptr()->GetName(), "Mercury")
00491 || itr.Ptr()->GetOrder() != 1 ) {
00492 MSG("Nav",Msg::kError)
00493 << "Iterator not initialised to first object:-" << endl
00494 << itr.Ptr()->GetName() << " " << itr.Ptr()->GetOrder() << " "
00495 << itr.Ptr()->GetMass() << " using Ptr()" << endl;
00496 ok = kFALSE;
00497 }
00498 else if ( strcmp( itr.Ptr()->GetName(), "Mercury")
00499 || itr.Ptr()->GetOrder() != 1 ) {
00500 MSG("Nav",Msg::kError)
00501 << "Iterator not initialised to first object:-" << endl
00502 << itr.Ptr()->GetName() << " " << itr.Ptr()->GetOrder() << " "
00503 << itr.Ptr()->GetMass() << " using Obj()" << endl;
00504 ok = kFALSE;
00505 }
00506
00507
00508
00509 UInt_t nreve = 0;
00510 itr.ResetLast();
00511 while ( *itr ) {
00512 nreve++;
00513 --itr;
00514 }
00515
00516 UInt_t nforw = 0;
00517
00518
00519 while ( *++itr ) nforw++;
00520
00521 if ( nreve != tcolSize || nforw != tcolSize ) {
00522 MSG("Nav",Msg::kError)
00523 << "Iterating using ++ and -- give " << nforw
00524 << "," << nreve << " but should give " << tcolSize << endl;
00525 ok = kFALSE;
00526 }
00527
00528
00529
00530
00531
00532 itr.ResetFirst();
00533 nforw = 1;
00534 while ( itr.Next() ) nforw++;
00535
00536 itr.ResetLast();
00537 nreve = 1;
00538 while ( itr. PrevPtr() ) nreve++;
00539
00540
00541 if ( nreve != tcolSize || nforw != tcolSize ) {
00542 MSG("Nav",Msg::kError)
00543 << "Iterating using Next and PrevPtr give " << nforw
00544 << "," << nreve << " but should give " << tcolSize << endl;
00545 ok = kFALSE;
00546 }
00547
00548
00549
00550 itr.ResetFirst();
00551 itr.SetDirection(1);
00552 nforw = 0;
00553 while ( itr() ) nforw++;
00554
00555 itr.ResetLast();
00556 nreve = 0;
00557 while ( itr() ) nreve++;
00558
00559 if ( nreve != tcolSize || nforw != tcolSize ) {
00560 MSG("Nav",Msg::kError)
00561 << "Iterating using operator() give " << nforw
00562 << "," << nreve << " but should give " << tcolSize << endl;
00563 ok = kFALSE;
00564
00565 }
00566
00567
00568
00569
00570 itr.ResetFirst();
00571 --itr;
00572 if ( itr.IsValid() ) {
00573 MSG("Nav",Msg::kError)
00574 << "Iterator valid before first entry" << endl;
00575 ok = kFALSE;
00576 }
00577 itr.ResetLast();
00578 ++itr;
00579 if ( itr.IsValid() ) {
00580 MSG("Nav",Msg::kError)
00581 << "Iterator valid after last entry" << endl;
00582 ok = kFALSE;
00583 }
00584
00585
00586
00587
00588 MSG("Nav",Msg::kInfo) << "This test should fail!" << endl;
00589
00590 NavItr bad(tcol,"WrongObject");
00591
00592 if ( bad.Size() != 0 ) {
00593 MSG("Nav",Msg::kError)
00594 << "NavItr accepted TCollection of wrong objects" << endl;
00595 ok = kFALSE;
00596 }
00597
00598
00599
00600
00601
00602
00603 TObject obj1, obj2, obj3;
00604 TObjArray objArray;
00605
00606
00607 objArray.Add( &obj1);
00608 objArray.Add( &obj2);
00609 objArray.Add( &obj3);
00610 TObjectItr itrObj;
00611 itrObj.Attach(&objArray);
00612 if (itrObj.Size() != 3) {
00613 MSG("Nav",Msg::kError)
00614 << "Test of default ctor failed. Size should be 3 but gave "
00615 << itrObj.Size() << endl;
00616 ok = kFALSE;
00617 }
00618
00619
00620
00621
00622
00623 tcol->Delete();
00624 delete tcol;
00625 LEA_DTOR_NM("TList",tcol)
00626
00627 MSG("Nav",Msg::kInfo)
00628 << "Test 1: Iterators over simple set ...... ";
00629 MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
00630 MSG("Nav",Msg::kInfo) << "\n";
00631
00632 if ( ok ) fNumPass++; else fNumFail++;
00633
00634 return ok;
00635
00636 }
00637
00638
00639 Bool_t NavValidate::Test_2() {
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654 Bool_t ok = kTRUE;
00655
00656
00657
00658
00659 PrepareTestObjects();
00660
00661 UInt_t numMoons = fMoons->Capacity();
00662 UInt_t numPlanets = fPlanets->Capacity();
00663
00664
00665 UInt_t numPlanetsWithMoons = numPlanets - 3;
00666
00667 NavPrimer* primer = NavPrimer::Instance();
00668
00669
00670
00671
00672 VectorID planetIDs;
00673 VectorID moonIDs;
00674
00675 const Lattice* lat0 = primer->FindLattice("NavTestPlanet",
00676 "NavTestMoon",
00677 0);
00678 if ( ! lat0 ) {
00679 MSG("Nav",Msg::kError)
00680 << "Lattice 0 was not created "<< endl;
00681 ok = kFALSE;
00682 }
00683 else {
00684 lat0->GetAllIDs( Lattice::kLeft, planetIDs);
00685 lat0->GetAllIDs( Lattice::kRight, moonIDs);
00686
00687 if ( moonIDs.size() != numMoons
00688 || planetIDs.size() != numPlanetsWithMoons ) {
00689 MSG("Nav",Msg::kError)
00690 << "Lattice 0 has planets,moons: " << planetIDs.size() << ","
00691 << moonIDs.size() << " but should have: "
00692 << numPlanetsWithMoons << "," << numMoons << endl;
00693 ok = kFALSE;
00694 }
00695 }
00696
00697 planetIDs.clear();
00698 moonIDs.clear();
00699
00700 const Lattice* lat1 = primer->FindLattice("NavTestPlanet",
00701 "NavTestMoon",
00702 1);
00703 if ( ! lat1 ) {
00704 MSG("Nav",Msg::kError)
00705 << "Lattice 0 was not created "<< endl;
00706 ok = kFALSE;
00707 }
00708 else {
00709 lat1->GetAllIDs( Lattice::kLeft, planetIDs);
00710 lat1->GetAllIDs( Lattice::kRight, moonIDs);
00711
00712 if ( moonIDs.size() != numMoons
00713 || planetIDs.size() != numPlanetsWithMoons ) {
00714 MSG("Nav",Msg::kError)
00715 << "Lattice 1 has planets,moons: " << planetIDs.size() << ","
00716 << moonIDs.size() << " but should have: "
00717 << numPlanetsWithMoons << "," << numMoons << endl;
00718 ok = kFALSE;
00719 }
00720 }
00721
00722
00723
00724
00725 EraseTestObjects();
00726
00727
00728 MSG("Nav",Msg::kInfo)
00729 << "Test 2: Primer and Generators. ...... ";
00730 MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
00731 MSG("Nav",Msg::kInfo) << "\n";
00732
00733 if ( ok ) fNumPass++; else fNumFail++;
00734
00735 return ok;
00736
00737 }
00738
00739
00740 Bool_t NavValidate::Test_3() {
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754 Bool_t ok = kTRUE;
00755
00756
00757
00758 PrepareTestObjects();
00759
00760 UInt_t numMoons = fMoons->Capacity();
00761 UInt_t numPlanets = fPlanets->Capacity();
00762
00763
00764 UInt_t numPlanetsWithMoons = numPlanets - 3;
00765
00766
00767
00768
00769
00770 NavTestPlanetItr pItr("NavTestMoon",0);
00771 NavTestMoonItr mItr("NavTestPlanet",0);
00772
00773 UInt_t np = 0;
00774 UInt_t nm = 0;
00775 NavTestPlanet* p = 0;
00776 NavTestMoon* m = 0;
00777
00778
00779
00780 p = pItr.Ptr();
00781 while ( p ) {
00782 m = mItr.Map(p);
00783 while ( m ) {
00784 if ( strcmp( m->GetParent(), p->GetName()) ) {
00785 MSG("Nav",Msg::kError)
00786 << "Planet/Moon name mismatch:" << p->GetName()
00787 << ":" << m->GetParent() << endl;
00788 ok = kFALSE;
00789 }
00790 nm++;
00791 m = mItr.NextPtr();
00792 }
00793 np++;
00794 p = pItr.NextPtr();
00795 }
00796
00797 if ( np != numPlanetsWithMoons || nm != numMoons ) {
00798 MSG("Nav",Msg::kError)
00799 << "Iterating Lattice planet,moon gives planet,moon counts "
00800 << np << "," << nm << "but should give "
00801 << numPlanetsWithMoons << "," << numMoons << endl;
00802 ok = kFALSE;
00803 }
00804
00805
00806
00807
00808
00809 mItr.Map(0);
00810
00811 nm = 0;
00812
00813 m = mItr.Ptr();
00814 while ( m ) {
00815 p = pItr.Map(m);
00816 if ( strcmp( m->GetParent(), p->GetName()) ) {
00817 MSG("Nav",Msg::kError)
00818 << "Planet/Moon name mismatch:" << p->GetName()
00819 << ":" << m->GetParent() << endl;
00820 ok = kFALSE;
00821 }
00822 nm++;
00823 m = mItr.NextPtr();
00824 }
00825
00826 if ( nm != numMoons ) {
00827 MSG("Nav",Msg::kError)
00828 << "Iterating Lattice moon,planet gives moon counts "
00829 << nm << " but should give " << numMoons << endl;
00830 ok = kFALSE;
00831 }
00832
00833
00834
00835
00836 NavTestPlanetItr p2Itr;
00837 NavTestMoonItr m2Itr;
00838
00839 np = p2Itr.Size();
00840 nm = m2Itr.Size();
00841
00842 if ( np != numPlanets || nm != numMoons ) {
00843 MSG("Nav",Msg::kError)
00844 << "Size of TCollection gives planet.moon counts"
00845 << np << "," << nm << " but should give "
00846 << numPlanets << "," << numMoons << endl;
00847 ok = kFALSE;
00848 }
00849
00850
00851
00852 EraseTestObjects();
00853
00854
00855 MSG("Nav",Msg::kInfo)
00856 << "Test 3: Lattice mapping. ...... ";
00857 MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
00858 MSG("Nav",Msg::kInfo) << "\n";
00859
00860 if ( ok ) fNumPass++; else fNumFail++;
00861
00862 return ok;
00863
00864 }
00865
00866
00867 Bool_t NavValidate::Test_4() {
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883 Bool_t ok = kTRUE;
00884
00885
00886
00887 TCollection* tcol = MakeTCollection(1);
00888 NavTestMoonItr itr(tcol);
00889
00890
00891
00892
00893 NavTestMoonItr itr2(itr);
00894
00895 if ( itr.Size() != itr2.Size() || itr.GetSet() != itr2.GetSet() ) {
00896 MSG("Nav",Msg::kError)
00897 << "Copy ctor does not create an identical iterator. "
00898 << "Sizes:" << itr.Size() << "," << itr2.Size()
00899 << " NavSet pointers: " << itr.GetSet() << ","
00900 << itr2.GetSet() << endl;
00901 ok = kFALSE;
00902 }
00903
00904
00905 NavItrT<NavTestMoon> itr99(tcol);
00906
00907 while ( const NavTestMoon* ptr =itr99() ) cout << "Testing ... " << ptr->GetName() << endl;
00908
00909
00910
00911
00912
00913 ++itr;
00914 ++itr;
00915 itr2 = itr;
00916
00917 if ( itr.GetIndex() != itr2.GetIndex() || itr.GetSet() != itr2.GetSet() ) {
00918 MSG("Nav",Msg::kError)
00919 << "Assignment does not create an identical iterator. "
00920 << "Index:" << itr.GetIndex() << "," << itr2.GetIndex()
00921 << " NavSet pointers: " << itr.GetSet() << ","
00922 << itr2.GetSet() << endl;
00923 ok = kFALSE;
00924 }
00925
00926
00927
00928 NavTestMoonItr itr3(tcol);
00929 itr2 = itr3;
00930
00931 if ( itr3.Size() != itr2.Size() || itr3.GetSet() != itr2.GetSet() ) {
00932 MSG("Nav",Msg::kError)
00933 << "Assignment to diff set does not create an identical iterator. "
00934 << "Sizes:" << itr3.Size() << "," << itr2.Size()
00935 << " NavSet pointers: " << itr3.GetSet() << ","
00936 << itr2.GetSet() << endl;
00937 ok = kFALSE;
00938 }
00939
00940
00941
00942
00943
00944 tcol->Delete();
00945 delete tcol;
00946 LEA_DTOR_NM("TList",tcol)
00947
00948 MSG("Nav",Msg::kInfo)
00949 << "Test 4: Copy ctors and assignment. ...... ";
00950 MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
00951 MSG("Nav",Msg::kInfo) << "\n";
00952
00953 if ( ok ) fNumPass++; else fNumFail++;
00954
00955 return ok;
00956
00957 }
00958
00959
00960 Bool_t NavValidate::Test_5() {
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981 Bool_t ok = kTRUE;
00982
00983
00984
00985 PrepareTestObjects();
00986 NavTestPlanetItr itr(fPlanets);
00987 UInt_t numUnsliced = itr.Size();
00988
00989
00990
00991 UInt_t numSel = itr.SizeSelect();
00992 if ( numSel != numUnsliced ){
00993 MSG("Nav",Msg::kError)
00994 << "Unsliced set size != full size "
00995 << "Size.SizeSelect :" << numUnsliced << "," << numSel
00996 << endl;
00997 ok = kFALSE;
00998 }
00999
01000
01001
01002
01003 NavTestPlanetKeyFunc* pFunc = itr.CreateKeyFunc();
01004 pFunc->SetFun(KeyPlanet_NameSafe);
01005 itr.GetSet()->AdoptSortKeyFunc(pFunc);
01006 pFunc = 0;
01007
01008 itr.ResetFirst();
01009 NavTestPlanet* p = itr.Ptr();
01010 const Char_t* oldName = p->GetName();
01011 ++itr;
01012 while ( ( p = itr.Ptr()) ) {
01013 if ( strcmp(oldName,p->GetName()) >= 0 ) {
01014 MSG("Nav",Msg::kError)
01015 << "Character sort out of order. "
01016 << "Previous, current :" << oldName << "," << p->GetName()
01017 << endl;
01018 ok = kFALSE;
01019 }
01020 oldName = p->GetName();
01021 ++itr;
01022 }
01023
01024
01025
01026 const Char_t* loName = "J";
01027 const Char_t* hiName = "Mea";
01028 UInt_t numCharSlice = 2;
01029
01030 itr.GetSet()->Slice( loName, hiName);
01031 numSel = 0;
01032 while ( ( p = itr.Ptr()) ) {
01033 const Char_t* pName = p->GetName();
01034 if ( strcmp(pName,loName) < 0 || strcmp(pName,hiName) > 0 ) {
01035 MSG("Nav",Msg::kError)
01036 << "Character slice out of range: lo,current,hi: "
01037 << loName << "," << pName << "," << hiName
01038 << endl;
01039 ok = kFALSE;
01040 }
01041 ++itr;
01042 numSel++;
01043 }
01044
01045 if ( itr.SizeSelect() != numSel
01046 || numSel != numCharSlice) {
01047 MSG("Nav",Msg::kError)
01048 << "Char slice: num selected does not match SizeSelect"
01049 << " or expected: "
01050 << "num sel, SizeSelect(), expected " << numSel << ","
01051 << itr.SizeSelect() << "," << numCharSlice
01052 << endl;
01053 ok = kFALSE;
01054 }
01055
01056 if ( itr.Size() != numUnsliced ) {
01057 MSG("Nav",Msg::kError)
01058 << "Float slice:unsliced size does not match Size(): "
01059 << "num unsliced, Size() " << numUnsliced << "," << itr.Size()
01060 << endl;
01061 ok = kFALSE;
01062 }
01063
01064 itr.GetSet()->Slice();
01065
01066 if ( itr.SizeSelect() != numUnsliced ) {
01067 MSG("Nav",Msg::kError)
01068 << "Char cancelled slice:does not match Size(): "
01069 << "SizeSelect(), num unsliced " << itr.SizeSelect() << ","
01070 << numUnsliced << endl;
01071 ok = kFALSE;
01072 }
01073
01074
01075
01076 NavTestPlanetItr itr2(fPlanets);
01077
01078 pFunc = itr2.CreateKeyFunc();
01079 pFunc->SetFun(KeyPlanet_MassSafe);
01080 itr2.GetSet()->AdoptSortKeyFunc(pFunc);
01081 pFunc = 0;
01082
01083 itr2.ResetFirst();
01084 p = itr2.Ptr();
01085 Float_t oldMass = p->GetMass();
01086 ++itr2;
01087 while ( (p = itr2.Ptr()) ) {
01088 if ( oldMass >= p->GetMass() ) {
01089 MSG("Nav",Msg::kError)
01090 << "Float sort out of order. "
01091 << "Previous, current " << oldMass << "," << p->GetMass()
01092 << endl;
01093 ok = kFALSE;
01094 }
01095 oldMass = p->GetMass();
01096 ++itr2;
01097 }
01098
01099
01100
01101 Float_t loMass = 5.;
01102 Float_t hiMass = 10000.;
01103 UInt_t numFloatSlice = 4;
01104
01105 itr2.GetSet()->Slice( loMass, hiMass);
01106 numSel = 0;
01107 while ( ( p = itr2.Ptr()) ) {
01108 Float_t pMass = p->GetMass();
01109 if ( pMass < loMass || pMass > hiMass ) {
01110 MSG("Nav",Msg::kError)
01111 << "Float slice out of range: lo,current,hi: "
01112 << loMass << "," << pMass << "," << hiMass
01113 << endl;
01114 ok = kFALSE;
01115 }
01116 ++itr2;
01117 numSel++;
01118 }
01119
01120 if ( itr2.SizeSelect() != numSel
01121 || numSel != numFloatSlice ) {
01122 MSG("Nav",Msg::kError)
01123 << "Float slice: num selected does not match SizeSelect or"
01124 << " expected: "
01125 << "num sel, SizeSelect(), expected " << numSel << ","
01126 << itr2.SizeSelect() << "," << numFloatSlice
01127 << endl;
01128 ok = kFALSE;
01129 }
01130
01131 if ( itr2.Size() != numUnsliced ) {
01132 MSG("Nav",Msg::kError)
01133 << "Float slice:unsliced size does not match Size(): "
01134 << "num unsliced, Size() " << numUnsliced << ","
01135 << itr2.Size() << endl;
01136 ok = kFALSE;
01137 }
01138
01139 itr2.GetSet()->Slice();
01140
01141 if ( itr2.SizeSelect() != numUnsliced ) {
01142 MSG("Nav",Msg::kError)
01143 << "Float cancelled slice:does not match Size(): "
01144 << "SizeSelect(), num unsliced " << itr2.SizeSelect() << ","
01145 << numUnsliced << endl;
01146 ok = kFALSE;
01147 }
01148
01149
01150
01151
01152 pFunc = itr2.CreateKeyFunc();
01153 pFunc->SetFun(KeyPlanet_OrderSafe);
01154 itr2.GetSet()->AdoptSortKeyFunc(pFunc);
01155 pFunc = 0;
01156
01157 itr2.ResetFirst();
01158 p = itr2.Ptr();
01159 Int_t oldOrder = p->GetOrder();
01160 ++itr2;
01161 while ( (p = itr2.Ptr()) ) {
01162 if ( oldOrder >= p->GetOrder() ) {
01163 MSG("Nav",Msg::kError)
01164 << "Integer sort out of order. "
01165 << "Previous, current " << oldOrder << "," << p->GetOrder()
01166 << endl;
01167 ok = kFALSE;
01168 }
01169 oldOrder = p->GetOrder();
01170 ++itr2;
01171 }
01172
01173
01174
01175 Int_t loOrder = -1;
01176 Int_t hiOrder = 3;
01177 UInt_t numIntSlice = 3;
01178
01179 itr2.GetSet()->Slice( loOrder, hiOrder);
01180 numSel = 0;
01181 while ( ( p = itr2.Ptr()) ) {
01182 Int_t pOrder = p->GetOrder();
01183 if ( pOrder < loOrder || pOrder > hiOrder ) {
01184 MSG("Nav",Msg::kError)
01185 << "Int slice out of range: lo,current,hi: "
01186 << loOrder << "," << pOrder << "," << hiOrder
01187 << endl;
01188 ok = kFALSE;
01189 }
01190 ++itr2;
01191 numSel++;
01192 }
01193
01194 if ( itr2.SizeSelect() != numSel
01195 || numSel != numIntSlice ) {
01196 MSG("Nav",Msg::kError)
01197 << "Int slice: num selected does not match SizeSelect or"
01198 << " expected: "
01199 << "num sel, SizeSelect(), expected " << numSel << ","
01200 << itr2.SizeSelect() << "," << numIntSlice
01201 << endl;
01202 ok = kFALSE;
01203 }
01204
01205 if ( itr2.Size() != numUnsliced ) {
01206 MSG("Nav",Msg::kError)
01207 << "Int slice:unsliced size does not match Size(): "
01208 << "num unsliced, Size() " << numUnsliced << ","
01209 << itr2.Size() << endl;
01210 ok = kFALSE;
01211 }
01212
01213 itr2.GetSet()->ClearSlice();
01214
01215 if ( itr2.SizeSelect() != numUnsliced ) {
01216 MSG("Nav",Msg::kError)
01217 << "Int cancelled slice:does not match Size(): "
01218 << "SizeSelect(), num unsliced " << itr2.SizeSelect() << ","
01219 << numUnsliced << endl;
01220 ok = kFALSE;
01221 }
01222
01223
01224
01225
01226 itr2.GetSet()->Slice(2);
01227 if ( itr2.SizeSelect() != 1 ) {
01228 MSG("Nav",Msg::kError)
01229 << "Single arg slice does not give right set size: "
01230 << "SizeSelect() should be 1, but is " << itr2.SizeSelect()
01231 << endl;
01232 ok = kFALSE;
01233 }
01234
01235
01236
01237
01238
01239
01240 NavTestMoonItr mItr("NavTestPlanet",0);
01241 UInt_t numMoons = mItr.Size();
01242 NavTestMoonKeyFunc* pFuncM = mItr.CreateKeyFunc();
01243 pFuncM->SetFun(KeyMoon_NameSafe);
01244 mItr.GetSet()->AdoptSortKeyFunc(pFuncM);
01245 pFuncM = 0;
01246
01247
01248 itr2.ResetFirst();
01249 while ( (p = itr2.Ptr()) ) {
01250 mItr.Map(p);
01251 if ( mItr.SizeSelect() > 1 ) {
01252 NavTestMoon* m = mItr.Ptr();
01253 const Char_t* mName = m->GetName();
01254 ++mItr;
01255
01256 while ( (m = mItr.Ptr()) ) {
01257 if ( strcmp(mName,m->GetName()) >= 0 ) {
01258 MSG("Nav",Msg::kError)
01259 << "Character sort after mapping out of order. "
01260 << "Previous, current :" << mName << "," << m->GetName()
01261 << endl;
01262 ok = kFALSE;
01263 }
01264 mName = m->GetName();
01265 ++mItr;
01266 }
01267
01268 }
01269 ++itr2;
01270 }
01271
01272
01273
01274 if ( numMoons != mItr.Size() ) {
01275 MSG("Nav",Msg::kError)
01276 << "Full set size changes after mapping: before,after. "
01277 << numMoons << "," << mItr.Size() << endl;
01278 ok = kFALSE;
01279 }
01280
01281
01282
01283 pFunc = itr.CreateKeyFunc();
01284 MSG("Nav",Msg::kInfo) << "This test should fail!" << endl;
01285 if ( mItr.GetSet()->AdoptSortKeyFunc(pFunc) ) {
01286 MSG("Nav",Msg::kError)
01287 << "Moon NavSet accepted Planet NavKeyFunc " << endl;
01288 ok = kFALSE;
01289 }
01290
01291
01292
01293 mItr.Map(0);
01294 mItr.ResetFirst();
01295 pFuncM = mItr.CreateKeyFunc();
01296 pFuncM->SetFun(KeyMoon_ParentSafe);
01297 mItr.GetSet()->AdoptSortKeyFunc(pFuncM,kTRUE,kFALSE);
01298 pFuncM = mItr.CreateKeyFunc();
01299 pFuncM->SetFun(KeyMoon_NameSafe);
01300 mItr.GetSet()->AdoptSortKeyFunc(pFuncM,kFALSE,kTRUE);
01301 pFuncM = 0;
01302 NavTestMoon* oldMoon = 0;
01303 while ( mItr.IsValid() ) {
01304 NavTestMoon* moon = mItr.Ptr();
01305 if ( oldMoon ) {
01306 Int_t compParent = strcmp(oldMoon->GetParent(),moon->GetParent());
01307 if ( compParent > 0
01308 || ( compParent == 0
01309 && strcmp(oldMoon->GetName(),moon->GetName()) >= 0 ) ) {
01310 MSG("Nav",Msg::kError)
01311 << "Moon double sort out of order " << endl
01312 << " Previous: " << oldMoon->GetParent()
01313 << "," << oldMoon->GetName() << endl
01314 << " Current: " << moon->GetParent()
01315 << "," << moon->GetName() << endl;
01316 ok = kFALSE;
01317 }
01318 }
01319 oldMoon = moon;
01320 mItr.Next();
01321 }
01322
01323
01324
01325
01326 EraseTestObjects();
01327
01328 MSG("Nav",Msg::kInfo)
01329 << "Test 5: Sorting and slicing ...... ";
01330 MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01331 MSG("Nav",Msg::kInfo) << "\n";
01332
01333 if ( ok ) fNumPass++; else fNumFail++;
01334
01335 return ok;
01336
01337 }
01338
01339
01340 Bool_t NavValidate::Test_6() {
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360 Bool_t ok = kTRUE;
01361
01362
01363
01364 TCollection* tcol = MakeTCollection();
01365 UInt_t tcolSize = tcol->Capacity();
01366 NavTestPlanetItr itr(tcol);
01367
01368 const UInt_t numExpectedSel = 5;
01369 const UInt_t numExpectedSelInv = itr.GetSet()->Size() - numExpectedSel;
01370 const UInt_t numExpectedSlice = 4;
01371 const UInt_t numExpectedSelSlice = 2;
01372
01373 NavTestPlanetKeyFunc* pFunc = itr.CreateKeyFunc();
01374 pFunc->SetFun(SelPlanet);
01375
01376
01377 ++itr;
01378 ++itr;
01379 itr.GetSet()->AdoptSelectKeyFunc(pFunc);
01380 pFunc = 0;
01381
01382 UInt_t numSelFor = 0;
01383 for ( ; itr.IsValid(); ++itr ) numSelFor++;
01384 UInt_t numSelBac = 0;
01385 itr.ResetLast();
01386 for ( ; itr.IsValid(); --itr ) numSelBac++;
01387
01388 if ( numExpectedSel != numSelFor || numSelFor != numSelBac
01389 || numExpectedSel != itr.SizeSelect() ) {
01390 MSG("Nav",Msg::kError)
01391 << "Selected size not as expected. Expected,sum (for,back),"
01392 << "SizeSelect(): " << numExpectedSel << "," << numSelFor
01393 << "," << numSelBac << "," << itr.SizeSelect()
01394 << endl;
01395 ok = kFALSE;
01396 }
01397
01398
01399
01400 itr.GetSet()->InvertSelection();
01401 numSelFor = 0;
01402 for ( ; itr.IsValid(); ++itr ) numSelFor++;
01403 numSelBac = 0;
01404 itr.ResetLast();
01405 for ( ; itr.IsValid(); --itr ) numSelBac++;
01406
01407 if ( numExpectedSelInv != numSelFor || numSelFor != numSelBac
01408 || numExpectedSelInv != itr.SizeSelect() ) {
01409 MSG("Nav",Msg::kError)
01410 << "Inverted selected size not as expected:. Expected,sum (for,back),"
01411 << "SizeSelect(): " << numExpectedSelInv << "," << numSelFor
01412 << "," << numSelBac << "," << itr.SizeSelect()
01413 << endl;
01414 ok = kFALSE;
01415 }
01416 itr.GetSet()->InvertSelection(kFALSE);
01417
01418
01419
01420
01421 pFunc = itr.CreateKeyFunc();
01422 pFunc->SetFun(KeyPlanet_MassSafe);
01423 itr.GetSet()->AdoptSortKeyFunc(pFunc);
01424
01425 pFunc = 0;
01426 itr.GetSet()->Slice( 1.001,10000000.);
01427
01428
01429
01430 NavKey oldKey = itr.GetNavKey();
01431 while ( itr.IsValid() ) {
01432 NavKey key = itr.GetNavKey();
01433 if ( oldKey.CompareValue(key) > 0 ) {
01434 MSG("Nav",Msg::kError)
01435 << "Set ordering wrong. Previous key: " << oldKey.GetValue()
01436 << " currrent key: " << key.GetValue() << endl;
01437 ok = kFALSE;
01438 }
01439 oldKey = key;
01440 itr.Next();
01441 }
01442
01443 if ( numExpectedSelSlice != itr.SizeSelect() ) {
01444 MSG("Nav",Msg::kError)
01445 << "Selected/slice size not as expected: expected,"
01446 << "SizeSelect(): " << numExpectedSelSlice << ","
01447 << itr.SizeSelect() << endl;
01448 ok = kFALSE;
01449 }
01450
01451
01452
01453 itr.GetSet()->AdoptSelectKeyFunc(0);
01454 if ( numExpectedSlice != itr.SizeSelect() ) {
01455 MSG("Nav",Msg::kError)
01456 << "Slice size not as expected: expected,"
01457 << "SizeSelect(): " << numExpectedSlice << ","
01458 << itr.SizeSelect() << endl;
01459 ok = kFALSE;
01460 }
01461
01462
01463 itr.Reset();
01464 pFunc = itr.CreateKeyFunc();
01465 pFunc->SetFun(KeyPlanet_NameSafe);
01466 itr.GetSet()->AdoptSortKeyFunc(pFunc,kFALSE,kTRUE);
01467 itr.GetSet()->Slice( "N","T" );
01468 pFunc = 0;
01469 if ( itr.SizeSelect() != 2 ) {
01470 MSG("Nav",Msg::kError)
01471 << "Double slice should give 2 but gave " << itr.SizeSelect() << endl;
01472 ok = kFALSE;
01473 }
01474
01475
01476 oldKey = itr.GetNavKey();
01477 while ( itr.IsValid() ) {
01478 NavKey key = itr.GetNavKey();
01479 if ( oldKey.CompareValue(key) > 0 ) {
01480 MSG("Nav",Msg::kError)
01481 << "Set ordering wrong. Previous key: " << oldKey.GetValue()
01482 << " currrent key: " << key.GetValue() << endl;
01483 ok = kFALSE;
01484 }
01485 oldKey = key;
01486 itr.Next();
01487 }
01488
01489
01490
01491
01492 itr.GetSet()->Slice();
01493 if ( tcolSize != itr.SizeSelect() ) {
01494 MSG("Nav",Msg::kError)
01495 << "Full size not as expected: expected,"
01496 << "SizeSelect(): " << tcolSize << ","
01497 << itr.SizeSelect() << endl;
01498 ok = kFALSE;
01499 }
01500
01501
01502
01503
01504
01505 tcol->Delete();
01506 delete tcol;
01507 LEA_DTOR_NM("TList",tcol)
01508
01509
01510 MSG("Nav",Msg::kInfo)
01511 << "Test 6: Selection and multi-dim slicing ...... ";
01512 MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01513 MSG("Nav",Msg::kInfo) << "\n";
01514
01515 if ( ok ) fNumPass++; else fNumFail++;
01516
01517 return ok;
01518
01519 }
01520
01521
01522 Bool_t NavValidate::Test_7() {
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536 Bool_t ok = kTRUE;
01537
01538
01539
01540 TCollection* tcol = MakeTCollection();
01541 Int_t tcolSize = tcol->Capacity();
01542 NavTestPlanetItr itr(tcol);
01543
01544
01545
01546 Bool_t t_low = itr.Jump(-1);
01547 Bool_t t_first = itr.Jump(0);
01548 Bool_t t_last = itr.Jump(tcolSize-1);
01549 Bool_t t_hi = itr.Jump(tcolSize);
01550 if ( t_low || t_hi || ! t_first || ! t_last ) {
01551
01552
01553 MSG("Nav",Msg::kError)
01554 << "Jump before first or after last should fail but give "
01555 << Int_t(t_low) << "," << Int_t(t_hi) << endl
01556 << "Jump to first or last should suceed but give "
01557 << Int_t(t_first) << "," << Int_t(t_last) << endl;
01558 ok = kFALSE;
01559 }
01560
01561
01562 if ( strcmp( itr.JumpPtr(2)->GetName(), "Earth") ) {
01563 MSG("Nav",Msg::kError)
01564 << "Jump to position 2 should be Earth, but is "
01565 << itr.JumpPtr(2)->GetName() << endl;
01566 ok = kFALSE;
01567 }
01568
01569
01570
01571 tcol->Delete();
01572 delete tcol;
01573 LEA_DTOR_NM("TList",tcol)
01574
01575 MSG("Nav",Msg::kInfo)
01576 << "Test 7: Random Access ...... ";
01577 MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01578 MSG("Nav",Msg::kInfo) << "\n";
01579
01580 if ( ok ) fNumPass++; else fNumFail++;
01581
01582 return ok;
01583
01584 }
01585
01586
01587 Bool_t NavValidate::Test_8() {
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601 Bool_t ok = kTRUE;
01602
01603
01604
01605 PrepareTestObjects();
01606 NavTestMoonItr itr(fMoons);
01607
01608 NavTestMoonKeyFunc* pFuncM = itr.CreateKeyFunc();
01609 string lo("G");
01610 string hi("M");
01611 MoonKeyFunctor ftor(lo,hi);
01612 pFuncM->SetFun(ftor);
01613
01614 MoonKeyFunctor ftor2(lo,hi);
01615 pFuncM->SetFun(ftor2);
01616 itr.GetSet()->AdoptSelectKeyFunc(pFuncM);
01617 while ( itr.IsValid() ) {
01618 string name = itr.Ptr()->GetName();
01619 if ( lo > name || hi < name ) {
01620 MSG("Nav",Msg::kError)
01621 << " Found name: " << name << ", which is outside range: "
01622 << lo << "..." << hi << endl;
01623 ok = kFALSE;
01624 }
01625 itr.Next();
01626 }
01627
01628
01629
01630 EraseTestObjects();
01631
01632 MSG("Nav",Msg::kInfo)
01633 << "Test 8: Selection by functor ...... ";
01634 MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01635 MSG("Nav",Msg::kInfo) << "\n";
01636
01637 if ( ok ) fNumPass++; else fNumFail++;
01638
01639 return ok;
01640
01641 }
01642
01643
01644 Bool_t NavValidate::Test_9() {
01645
01646
01647
01648
01649
01650
01651
01652
01653
01654
01655
01656
01657
01658 Bool_t ok = kTRUE;
01659
01660
01661
01662 PrepareTestObjects();
01663 NavTestMoonItr itr(fMoons);
01664
01665
01666
01667
01668
01669
01670
01671
01672
01673 itr.SetSort2Fun(KeyMoon_ParentSafe,KeyMoon_NameSafe);
01674
01675 itr.ResetFirst();
01676 NavTestMoon* oldMoon = 0;
01677 Int_t numPlanets = 0;
01678 while ( itr.IsValid() ) {
01679 NavTestMoon* moon = itr.Ptr();
01680 if ( oldMoon
01681 && strcmp(oldMoon->GetParent(),moon->GetParent()) == 0) {
01682 MSG("Nav",Msg::kError)
01683 << " NextKey fails: Found name: " << oldMoon->GetParent()
01684 << " twice " << endl;
01685 ok = kFALSE;
01686 }
01687 numPlanets++;
01688 oldMoon = moon;
01689 itr.NextKey();
01690 }
01691
01692 if ( numPlanets != 6 ) {
01693 MSG("Nav",Msg::kError)
01694 << " NextKey fails: Found " << numPlanets
01695 << " distinct keys but should be 6 " << endl;
01696 ok = kFALSE;
01697 }
01698
01699
01700
01701 itr.ResetFirst();
01702 Int_t numMoons = 0;
01703 numPlanets = 0;
01704 while ( itr.IsValid() ) {
01705
01706
01707 numPlanets++;
01708
01709
01710 for ( NavTestMoonItr itr2(itr,kTRUE);
01711 itr2.IsValid();
01712 itr2.Next() ) {
01713 numMoons++;
01714 }
01715 itr.NextKey();
01716 }
01717 if ( numPlanets != 6 || numMoons != 11) {
01718 MSG("Nav",Msg::kError)
01719 << " Multi-dim itr fails: Found " << numPlanets
01720 << " planets and " << numMoons
01721 << " moons but should be 6, 11 " << endl;
01722 ok = kFALSE;
01723 }
01724
01725
01726
01727 EraseTestObjects();
01728
01729 MSG("Nav",Msg::kInfo)
01730 << "Test 9: Multi-dimensional sorting and iteration...... ";
01731 MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01732 MSG("Nav",Msg::kInfo) << "\n";
01733
01734 if ( ok ) fNumPass++; else fNumFail++;
01735
01736 return ok;
01737
01738 }
01739
01740
01741
01742 Bool_t NavValidate::Test_10() {
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752
01753
01754
01755
01756 Bool_t ok = kTRUE;
01757
01758
01759
01760 TCollection* tcol = MakeTCollection(1);
01761 NavTestMoonItr itr(tcol);
01762
01763 Mask_t reqMask = 0;
01764
01765 while ( itr.IsValid() ) {
01766 Mask_t mask = itr.GetSet()->GetMasks().GetMask(itr.Ptr());
01767 if ( mask != reqMask ) {
01768 MSG("Nav",Msg::kError)
01769 << "Found mask:" << mask
01770 << " when expecting: " << reqMask << endl;
01771 ok = kFALSE;
01772 }
01773 itr.Next();
01774 }
01775
01776 reqMask = 7;
01777 itr.ResetFirst();
01778 while ( itr.IsValid() ) {
01779 itr.GetSet()->GetMasks().SetMask(reqMask,itr.Ptr());
01780 Mask_t mask = itr.GetSet()->GetMasks().GetMask(itr.Ptr());
01781 if ( mask != reqMask ) {
01782 MSG("Nav",Msg::kError)
01783 << "Found mask:" << mask
01784 << " when expecting: " << reqMask << endl;
01785 ok = kFALSE;
01786 }
01787 itr.Next();
01788 }
01789
01790 reqMask = 9;
01791 itr.ResetFirst();
01792 itr.GetSet()->GetMasks().SetAllMasks(reqMask);
01793 while ( itr.IsValid() ) {
01794 Mask_t mask = itr.GetSet()->GetMasks().GetMask(itr.Ptr());
01795 if ( mask != reqMask ) {
01796 MSG("Nav",Msg::kError)
01797 << "Found mask:" << mask
01798 << " when expecting: " << reqMask << endl;
01799 ok = kFALSE;
01800 }
01801 itr.Next();
01802 }
01803
01804
01805
01806 tcol->Delete();
01807 delete tcol;
01808 LEA_DTOR_NM("TList",tcol)
01809
01810 MSG("Nav",Msg::kInfo)
01811 << "Test 10: Masks ...... ";
01812 MSG("Nav",Msg::kInfo) << ( ok ? "O.K." : "Failed") ;
01813 MSG("Nav",Msg::kInfo) << "\n";
01814
01815 if ( ok ) fNumPass++; else fNumFail++;
01816
01817 return ok;
01818
01819 }