Project

General

Profile

C++TESK Cookbook » History » Revision 4

Revision 3 (Alexander Kamkin, 08/01/2013 01:39 PM) → Revision 4/5 (Alexander Protsenko, 11/14/2013 11:49 AM)

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(cpptesk::hw::report::Failures::const_iterator for(Failures::const_iterator i = failures.begin(); i != failures.end(); i++) 
     { 
         const cpptesk::hw::report::FailureGroup &failure_group Failure &failure = *i; 
    
         const cpptesk::hw::report::Failure &failure = *failure_group.begin(); 

         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; 

         for(cpptesk::hw::report::DataFailure::const_iterator const DataFailure &data = failure.data; 

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

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

             FieldList field_impl = field.impl; out << field.name      << std::endl; 
             out << "Impl field.failure << std::endl; 

             for(FieldFailure::const_iterator k = "; 
             for(cpptesk::hw::report::FieldList::const_iterator i = field_impl.begin(); i field.begin(); k != field_impl.end(); i++) field.end(); k++) 
             { 
                 const cpptesk::hw::report::ItemField ItemFailure &item = *i; 
                
                 *k; 

                 out << item.value; 
             }    
             item.name      << std::endl; 
                 out << item.spec      << std::endl; 

             FieldList field_spec = field.impl; 
             
                 out << "Spec = "; 
             for(cpptesk::hw::report::FieldList::const_iterator i = field_spec.begin(); i != field_spec.end(); i++) 
             { item.impl      << std::endl; 
                 const cpptesk::hw::report::ItemField &item = *i; 
                
                 out << item.value; item.failure << std::endl; 
             }    
             out << 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; 

     out << simulation.cycle.name << " for(Simulation::const_iterator i = " << simulation.cycle.value << " " << simulation.cycle.unit << std::endl; simulation.begin(); i != simulation.end(); i++) 
     { 
         const Cycle &cycle = *i; 

         out << simulation.time.name cycle.name    << " = " << simulation.time.value << " " << simulation.time.unit << std::endl; 
     
         out << simulation.frequency.name cycle.value << " = " << simulation.frequency.value << " " << simulation.frequency.unit << std::endl; 
     } 

     const Statistics &statistics = report.statistics; 

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

     out << statistics.stimuli.name << " for(Statistics::const_iterator i = " << statistics.stimuli.value << std::endl; statistics.begin(); i != statistics.end(); i++) 
     out << statistics.reactions.name << " { 
         const Count &count = " << statistics.reactions.value << std::endl; 
     *i; 

         out << statistics.normal.name count.name    << " = " << statistics.normal.value << std::endl; 
     
         out << statistics.incorrect.name count.value << " = " << statistics.incorrect.value << std::endl; 
     out << statistics.missing.name << " = " << statistics.missing.value << std::endl; 
     out << statistics.unexpected.name << " = " << statistics.unexpected.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.