Project

General

Profile

C++TESK Cookbook » History » Revision 3

Revision 2 (Alexander Kamkin, 08/01/2013 11:06 AM) → Revision 3/5 (Alexander Kamkin, 08/01/2013 01:39 PM)

h1. C++TESK Cookbook 

 h2. Developing a Report Printer 

 If you want to change the way the tool describes failures (you don’t like the printing style or you get used to work with a different format or you need to integrate your test system with a bug tracker or whatever), the best solution is probably to write your own report printer. It can be easily done by defining one method in a printer class and registering the printer in C++TESK Report Subsystem. The steps are as follows. 

 h4. Step 1. Printer Definition 

 <pre><code class="cpp"> 
 #include <hw/report/printer.hpp> 

 using namespace cpptesk::hw::report; 

 // You need to inherit from the base printer 
 structure MyPrinter: public ReportPrinter 
 { 
     // ... and to define (override) the print method. 
     virtual void print(std::ostream &out, const Report &report) { ... } 
 }; 
 </code></pre> 

 h4. Step 2. Printer Registration 

 <pre><code class="cpp"> 
 // If the printer is ready, it may be registered. 
 CPPTESK_MODEL(MyModel) 
 { 
     MyModel() 
     { 
         // Printers are registered in a model. 
         registerReportPrinter(new MyPrinter()); 
         ... 
     } 
 }; 
 </code></pre> 

 h4. Example. Simple Console Printer 

 <pre><code class="cpp"> 
 void MyPrinter::print(std::ostream &out, const Report &report) 
 { 
     const Failures &failures = report.failures; 

     out << "================================================================================" << std::endl; 
     out << failures.name << std::endl; 
     out << "================================================================================" << std::endl; 

     for(Failures::const_iterator i = failures.begin(); i != failures.end(); i++) 
     { 
         const Failure &failure = *i; 

         out << "--------------------------------------------------------------------------------" << std::endl; 
         out << failure.name               << std::endl; 
         out << "--------------------------------------------------------------------------------" << std::endl; 

         out << failure.type      << std::endl; 
         out << failure.value     << std::endl; 
         out << failure.unit      << std::endl; 
         out << failure.info      << std::endl; 
         out << failure.failure << std::endl; 

         const DataFailure &data = failure.data; 

         out << data.name      << std::endl; 
         out << data.failure << std::endl; 

         for(DataFailure::const_iterator j = data.begin(); j != data.end(); j++) 
         { 
             const FieldFailure &field = *j; 

             out << field.name      << std::endl; 
             out << field.failure << std::endl; 

             for(FieldFailure::const_iterator k = field.begin(); k != field.end(); k++) 
             { 
                 const ItemFailure &item = *k; 

                 out << item.name      << std::endl; 
                 out << item.spec      << std::endl; 
                 out << item.impl      << std::endl; 
                 out << item.failure << std::endl; 
             } 
         } 

         const TimeFailure &time = failure.time; 

         out << "--------------------------------------------------------------------------------" << std::endl; 
         out << time.name      << std::endl; 
         out << "--------------------------------------------------------------------------------" << std::endl; 

         out << time.spec      << std::endl; 
         out << time.impl      << std::endl; 
         out << time.failure << std::endl; 

         const IfaceFailure &iface = failure.iface; 

         out << "--------------------------------------------------------------------------------" << std::endl; 
         out << iface.name      << std::endl; 
         out << "--------------------------------------------------------------------------------" << std::endl; 

         out << iface.spec      << std::endl; 
         out << iface.impl      << std::endl; 
         out << iface.failure << std::endl; 
     } 

     const Simulation &simulation = report.simulation; 

     out << "================================================================================" << std::endl; 
     out << simulation.name << std::endl; 
     out << "================================================================================" << std::endl; 

     for(Simulation::const_iterator i = simulation.begin(); i != simulation.end(); i++) 
     { 
         const Cycle &cycle = *i; 

         out << cycle.name    << std::endl; 
         out << cycle.value << std::endl; 
     } 

     const Statistics &statistics = report.statistics; 

     out << "================================================================================" << std::endl; 
     out << statistics.name << std::endl; 
     out << "================================================================================" << std::endl; 

     for(Statistics::const_iterator i = statistics.begin(); i != statistics.end(); i++) 
     { 
         const Count &count = *i; 

         out << count.name    << std::endl; 
         out << count.value << std::endl; 
     } 
 } 
 </code></pre> 

 Before developing your report printer make sure that printer you need to develop (or a similar one) doesn’t exist in the library.