1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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
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"
50 #define MDDS_HASH_CONTAINER_BOOST 1
51 #include <mdds/mixed_type_matrix.hpp>
55 using namespace ::com::sun::star
;
56 using ::rtl::OUString
;
57 using ::rtl::OUStringBuffer
;
66 typedef ::mdds::mixed_type_matrix
<OUString
, bool> MatrixType
;
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
));
77 void print(const char* header
) const
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.
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
)
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();
119 for (size_t i
= 0; i
< nPadding
; ++i
)
120 aBuf
.append(sal_Unicode(' '));
121 cout
<< aBuf
.makeStringAndClear() << " | ";
124 cout
<< aSep
<< endl
;
128 void print(const char*) const {}
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
)
142 for (size_t col
= 0; col
< ns
.second
; ++col
)
144 const OUString
* p
= maMatrix
.get_string(row
, col
);
146 cout
<< "\"" << *p
<< "\"";
149 if (col
< ns
.second
- 1)
153 if (row
< ns
.first
- 1)
160 void clear() { maMatrix
.clear(); }
161 void resize(size_t rows
, size_t cols
) { maMatrix
.resize(rows
, cols
); }
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */