proj home

Files   Classes   Functions   Hierarchy  

modulereport.cpp

Go to the documentation of this file.
00001 #include <cassert>
00002 #include <iostream>
00003 using namespace std;
00004 
00005 #include <modulereport.h>
00006 #include <mkerrors.h>
00007 #include <projunittests.h>
00008 #include <stringconvert.h>
00009 #include <stringserialization.h>
00010 #include <tokenizerlocal.h>
00011 
00012 /*
00013 Module status:
00014 
00015  Fail if no files.
00016 
00017  Fail if no compilation file.
00018 
00019  amber if compiled but no unit tests or unit test failed.
00020 
00021  Success if compiled and passed unit tests.
00022 
00023 */
00024 
00025 string modulereport::fileout_html="modulereport.html";
00026 
00027 int modulereport::update01()
00028 {
00029   reset();
00030   statecalc();
00031 
00032   string s1="\n";
00033   s1 += "<h1>Module Report";
00034   s1 += htmlimg("../"); 
00035   s1 += "</h1>\n";
00036 
00037 // Spec
00038 // Module Status  Failure
00039 // Compilation Status  Success
00040 // Unit Tests  Failure
00041 
00042   s1 += "Module Status &nbsp; ";
00043   s1 += (statestring() + "<br />");
00044   
00045   s1 += "Compilation Status &nbsp; ";
00046   s1 += (exitint( compile_exitstatus() ).isvalidtext() + "<br />");
00047 
00048 
00049   s1 += "Unit Tests &nbsp; ";
00050   s1 += (exitint( unittests_exitstatus() ).isvalidtext() + "<br />");
00051 
00052 
00053   string s2 = stringtag(s1,"body");
00054   string s3 = stringtag(s2,"html");
00055 
00056   filestring::serializeInverse(fileout_html,s3);
00057 
00058   return 0;
00059 }
00060 
00061 boolc modulereport::reset()
00062 {
00063   bool res=true;
00064 
00065   ureport.seq.clear();
00066   string unittestsreport;
00067   string file1=filepathfront+projunittests::fileresults;
00068   if (!filestring::serialize(unittestsreport,file1))
00069   {
00070     res=false;
00071 
00072     if (!errorssilent)
00073       cout << "error:  could not read file " << file1 << endl;
00074   }
00075   ureport.read(unittestsreport);
00076   
00077   creport.seq.clear();
00078   string compilationreport;
00079   string file2=filepathfront+mkerrorscompile::fileout_txt;
00080   if (!filestring::serialize(compilationreport,file2))
00081   {
00082     res=false;
00083 
00084     if (!errorssilent)
00085       cout << "error:  could not read file " << file2 << endl;
00086   }
00087   creport.read(compilationreport);
00088 
00089   return res;
00090 }
00091 
00092 modulereport::modulereport()
00093   : errorssilent(false)
00094 {
00095 }
00096 
00097 stringc modulestate::statecolor() const
00098 {
00099   string str;
00100   switch(state)
00101   {
00102     case red: str="red"; break; 
00103     case amber: str="amber"; break; 
00104     case green: str="green"; break; 
00105   }
00106 
00107   return str;
00108 }
00109 
00110 stringc modulestate::statestring() const
00111 {
00112   string str;
00113   switch(state)
00114   {
00115     case red: str="Fail"; break; 
00116     case amber: str="Compiled"; break; 
00117     case green: str="Success"; break; 
00118   }
00119 
00120   return str;
00121 }
00122 
00123 int modulereport::unittests_exitstatus()
00124 {
00125   tokenizerlocal tkl(ureport);
00126   string s1;
00127   ureport.reset();
00128 
00129   int exitstatus=1;
00130   if (tkl.read(s1,"status","exitstatus")==false)
00131     return exitstatus;
00132 
00133   stringfrom(exitstatus,s1);
00134 
00135   return exitstatus;
00136 }
00137 
00138 int modulereport::compile_exitstatus()
00139 {
00140   tokenizerlocal tkl(creport);
00141   string s1;
00142   creport.reset();
00143   bool res=true;
00144   res &= tkl.read(s1,"exitstatus");
00145 //cout << SHOW(res) << " " << SHOW(s1) << endl;
00146 
00147   int exitstatus=1;
00148   stringfrom(exitstatus,s1);
00149 
00150   return exitstatus;
00151 }
00152 
00153 void modulereport::statecalc()
00154 {
00155   int compilestatus=compile_exitstatus();
00156   int unittestsstatus=unittests_exitstatus();
00157 
00158   state=red;
00159 
00160   if ((compilestatus==0)&&(unittestsstatus==0))
00161     state=green;
00162   if ((compilestatus==0)&&(unittestsstatus!=0))
00163     state=amber;
00164 }
00165 
00166 stringc modulestate::htmlimg(stringc& pathfront) const
00167 {
00168   switch(state)
00169   {
00170     case green: return (" <img src=\""+pathfront+"documentation/images/success.gif\" alt=\""+pathfront+"documentation/images/success.gif\" />");
00171     case amber: return " <img src=\""+pathfront+"documentation/images/risk.gif\" alt=\""+pathfront+"documentation/images/risk.gif\" />";
00172     case red: return "<img src=\""+pathfront+"documentation/images/attention.png\" alt=\""+pathfront+"documentation/images/attention.png\" />";
00173   }
00174 
00175   return "";
00176 }
00177 
00178 modulestate::modulestate()
00179   : state(red)
00180 {
00181 }
00182 
00183 stringc modulereport::compilerhtmldetailed()
00184 {
00185 // id: 
00186 // compilertag id
00187 // command:
00188 // compilertag command
00189 // libraries: 
00190 // compilertag libraries
00191 
00192 // time: time
00193 
00194 // head
00195 // output in <pre> tags.
00196 
00197   tokenizerlocal tkl(creport);
00198   string s1;
00199   string s0; 
00200 
00201   //tkl.reset_start=true;
00202 
00203   //s0 += "<h2>Compilation</h2>\n";
00204 
00205   s0 += "<p>\n";
00206 
00207   tkl.reset();
00208   if (tkl.read(s1,"compiletag","id"))
00209     s0 += ("id: " + s1 + "<br />\n");
00210 /*
00211   {
00212     s0 += ("id: " + s1 + "<br />");
00213   }
00214 */
00215 
00216 /*
00217   tkl.reset();
00218   bool res=tkl.read(s1,"compiletag","command");
00219 cout << SHOW(res) << endl;
00220 tkl.ref.printdelimiter="*\n";
00221 cout << tkl.ref << endl;
00222 */
00223 /*
00224   if (tkl.read(s1,"compiletag","command"))
00225   {
00226     s0 += ("command: " + s1 + "<br />");
00227   }
00228 */
00229 
00230   tkl.reset();
00231   if (tkl.read(s1,"compiletag","command"))
00232     s0 += ("command: " + s1 + "<br />\n");
00233 
00234   tkl.reset();
00235   if (tkl.read(s1,"compiletag","libraries"))
00236     s0 += ("libraries: " + s1 + "<br />\n");
00237 
00238   tkl.reset();
00239   if (tkl.read(s1,"time"))
00240     s0 += ("time: " + s1 + "\n</p>\n");
00241 
00242   tkl.reset();
00243   if (tkl.read(s1,"head"))
00244   {
00245     string s2;
00246     htmlstring::serializeInverse(s2,s1);
00247     s0 += stringtag(s2,"pre");
00248   }
00249 
00250   s0 += "\n";
00251 
00252   return s0;
00253 }
00254 
00255 // vi
00256 // unittest
00257 //    exitstatus
00258 //    file
00259 //    commandlines
00260 //      cmd 
00261 //        exitstatus
00262 //        line
00263 //        output
00264 //      cmd ...
00265 //  unittest ...
00266 
00267 // scope vi, iterate over unittest
00268 // 
00269 
00270 stringc modulereport::unittestshtmldetailed()
00271 {
00272   string s0;
00273 //  string s0="<h2>Unit tests</h2>";
00274 //cout << "modulereport::unittestshtmldetailed()" << endl;
00275 
00276   string exitstatus;
00277   string file;
00278 
00279   tokenizerlocal tl1(ureport);
00280   tl1.boundscope("vi");
00281 
00282   string s1;
00283 
00284   tokenizerlocal tl2(tl1);
00285   for ( ; tl2.scope("unittest"); ++tl2)
00286   {
00287     tokenizerlocal tl3(tl2);
00288     if (tl3.read(exitstatus,"exitstatus")==false)
00289       continue;
00290 // cout << SHOW3(exitstatus) << endl;
00291     if (tl3.read(file,"file")==false)
00292       continue;
00293 // cout << SHOW3(file) << endl;
00294 
00295     s1 += ("<p>exitstatus: "+exitstatus);
00296     s1 += "<br />";
00297     s1 += ("file: " + file);
00298     s1 += "</p>";
00299    
00300     s0 += s1;
00301 
00302     s1.clear();
00303 
00304     if (tl3.scope("commandlines")==false)
00305       continue;
00306 
00307     tokenizerlocal tl4(tl3);
00308     for ( ; tl4.scope("cmd"); ++tl4)
00309     {
00310       tokenizerlocal tl5(tl4);
00311       string exitstatus;
00312       if (tl5.read(exitstatus,"exitstatus")==false)
00313         continue;
00314       string line;
00315       if (tl5.read(line,"line")==false)
00316         continue;
00317       string output;
00318       if (tl5.read(output,"output")==false)
00319         continue;
00320 
00321       //cout << SHOW3(exitstatus) << endl;
00322       //cout << SHOW3(line) << endl;
00323       //cout << SHOW3(output) << endl;
00324 
00325       s1 += ("<p>exitstatus: " + exitstatus);
00326       s1 += "<br />";
00327       s1 += ("line: " + line);
00328       s1 += "</p>\n";
00329       {
00330         string output2;
00331         htmlstring::serializeInverse(output2,output);
00332         s1 += (stringtag(output2,"pre")+"\n");
00333       }
00334       //s1 += ("<pre>"+output+"</pre>\n");
00335     }
00336 //    s1 += "</p>";
00337 
00338     s0 += s1;
00339   }
00340 
00341 //cout << SHOW3(exitstatus) << endl;
00342   
00343   return s0;
00344 }
00345 
00346 /*
00347 stringc modulereport::unittestshtmldetailed()
00348 {
00349   string s0;
00350 cout << "modulereport::unittestshtmldetailed()" << endl;
00351 
00352   string exitstatus;
00353   string file;
00354 
00355   tokenizerlocal tkl1(ureport);
00356   tokenizerlocal tkl2(ureport);
00357 
00358   tkl1.scope("unittestsreport");
00359 
00360   for ( tkl1.reset(); tkl1.scope("unittest"); ++tkl1)
00361   {
00362     if (tkl2.read(exitstatus,"exitstatus")==false)
00363       continue;
00364 //cout << SHOW3(exitstatus) << endl;
00365     if (tkl2.read(file,"file")==false)
00366       continue;
00367 cout << SHOW3(file) << endl;
00368 
00369 */
00370 
00371 stringc modulereport::summary01()
00372 {
00373   string s1;
00374   s1 += "<p>Module Status &nbsp; ";
00375   s1 += (statestring() + "<br />");
00376   
00377   s1 += "Compilation Status &nbsp; ";
00378   s1 += (exitint( compile_exitstatus() ).isvalidtext() + "<br />");
00379 
00380   s1 += "Unit Tests &nbsp; ";
00381   s1 += (exitint( unittests_exitstatus() ).isvalidtext() );
00382 
00383   s1 += "</p>";
00384 
00385   return s1;
00386 }
00387 
00388 int modulereport::update()
00389 {
00390   reset();
00391   statecalc();
00392 
00393   string s1="\n";
00394   s1 += "<h1>Module Report";
00395   s1 += htmlimg("../"); 
00396   s1 += "</h1>\n";
00397 
00398   s1 += (summary01()+"\n");
00399 
00400   s1 += "<h2>Compilation</h2>\n";
00401   s1 += compilerhtmldetailed();
00402   s1 += "<h2>Unit tests</h2>\n";
00403   s1 += unittestshtmldetailed();
00404 
00405   string s2 = stringtag(s1,"body");
00406   string s3 = stringtag(s2,"html");
00407 
00408   
00409   filestring::serializeInverse(fileout_html,s3);
00410 
00411   return 0;
00412 }
00413 
00414 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8