LCOV - code coverage report
Current view: top level - sc/qa/unit/helper - debughelper.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 7 7 100.0 %
Date: 2014-04-11 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #ifndef SC_DEBUG_HELPER_HXX
      11             : #define SC_DEBUG_HELPER_HXX
      12             : 
      13             : #include <rtl/strbuf.hxx>
      14             : #include <rtl/ustrbuf.hxx>
      15             : #include <rtl/ustring.hxx>
      16             : 
      17             : #ifdef WNT
      18             : #if !defined NOMINMAX
      19             : #define NOMINMAX
      20             : #endif
      21             : #include <prewin.h>
      22             : #include <postwin.h>
      23             : #undef NOMINMAX
      24             : #endif
      25             : 
      26             : #define MDDS_HASH_CONTAINER_BOOST 1
      27             : #include <mdds/mixed_type_matrix.hpp>
      28             : 
      29             : #include <iostream>
      30             : 
      31             : #define CALC_DEBUG_OUTPUT 0
      32             : #define CALC_TEST_PERF 0
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using ::std::cout;
      36             : using ::std::cerr;
      37             : using ::std::endl;
      38             : using ::std::vector;
      39             : 
      40             : /**
      41             :  * Print nicely formatted sheet content to stdout.  Indispensable when
      42             :  * debugging the unit test code involving testing of sheet contents.
      43             :  */
      44          74 : class SheetPrinter
      45             : {
      46             :     typedef ::mdds::mixed_type_matrix<OUString, bool> MatrixType;
      47             : public:
      48          74 :     SheetPrinter(size_t rows, size_t cols) :
      49          74 :         maMatrix(rows, cols, ::mdds::matrix_density_sparse_empty) {}
      50             : 
      51        1548 :     void set(size_t row, size_t col, const OUString& aStr)
      52             :     {
      53        1548 :         maMatrix.set_string(row, col, new OUString(aStr));
      54        1548 :     }
      55             : 
      56             : #if CALC_DEBUG_OUTPUT
      57             :     void print(const char* header) const
      58             :     {
      59             :         if (header)
      60             :             cout << header << endl;
      61             : 
      62             :         MatrixType::size_pair_type ns = maMatrix.size();
      63             :         vector<sal_Int32> aColWidths(ns.second, 0);
      64             : 
      65             :         // Calculate column widths first.
      66             :         for (size_t row = 0; row < ns.first; ++row)
      67             :         {
      68             :             for (size_t col = 0; col < ns.second; ++col)
      69             :             {
      70             :                 const OUString* p = maMatrix.get_string(row, col);
      71             :                 if (aColWidths[col] < p->getLength())
      72             :                     aColWidths[col] = p->getLength();
      73             :             }
      74             :         }
      75             : 
      76             :         // Make the row separator string.
      77             :         OUStringBuffer aBuf;
      78             :         aBuf.appendAscii("+");
      79             :         for (size_t col = 0; col < ns.second; ++col)
      80             :         {
      81             :             aBuf.appendAscii("-");
      82             :             for (sal_Int32 i = 0; i < aColWidths[col]; ++i)
      83             :                 aBuf.append(sal_Unicode('-'));
      84             :             aBuf.appendAscii("-+");
      85             :         }
      86             : 
      87             :         OUString aSep = aBuf.makeStringAndClear();
      88             : 
      89             :         // Now print to stdout.
      90             :         cout << aSep << endl;
      91             :         for (size_t row = 0; row < ns.first; ++row)
      92             :         {
      93             :             cout << "| ";
      94             :             for (size_t col = 0; col < ns.second; ++col)
      95             :             {
      96             :                 const OUString* p = maMatrix.get_string(row, col);
      97             :                 size_t nPadding = aColWidths[col] - p->getLength();
      98             :                 aBuf.append(*p);
      99             :                 for (size_t i = 0; i < nPadding; ++i)
     100             :                     aBuf.append(sal_Unicode(' '));
     101             :                 cout << aBuf.makeStringAndClear() << " | ";
     102             :             }
     103             :             cout << endl;
     104             :             cout << aSep << endl;
     105             :         }
     106             :     }
     107             : #else
     108          74 :     void print(const char*) const {}
     109             : #endif
     110             : 
     111             :     /**
     112             :      * Print nested string array which can be copy-n-pasted into the test code
     113             :      * for content verification.
     114             :      */
     115             :     void printArray() const
     116             :     {
     117             : #if CALC_DEBUG_OUTPUT
     118             :         MatrixType::size_pair_type ns = maMatrix.size();
     119             :         for (size_t row = 0; row < ns.first; ++row)
     120             :         {
     121             :             cout << "    { ";
     122             :             for (size_t col = 0; col < ns.second; ++col)
     123             :             {
     124             :                 const OUString* p = maMatrix.get_string(row, col);
     125             :                 if (p->getLength())
     126             :                     cout << "\"" << *p << "\"";
     127             :                 else
     128             :                     cout << "0";
     129             :                 if (col < ns.second - 1)
     130             :                     cout << ", ";
     131             :             }
     132             :             cout << " }";
     133             :             if (row < ns.first - 1)
     134             :                 cout << ",";
     135             :             cout << endl;
     136             :         }
     137             : #endif
     138             :     }
     139             : 
     140             :     void clear() { maMatrix.clear(); }
     141             :     void resize(size_t rows, size_t cols) { maMatrix.resize(rows, cols); }
     142             : 
     143             : private:
     144             :     MatrixType maMatrix;
     145             : };
     146             : 
     147             : #endif
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10