RegistryValidate Class Reference

#include <RegistryValidate.h>

List of all members.

Public Member Functions

 RegistryValidate ()
 ~RegistryValidate ()
bool RunAllTests (void)

Private Member Functions

bool FillRegistry (Registry &r)
bool AddToRegistry (Registry &r)
bool DumpRegistry (Registry &r)
bool WriteRegistry (Registry &r)
bool ReadWriteTest ()
RegistryReadRegistry (int method)
bool TypePromotionTest ()

Private Attributes

const char * fFileName
const char * fRegName
TFile * fFile

Detailed Description

Definition at line 24 of file RegistryValidate.h.


Constructor & Destructor Documentation

RegistryValidate::RegistryValidate ( void   ) 

Definition at line 43 of file RegistryValidate.cxx.

00043                                        :
00044     fFileName("/tmp/registry-validation-test.root"),
00045     fRegName("Test validation registry"),
00046     fFile(0)
00047 {
00048 
00049 }
RegistryValidate::~RegistryValidate(void) 

RegistryValidate::~RegistryValidate ( void   ) 

Definition at line 50 of file RegistryValidate.cxx.

00051 {
00052 
00053 }


Member Function Documentation

bool RegistryValidate::AddToRegistry ( Registry r  )  [private]

Definition at line 73 of file RegistryValidate.cxx.

References Registry::Set().

Referenced by RunAllTests().

00074 {
00075     double d = 96.96;
00076     int i = 6996;
00077     char c = 'x';
00078     const char* s = "Lhab Lhab Lhab!";
00079 //    bool b = false;
00080 
00081     if (!r.Set("my other double", d))  return false;
00082     if (!r.Set("my other integer", i)) return false;
00083     if (!r.Set("my other char", c))    return false;
00084 //    if (!r.Set("my other bool", b))    return false;
00085     if (!r.Set("my other string", s))  return false;
00086 
00087     return true;
00088 }

bool RegistryValidate::DumpRegistry ( Registry r  )  [private]

Definition at line 100 of file RegistryValidate.cxx.

References dump_keys(), MuELoss::e, Registry::Get(), Registry::Print(), and Registry::Set().

Referenced by RunAllTests().

00101 {
00102     dump_keys(r);
00103 
00104     cerr << "Dumping registry named: \"" << r.GetName() << "\"\n";
00105 
00106     double d = 0;
00107     if (r.Get("my double",d)) 
00108         cerr << "my double is; `" << d << "'\n";
00109     else
00110         cerr << "Failed to Get `my double'\n";
00111     if (r.Get("my other double",d)) 
00112         cerr << "my other double is; `" << d << "'\n";
00113     else
00114         cerr << "Failed to Get `my other double'\n";
00115 
00116     int i = 0;
00117     if (r.Get("my integer",i))
00118         cerr << "my integer is; `" << i << "'\n";
00119     else
00120         cerr << "Failed to Get `my integer'\n";
00121     if (r.Get("my other integer",i))
00122         cerr << "my other integer is; `" << i << "'\n";
00123     else
00124         cerr << "Failed to Get `my other integer'\n";
00125     
00126     char c = 0;
00127     if (r.Get("my char",c))
00128         cerr << "my char is; `" << c << "'\n";
00129     else
00130         cerr << "Failed to Get `my char'\n";
00131     if (r.Get("my other char",c))
00132         cerr << "my other char is; `" << c << "'\n";
00133     else
00134         cerr << "Failed to Get `my other char'\n";
00135 
00136 #if 0
00137     bool b = 0;
00138     if (r.Get("my bool",b))
00139         cerr << "my bool is; `" << b << "'\n";
00140     else
00141         cerr << "Failed to Get `my bool'\n";
00142     if (r.Get("my other bool",b))
00143         cerr << "my other bool is; `" << b << "'\n";
00144     else
00145         cerr << "Failed to Get `my other bool'\n";
00146 #endif
00147     const char* cptr = 0;
00148     if (r.Get("my string", cptr)) 
00149         cerr << "my string is; `" << cptr << "'\n";
00150     else
00151         cerr << "Failed to Get `my string'\n";
00152     if (r.Get("my other string", cptr)) 
00153         cerr << "my other string is; `" << cptr << "'\n";
00154     else
00155         cerr << "Failed to Get `my other string'\n";
00156 
00157     cerr << "**** dump complete ****\n";
00158 
00159     cerr << "*** Printing registry ****\n";
00160     r.Set("small",19.*1.e-9);
00161     r.Print();
00162 
00163     return true;
00164 }

bool RegistryValidate::FillRegistry ( Registry r  )  [private]

Definition at line 55 of file RegistryValidate.cxx.

References Registry::Set().

Referenced by ReadWriteTest(), and RunAllTests().

00056 {
00057     double d = 6.9;
00058     int i = 69;
00059     char c = 'c';
00060     const char* s = "Blah blah blah!";
00061 //    bool b = true;
00062 
00063     if (!r.Set("my double", d))  return false;
00064     if (!r.Set("my integer", i)) return false;
00065     if (!r.Set("my char", c))    return false;
00066 //    if (!r.Set("my bool", b))    return false;
00067     if (!r.Set("my string", s))  return false;
00068 
00069     r.SetName("My Cool Registry!!!!!");
00070     return true;
00071 }

Registry * RegistryValidate::ReadRegistry ( int  method  )  [private]

Definition at line 193 of file RegistryValidate.cxx.

References fFile, fFileName, and fRegName.

Referenced by RunAllTests().

00194 {
00195     if (fFile) fFile->Close();
00196     fFile = new TFile(fFileName,"READ");
00197     if (! fFile->IsOpen()) {
00198         cerr << "Could not open `" << fFileName << "' for reading\n";
00199         return 0;
00200     }
00201     
00202     fFile->ls();
00203 
00204     Registry* r;
00205     switch (method) {
00206     case 1:
00207         r = dynamic_cast<Registry*>(fFile->Get(fRegName));
00208         break;
00209     case 2:
00210         r = new Registry;
00211         r->Read(fRegName);
00212         break;
00213     default:
00214         cerr << "Unknown read method: `" << method << "'\n";
00215         return 0;
00216     }
00217 
00218     return r;
00219 }

bool RegistryValidate::ReadWriteTest (  )  [private]

Definition at line 222 of file RegistryValidate.cxx.

References FillRegistry(), Registry::PrintStream(), Registry::ReadStream(), Registry::Set(), and Registry::Size().

Referenced by RunAllTests().

00223 {
00224     Registry r1,r2;
00225     r1.Set("aaa number",111111);
00226     this->FillRegistry(r1);
00227     this->FillRegistry(r2);
00228     r2.SetName("My Cool Sub-Registry");
00229     r1.Set("the sub registry",r2);
00230     r1.Set("zzz number",999999);
00231     
00232     const char* tmpfile = "registry-test.txt";
00233     ofstream ofstr(tmpfile);
00234     if (!ofstr) return false;
00235 
00236     cerr << "ReadWriteTest using " << tmpfile << endl;
00237     cerr << "writing: " << r1.Size() << " entries:\n";
00238     cerr << r1 << endl;
00239     r1.PrintStream(ofstr);
00240     ofstr.close();
00241 
00242     Registry r3;
00243 
00244     ifstream ifstr(tmpfile);
00245     if (!ifstr) return false;
00246     r3.ReadStream(ifstr);
00247     ifstr.close();
00248 
00249     cerr << "read: " << r3.Size() << " entries:\n";
00250     cerr << r3 << endl;
00251 
00252     return r1.Size() == r2.Size();
00253 }

bool RegistryValidate::RunAllTests ( void   ) 

Definition at line 272 of file RegistryValidate.cxx.

References AddToRegistry(), Registry::Clear(), dump_keys(), DumpRegistry(), error_handler(), fFileName, FillRegistry(), Registry::Get(), Registry::GetCharString(), Registry::GetDouble(), Registry::GetInt(), Registry::GetRegistry(), Registry::KeyExists(), Registry::LockKeys(), Registry::LockValues(), Registry::Merge(), n, ReadRegistry(), ReadWriteTest(), Registry::RemoveKey(), Registry::Set(), Registry::SetErrorHandler(), Registry::Size(), TypePromotionTest(), Registry::UnLockKeys(), Registry::UnLockValues(), and WriteRegistry().

Referenced by main().

00273 {
00274     Registry r;
00275 
00276     cerr << "*** Filling Registry...\n";
00277     if (!FillRegistry(r)) return false;
00278 
00279     cerr << "*** Re-filling Registry with ValuesLocked == true...\n";
00280     r.LockValues();
00281     if (FillRegistry(r)) return false;
00282     cerr << "*** Re-filling Registry with ValuesLocked == false...\n";
00283     r.UnLockValues();
00284     if (!FillRegistry(r)) return false;
00285 
00286     cerr << "*** Adding to Registry with KeysLocked == true...\n";
00287     r.LockKeys();
00288     if (AddToRegistry(r)) return false;
00289     cerr << "*** Adding to Registry with KeysLocked == false...\n";
00290     r.UnLockKeys();
00291     if (!AddToRegistry(r)) return false;
00292 
00293     cerr << "*** Dumping Registry...\n";
00294     if (!DumpRegistry(r)) return false;
00295 
00296     cerr << "*** Writing Registry to `" << fFileName << "'...\n";
00297     if (!WriteRegistry(r)) return false;
00298 
00299     for (int n=1; n<=2; ++n) {
00300 
00301         cerr << "*** Reading Registry from `" << fFileName 
00302              << "', with method " << n <<" ...\n";
00303         Registry* rptr = ReadRegistry(n);
00304         if (!rptr) return false;
00305 
00306         cerr << "*** Dumping Registry...\n";
00307         if (!DumpRegistry(*rptr)) return false;
00308 
00309         cerr << "*** Destroying read-in Registry in heap...\n";
00310         delete rptr;
00311 
00312         cerr << "*** Done.\n\n";
00313 
00314     }
00315 
00316     cerr << "*** Test copy constructor...\n";
00317     Registry r2(r);
00318     int i1, i2;
00319     if (!r.Get("my integer",i1)) return false;
00320     if (!r2.Get("my integer",i2)) return false;
00321     cerr << "    `my integer' = `" << i1 << "' and `" << i2 << "'\n";
00322     if (i1 != i2) return false;
00323     cerr << "    sizes of orig and copy are: `" 
00324          << r.Size() << "' and `"
00325          << r2.Size() << "'\n";
00326     if (r.Size() != r2.Size()) return false;
00327     cerr << "*** Done\n\n";
00328 
00329     cerr << "*** Test assignment...\n";
00330     Registry r3;
00331     r3 = r;
00332     if (!r.Get("my integer",i1)) return false;
00333     if (!r3.Get("my integer",i2)) return false;
00334     cerr << "    `my integer' = `" << i1 << "' and `" << i2 << "'\n";
00335     if (i1 != i2) return false;
00336     cerr << "    sizes of orig and copy are: `" 
00337          << r.Size() << "' and `"
00338          << r3.Size() << "'\n";
00339     if (r.Size() != r3.Size()) return false;
00340     cerr << "*** Done\n\n";
00341 
00342     cerr << "*** Test overwriting asignment...\n";
00343     Registry r4, r5;
00344     FillRegistry(r4);
00345     AddToRegistry(r5);
00346     if (!r4.Get("my integer",i1)) return false;
00347     if (!r5.Get("my other integer",i2)) return false;;
00348     cerr << "    `my integer' = `" << i1 
00349          << "' and `my other integer' = `" << i2 << "'\n";
00350     cerr << "    sizes of r4 = `" << r4.Size() 
00351          << "' and size of r5 is: `" << r5.Size() << "'\n";
00352 
00353     r4 = r5;
00354 
00355     if (!r4.Get("my other integer",i1)) return false;
00356     if (!r5.Get("my other integer",i2)) return false;
00357     cerr << "    `my integer' = `" << i1 
00358          << "' and `my other integer' = `" << i2 << "'\n";
00359     cerr << "    sizes of r4 = `" << r4.Size() 
00360          << "' and size of r5 is: `" << r5.Size() << "'\n";
00361     if (i1 != i2) return false;
00362     cerr << "*** Done\n\n";
00363 
00364     cerr << "*** Test clearing while locked...\n";
00365     dump_keys(r5);
00366     i1 = r5.Size();
00367     r5.Clear();
00368     dump_keys(r5);
00369     i2 = r5.Size();
00370     if (!i2) return false;
00371     cerr << "*** Done\n\n";
00372 
00373     cerr << "*** Test clearing while unlocked...\n";
00374     r5.UnLockKeys();
00375     r5.UnLockValues();
00376     r5.Clear();
00377     dump_keys(r5);
00378     i2 = r5.Size();
00379     if (i2) return false;
00380     cerr << "*** Done\n\n";
00381 
00382 
00383     cerr << "*** Test checking for keys...\n";
00384     if (r5.KeyExists("booger")) 
00385         cerr << "  there is a key called `booger'\n";
00386     else 
00387         cerr << "  there is no key called `booger'\n";
00388     if (r5.KeyExists("my integer")) 
00389         cerr << "  there is a key called `my integer'\n";
00390     else 
00391         cerr << "  there is no key called `my integer'\n";
00392     cerr << "*** Done\n\n";
00393 
00394 
00395     cerr << "*** Test error handling...\n";
00396     r.SetErrorHandler(&error_handler);
00397     cerr << "  GetInt(\"booger\") = " << r.GetInt("booger") << endl;
00398     cerr << "*** Done\n\n";
00399 
00400 
00401     cerr << "*** Test GetType interface...\n";
00402     cerr << " my double: " << r.GetDouble("my double") << endl;
00403     cerr << " my string: " << r.GetCharString("my string") << endl;
00404     cerr << "*** Done\n\n";
00405 
00406     cerr << "*** Recursive test.  Adding r4 to r5...\n";
00407     cerr << " r4: " << r4 << endl;
00408     r5.Set("my registry",r4);
00409     Registry r6 = r5.GetRegistry("my registry");
00410     cerr << " my registry: " << r6 << endl;
00411     cerr << endl << "Printing recursive Registry:\n";
00412     cerr << r5 << endl;
00413 
00414     cerr << "*** Merge test...\n";
00415     Registry r7, r8;
00416     r7.Set("one",1);
00417     r7.SetName("one");
00418 //    r8.Set("one",1.0);
00419     r8.Set("two",2);
00420     r8.SetName("two");
00421     cerr << r7 << endl;
00422     cerr << r8 << endl;
00423     cerr << "Now merge two into one...\n";
00424     r7.Merge(r8);
00425     cerr << r7 << endl;
00426 
00427     cerr << "Removing \"one\" from merged registry 'one'\n";
00428     r7.RemoveKey("one");
00429     cerr << r7 << endl;
00430 
00431     cerr << "Unlocking andn resetting value for key 'two' of differeing type in registry 'two'\n";
00432     r8.UnLockValues();
00433     r8.Set("two",3.0);
00434 
00435 
00436     this->ReadWriteTest();
00437 
00438     this->TypePromotionTest();
00439     return true;
00440 }

bool RegistryValidate::TypePromotionTest (  )  [private]

Definition at line 256 of file RegistryValidate.cxx.

References Registry::Get(), and Registry::Set().

Referenced by RunAllTests().

00257 {
00258     Registry r;
00259 
00260     int x = 42;
00261     cerr << "Set as int = " << x << "\n";
00262     r.Set("x",x);
00263     double y;
00264     bool tf = r.Get("x",y);
00265     if (tf) 
00266         cerr << "succeeded to Get() as double = " << y << "\n";
00267     else
00268         cerr << "failed to Get() as double\n";
00269     return tf;
00270 }

bool RegistryValidate::WriteRegistry ( Registry r  )  [private]

Definition at line 166 of file RegistryValidate.cxx.

References fFile, fFileName, and fRegName.

Referenced by RunAllTests().

00167 {
00168     if (fFile) fFile->Close();
00169     fFile = new TFile(fFileName,"RECREATE");
00170     fFile->SetCompressionLevel(0);
00171     if (! fFile->IsOpen()) {
00172         cerr << "Could not open `" << fFileName << "' for writing\n";
00173         return false;
00174     }
00175     if (!r.Write(fRegName)) {
00176         cerr << "Could not write registry object\n";
00177         return false;
00178     }
00179 // I think TObject::Write() actualy writes to file so this would be
00180 // redundant.
00181 #if 0
00182     if (!fFile->Write()) {
00183         cerr << "Could not write registry file\n";
00184         return false;
00185     }
00186 #endif
00187     fFile->Close();
00188     fFile = 0;
00189 
00190     return true;
00191 }


Member Data Documentation

TFile* RegistryValidate::fFile [private]

Definition at line 48 of file RegistryValidate.h.

Referenced by ReadRegistry(), and WriteRegistry().

const char* RegistryValidate::fFileName [private]

Definition at line 46 of file RegistryValidate.h.

Referenced by ReadRegistry(), RunAllTests(), and WriteRegistry().

const char* RegistryValidate::fRegName [private]

Definition at line 47 of file RegistryValidate.h.

Referenced by ReadRegistry(), and WriteRegistry().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1