bump product version to 4.1.6.2
[LibreOffice.git] / sc / qa / unit / helper / debughelper.hxx
blobb9cf0a41fcaf6be74556b9e4f62c59a13771e259
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #ifndef SC_DEBUG_HELPER_HXX
11 #define SC_DEBUG_HELPER_HXX
13 /**
14 * Print nicely formatted sheet content to stdout. Indispensable when
15 * debugging the unit test code involving testing of sheet contents.
18 #include <rtl/strbuf.hxx>
19 #include <rtl/ustring.hxx>
21 #ifdef WNT
22 #if !defined NOMINMAX
23 #define NOMINMAX
24 #endif
25 #include <prewin.h>
26 #include <postwin.h>
27 #undef NOMINMAX
28 #endif
30 #define MDDS_HASH_CONTAINER_BOOST 1
31 #include <mdds/mixed_type_matrix.hpp>
33 #include <iostream>
35 using namespace ::com::sun::star;
36 using ::std::cout;
37 using ::std::cerr;
38 using ::std::endl;
39 using ::std::vector;
42 class SheetPrinter
44 typedef ::mdds::mixed_type_matrix<OUString, bool> MatrixType;
45 public:
46 SheetPrinter(size_t rows, size_t cols) :
47 maMatrix(rows, cols, ::mdds::matrix_density_sparse_empty) {}
49 void set(size_t row, size_t col, const OUString& aStr)
51 maMatrix.set_string(row, col, new OUString(aStr));
54 #if CALC_DEBUG_OUTPUT
55 void print(const char* header) const
57 if (header)
58 cout << header << endl;
60 MatrixType::size_pair_type ns = maMatrix.size();
61 vector<sal_Int32> aColWidths(ns.second, 0);
63 // Calculate column widths first.
64 for (size_t row = 0; row < ns.first; ++row)
66 for (size_t col = 0; col < ns.second; ++col)
68 const OUString* p = maMatrix.get_string(row, col);
69 if (aColWidths[col] < p->getLength())
70 aColWidths[col] = p->getLength();
74 // Make the row separator string.
75 OUStringBuffer aBuf;
76 aBuf.appendAscii("+");
77 for (size_t col = 0; col < ns.second; ++col)
79 aBuf.appendAscii("-");
80 for (sal_Int32 i = 0; i < aColWidths[col]; ++i)
81 aBuf.append(sal_Unicode('-'));
82 aBuf.appendAscii("-+");
85 OUString aSep = aBuf.makeStringAndClear();
87 // Now print to stdout.
88 cout << aSep << endl;
89 for (size_t row = 0; row < ns.first; ++row)
91 cout << "| ";
92 for (size_t col = 0; col < ns.second; ++col)
94 const OUString* p = maMatrix.get_string(row, col);
95 size_t nPadding = aColWidths[col] - p->getLength();
96 aBuf.append(*p);
97 for (size_t i = 0; i < nPadding; ++i)
98 aBuf.append(sal_Unicode(' '));
99 cout << aBuf.makeStringAndClear() << " | ";
101 cout << endl;
102 cout << aSep << endl;
105 #else
106 void print(const char*) const {}
107 #endif
110 * Print nested string array which can be copy-n-pasted into the test code
111 * for content verification.
113 void printArray() const
115 #if CALC_DEBUG_OUTPUT
116 MatrixType::size_pair_type ns = maMatrix.size();
117 for (size_t row = 0; row < ns.first; ++row)
119 cout << " { ";
120 for (size_t col = 0; col < ns.second; ++col)
122 const OUString* p = maMatrix.get_string(row, col);
123 if (p->getLength())
124 cout << "\"" << *p << "\"";
125 else
126 cout << "0";
127 if (col < ns.second - 1)
128 cout << ", ";
130 cout << " }";
131 if (row < ns.first - 1)
132 cout << ",";
133 cout << endl;
135 #endif
138 void clear() { maMatrix.clear(); }
139 void resize(size_t rows, size_t cols) { maMatrix.resize(rows, cols); }
141 private:
142 MatrixType maMatrix;
145 #endif
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */