Project

General

Profile

Actions

C++TESK Cookbook

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.

Step 1. Printer Definition

#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) { ... }
};

Step 2. Printer Registration

// If the printer is ready, it may be registered.
CPPTESK_MODEL(MyModel)
{
    MyModel()
    {
        // Printers are registered in a model.
        registerReportPrinter(new MyPrinter());
        ...
    }
};

Example. Simple Console Printer

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 i = failures.begin(); i != failures.end(); i++)
    {
        const cpptesk::hw::report::FailureGroup &failure_group = *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 j = failure.data.begin(); j != failure.data.end(); j++)
        {
            const cpptesk::hw::report::FieldFailure &field = *j;

            FieldList field_impl = field.impl;
            out << "Impl = ";
            for(cpptesk::hw::report::FieldList::const_iterator i = field_impl.begin(); i != field_impl.end(); i++)
            {
                const cpptesk::hw::report::ItemField &item = *i;

                out << item.value;
            }   
            out << 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++)
            {
                const cpptesk::hw::report::ItemField &item = *i;

                out << item.value;
            }   
            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 << " = " << simulation.cycle.value << " " << simulation.cycle.unit << std::endl;
    out << simulation.time.name << " = " << simulation.time.value << " " << simulation.time.unit << std::endl;
    out << simulation.frequency.name << " = " << 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 << " = " << statistics.stimuli.value << std::endl;
    out << statistics.reactions.name << " = " << statistics.reactions.value << std::endl;
    out << statistics.normal.name << " = " << statistics.normal.value << std::endl;
    out << statistics.incorrect.name << " = " << statistics.incorrect.value << std::endl;
    out << statistics.missing.name << " = " << statistics.missing.value << std::endl;
    out << statistics.unexpected.name << " = " << statistics.unexpected.value << std::endl;
}

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

Updated by Alexander Kamkin almost 10 years ago · 5 revisions