Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sc / qa / unit / helper / debughelper.hxx
blob2a560c68085f5290f94cb7e6739242522dccd7ce
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * Major Contributor(s):
16 * [ Copyright (C) 2011 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer) ]
18 * All Rights Reserved.
20 * For minor contributions see the git repository.
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 * instead of those above.
29 #ifndef SC_DEBUG_HELPER_HXX
30 #define SC_DEBUG_HELPER_HXX
32 /**
33 * Print nicely formatted sheet content to stdout. Indispensable when
34 * debugging the unit test code involving testing of sheet contents.
37 #include <rtl/strbuf.hxx>
38 #include <rtl/ustring.hxx>
39 #include "document.hxx"
41 #ifdef WNT
42 #if !defined NOMINMAX
43 #define NOMINMAX
44 #endif
45 #include <prewin.h>
46 #include <postwin.h>
47 #undef NOMINMAX
48 #endif
50 #define MDDS_HASH_CONTAINER_BOOST 1
51 #include <mdds/mixed_type_matrix.hpp>
53 #include <iostream>
55 using namespace ::com::sun::star;
56 using ::rtl::OUString;
57 using ::rtl::OUStringBuffer;
58 using ::std::cout;
59 using ::std::cerr;
60 using ::std::endl;
61 using ::std::vector;
64 class SheetPrinter
66 typedef ::mdds::mixed_type_matrix<OUString, bool> MatrixType;
67 public:
68 SheetPrinter(size_t rows, size_t cols) :
69 maMatrix(rows, cols, ::mdds::matrix_density_sparse_empty) {}
71 void set(size_t row, size_t col, const OUString& aStr)
73 maMatrix.set_string(row, col, new OUString(aStr));
76 #if CALC_DEBUG_OUTPUT
77 void print(const char* header) const
79 if (header)
80 cout << header << endl;
82 MatrixType::size_pair_type ns = maMatrix.size();
83 vector<sal_Int32> aColWidths(ns.second, 0);
85 // Calculate column widths first.
86 for (size_t row = 0; row < ns.first; ++row)
88 for (size_t col = 0; col < ns.second; ++col)
90 const OUString* p = maMatrix.get_string(row, col);
91 if (aColWidths[col] < p->getLength())
92 aColWidths[col] = p->getLength();
96 // Make the row separator string.
97 OUStringBuffer aBuf;
98 aBuf.appendAscii("+");
99 for (size_t col = 0; col < ns.second; ++col)
101 aBuf.appendAscii("-");
102 for (sal_Int32 i = 0; i < aColWidths[col]; ++i)
103 aBuf.append(sal_Unicode('-'));
104 aBuf.appendAscii("-+");
107 OUString aSep = aBuf.makeStringAndClear();
109 // Now print to stdout.
110 cout << aSep << endl;
111 for (size_t row = 0; row < ns.first; ++row)
113 cout << "| ";
114 for (size_t col = 0; col < ns.second; ++col)
116 const OUString* p = maMatrix.get_string(row, col);
117 size_t nPadding = aColWidths[col] - p->getLength();
118 aBuf.append(*p);
119 for (size_t i = 0; i < nPadding; ++i)
120 aBuf.append(sal_Unicode(' '));
121 cout << aBuf.makeStringAndClear() << " | ";
123 cout << endl;
124 cout << aSep << endl;
127 #else
128 void print(const char*) const {}
129 #endif
132 * Print nested string array which can be copy-n-pasted into the test code
133 * for content verification.
135 void printArray() const
137 #if CALC_DEBUG_OUTPUT
138 MatrixType::size_pair_type ns = maMatrix.size();
139 for (size_t row = 0; row < ns.first; ++row)
141 cout << " { ";
142 for (size_t col = 0; col < ns.second; ++col)
144 const OUString* p = maMatrix.get_string(row, col);
145 if (p->getLength())
146 cout << "\"" << *p << "\"";
147 else
148 cout << "0";
149 if (col < ns.second - 1)
150 cout << ", ";
152 cout << " }";
153 if (row < ns.first - 1)
154 cout << ",";
155 cout << endl;
157 #endif
160 void clear() { maMatrix.clear(); }
161 void resize(size_t rows, size_t cols) { maMatrix.resize(rows, cols); }
163 private:
164 MatrixType maMatrix;
167 #endif
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */