guitest_playback.C

Go to the documentation of this file.
00001 // This macro plays a recorded ROOT session showing how to perform various
00002 // interactive GUI operations with the guitest.C macro
00003 
00004 // While replaying the session, several temporary macros (guitest0xx.C) 
00005 // macros will be saved. These files will be later on compared with some 
00006 // reference values to verify the validity of different parts of the test.
00007 
00008 #include "TSystem.h"
00009 #include "TSystemFile.h"
00010 #include "TRecorder.h"
00011 #include "Riostream.h"
00012 
00013 // count characters in the file, skipping cr/lf
00014 Int_t file_size(const char *filename)
00015 {
00016    FILE *lunin;
00017    Int_t c, wc = 0;
00018 
00019    lunin = fopen(filename, "rb");
00020    if (lunin == 0) return -1;
00021    while (!feof(lunin)) {
00022       c = fgetc(lunin);
00023       if (c != 0x0d && c != 0x0a)
00024          wc++;
00025    }
00026    fclose(lunin);
00027    return wc;
00028 }
00029 
00030 // main function
00031 void guitest_playback()
00032 {
00033    Int_t i;
00034    Int_t guitest_ref[11], guitest_err[11], guitest_size[11];
00035 
00036    gBenchmark->Start("guitest_playback");
00037 
00038    // first delete old files, if any
00039    for (i=0;i<11;++i) {
00040       gSystem->Unlink(TString::Format("guitest%03d.C", i+1));
00041    }
00042 
00043    TRecorder r("http://root.cern.ch/files/guitest_playback.root");
00044 
00045    // wait for the recorder to finish the replay
00046    while (r.GetState() == TRecorder::kReplaying) {
00047       gSystem->ProcessEvents();
00048       gSystem->Sleep(1);
00049    }
00050 
00051    for (i=0;i<11;++i) {
00052       guitest_ref[i] = 0;
00053       guitest_err[i] = 100;
00054       guitest_size[i] = file_size(TString::Format("guitest%03d.C", i+1));
00055    }
00056 
00057    guitest_ref[0]  = 23319;
00058    guitest_ref[1]  =  5633;
00059    guitest_ref[2]  = 14939;
00060    guitest_ref[3]  =  9459;
00061    guitest_ref[4]  =  5351;
00062    guitest_ref[5]  = 22982;
00063    guitest_ref[6]  = 23812;
00064    guitest_ref[7]  = 23869;
00065    guitest_ref[8]  = 23918;
00066    guitest_ref[9]  = 24067;
00067    guitest_ref[10] = 65517;
00068 
00069    printf("**********************************************************************\n");
00070    printf("*  Results of guitest_playback.C                                     *\n");
00071    printf("**********************************************************************\n");
00072 
00073    for (i=0;i<11;++i) {
00074       printf("guitest %02d: output............................................", i+1);
00075       if (TMath::Abs(guitest_ref[i] - guitest_size[i]) <= guitest_err[i]) {
00076          printf("..... OK\n");
00077          // delete successful tests, keep only the failing ones (for verification)
00078          gSystem->Unlink(TString::Format("guitest%03d.C", i+1));
00079       }
00080       else {
00081          printf(". FAILED\n");
00082       }
00083    }
00084    printf("**********************************************************************\n");
00085    gBenchmark->Show("guitest_playback");
00086 }

Generated on Tue Jul 5 15:44:25 2011 for ROOT_528-00b_version by  doxygen 1.5.1