ROOT logo

From $ROOTSYS/tutorials/gui/guitest_playback.C

// This macro plays a recorded ROOT session showing how to perform various
// interactive GUI operations with the guitest.C macro

// While replaying the session, several temporary macros (guitest0xx.C) 
// macros will be saved. These files will be later on compared with some 
// reference values to verify the validity of different parts of the test.

#include "TSystem.h"
#include "TSystemFile.h"
#include "TRecorder.h"
#include "Riostream.h"

// count characters in the file, skipping cr/lf
Int_t file_size(const char *filename)
{
   FILE *lunin;
   Int_t c, wc = 0;

   lunin = fopen(filename, "rb");
   if (lunin == 0) return -1;
   while (!feof(lunin)) {
      c = fgetc(lunin);
      if (c != 0x0d && c != 0x0a)
         wc++;
   }
   fclose(lunin);
   return wc;
}

// main function
void guitest_playback()
{
   Int_t i;
   Int_t guitest_ref[11], guitest_err[11], guitest_size[11];

   gBenchmark->Start("guitest_playback");

   // first delete old files, if any
   for (i=0;i<11;++i) {
      gSystem->Unlink(TString::Format("guitest%03d.C", i+1));
   }

   TRecorder r("http://root.cern.ch/files/guitest_playback.root");

   // wait for the recorder to finish the replay
   while (r.GetState() == TRecorder::kReplaying) {
      gSystem->ProcessEvents();
      gSystem->Sleep(1);
   }

   for (i=0;i<11;++i) {
      guitest_ref[i] = 0;
      guitest_err[i] = 100;
      guitest_size[i] = file_size(TString::Format("guitest%03d.C", i+1));
   }

   guitest_ref[0]  = 23319;
   guitest_ref[1]  =  5633;
   guitest_ref[2]  = 14939;
   guitest_ref[3]  =  9459;
   guitest_ref[4]  =  5351;
   guitest_ref[5]  = 22982;
   guitest_ref[6]  = 23812;
   guitest_ref[7]  = 23869;
   guitest_ref[8]  = 23918;
   guitest_ref[9]  = 24067;
   guitest_ref[10] = 65517;

   printf("**********************************************************************\n");
   printf("*  Results of guitest_playback.C                                     *\n");
   printf("**********************************************************************\n");

   for (i=0;i<11;++i) {
      printf("guitest %02d: output............................................", i+1);
      if (TMath::Abs(guitest_ref[i] - guitest_size[i]) <= guitest_err[i]) {
         printf("..... OK\n");
         // delete successful tests, keep only the failing ones (for verification)
         gSystem->Unlink(TString::Format("guitest%03d.C", i+1));
      }
      else {
         printf(". FAILED\n");
      }
   }
   printf("**********************************************************************\n");
   gBenchmark->Show("guitest_playback");
}
 guitest_playback.C:1
 guitest_playback.C:2
 guitest_playback.C:3
 guitest_playback.C:4
 guitest_playback.C:5
 guitest_playback.C:6
 guitest_playback.C:7
 guitest_playback.C:8
 guitest_playback.C:9
 guitest_playback.C:10
 guitest_playback.C:11
 guitest_playback.C:12
 guitest_playback.C:13
 guitest_playback.C:14
 guitest_playback.C:15
 guitest_playback.C:16
 guitest_playback.C:17
 guitest_playback.C:18
 guitest_playback.C:19
 guitest_playback.C:20
 guitest_playback.C:21
 guitest_playback.C:22
 guitest_playback.C:23
 guitest_playback.C:24
 guitest_playback.C:25
 guitest_playback.C:26
 guitest_playback.C:27
 guitest_playback.C:28
 guitest_playback.C:29
 guitest_playback.C:30
 guitest_playback.C:31
 guitest_playback.C:32
 guitest_playback.C:33
 guitest_playback.C:34
 guitest_playback.C:35
 guitest_playback.C:36
 guitest_playback.C:37
 guitest_playback.C:38
 guitest_playback.C:39
 guitest_playback.C:40
 guitest_playback.C:41
 guitest_playback.C:42
 guitest_playback.C:43
 guitest_playback.C:44
 guitest_playback.C:45
 guitest_playback.C:46
 guitest_playback.C:47
 guitest_playback.C:48
 guitest_playback.C:49
 guitest_playback.C:50
 guitest_playback.C:51
 guitest_playback.C:52
 guitest_playback.C:53
 guitest_playback.C:54
 guitest_playback.C:55
 guitest_playback.C:56
 guitest_playback.C:57
 guitest_playback.C:58
 guitest_playback.C:59
 guitest_playback.C:60
 guitest_playback.C:61
 guitest_playback.C:62
 guitest_playback.C:63
 guitest_playback.C:64
 guitest_playback.C:65
 guitest_playback.C:66
 guitest_playback.C:67
 guitest_playback.C:68
 guitest_playback.C:69
 guitest_playback.C:70
 guitest_playback.C:71
 guitest_playback.C:72
 guitest_playback.C:73
 guitest_playback.C:74
 guitest_playback.C:75
 guitest_playback.C:76
 guitest_playback.C:77
 guitest_playback.C:78
 guitest_playback.C:79
 guitest_playback.C:80
 guitest_playback.C:81
 guitest_playback.C:82
 guitest_playback.C:83
 guitest_playback.C:84
 guitest_playback.C:85
 guitest_playback.C:86
 guitest_playback.C:87