LibreOffice Module test (master) 1
xtablecolumns.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
11
12#include <com/sun/star/table/XCellRange.hpp>
13#include <com/sun/star/table/XTableColumns.hpp>
14#include <com/sun/star/text/XSimpleText.hpp>
15#include <com/sun/star/uno/RuntimeException.hpp>
16
17#include <com/sun/star/uno/Reference.hxx>
18
19#include <cppunit/TestAssert.h>
20
21using namespace css;
22
23namespace apitest
24{
26{
27 uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW);
28 uno::Reference<table::XCellRange> xCR(m_xSheet, uno::UNO_QUERY_THROW);
29
30 // insert one column at position one
31 xTC->insertByIndex(1, 1);
32 CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(0, 0)));
33 CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(0, 1)));
34 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 0)));
35 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 1)));
36 CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(2, 0)));
37 CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(2, 1)));
38 CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(3, 0)));
39 CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(3, 1)));
40 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 0)));
41 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 1)));
42
43 // insert one column at position zero
44 xTC->insertByIndex(0, 1);
45 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 0)));
46 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 1)));
47 CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(1, 0)));
48 CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(1, 1)));
49 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 0)));
50 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 1)));
51 CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(3, 0)));
52 CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(3, 1)));
53 CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(4, 0)));
54 CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(4, 1)));
55 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(5, 0)));
56 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(5, 1)));
57
58 // insert two columns at position zero
59 xTC->insertByIndex(0, 2);
60 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 0)));
61 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 1)));
62 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 0)));
63 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 1)));
64 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 0)));
65 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 1)));
66 CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(3, 0)));
67 CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(3, 1)));
68 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 0)));
69 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 1)));
70 CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(5, 0)));
71 CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(5, 1)));
72 CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(6, 0)));
73 CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(6, 1)));
74 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(7, 0)));
75 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(7, 1)));
76}
77
79{
80 uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW);
81 CPPUNIT_ASSERT_THROW(xTC->insertByIndex(-1, 1), uno::RuntimeException);
82}
83
85{
86 uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW);
87 CPPUNIT_ASSERT_THROW(xTC->insertByIndex(0, 0), uno::RuntimeException);
88}
89
91{
92 uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW);
93
94 CPPUNIT_ASSERT_THROW(xTC->insertByIndex(xTC->getCount(), 1), uno::RuntimeException);
95}
96
98{
99 uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW);
100 uno::Reference<table::XCellRange> xCR(m_xSheet, uno::UNO_QUERY_THROW);
101
102 xTC->insertByIndex(1, 1); // insert one column at position one
103 xTC->insertByIndex(0, 1); // insert one column at position zero
104 xTC->insertByIndex(0, 2); // insert two columns at position zero
105
106 // remove two columns at position zero
107 xTC->removeByIndex(0, 2);
108 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 0)));
109 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 1)));
110 CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(1, 0)));
111 CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(1, 1)));
112 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 0)));
113 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 1)));
114 CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(3, 0)));
115 CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(3, 1)));
116 CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(4, 0)));
117 CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(4, 1)));
118 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(5, 0)));
119 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(5, 1)));
120
121 // remove one column at position zero
122 xTC->removeByIndex(0, 1);
123 CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(0, 0)));
124 CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(0, 1)));
125 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 0)));
126 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 1)));
127 CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(2, 0)));
128 CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(2, 1)));
129 CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(3, 0)));
130 CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(3, 1)));
131 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 0)));
132 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 1)));
133
134 // remove one column at position one
135 xTC->removeByIndex(1, 1);
136 CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(0, 0)));
137 CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(0, 1)));
138 CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(1, 0)));
139 CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(1, 1)));
140 CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(2, 0)));
141 CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(2, 1)));
142 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(3, 0)));
143 CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(3, 1)));
144}
145
147{
148 uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW);
149 CPPUNIT_ASSERT_THROW(xTC->removeByIndex(-1, 1), uno::RuntimeException);
150}
151
153{
154 uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW);
155 CPPUNIT_ASSERT_THROW(xTC->removeByIndex(0, 0), uno::RuntimeException);
156}
157
159{
160 uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW);
161
162 CPPUNIT_ASSERT_THROW(xTC->removeByIndex(xTC->getCount(), 1), uno::RuntimeException);
163}
164
165OUString XTableColumns::getCellText(const uno::Reference<table::XCell>& r_xCell)
166{
167 uno::Reference<text::XSimpleText> xST(r_xCell, uno::UNO_QUERY_THROW);
168 return xST->getString();
169}
170
171} // namespace apitest
172
173/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
void testInsertByIndexWithNegativeIndex()
css::uno::Reference< css::sheet::XSpreadsheet > m_xSheet
virtual css::uno::Reference< css::uno::XInterface > init()=0
void testInsertByIndexWithOutOfBoundIndex()
void testRemoveByIndexWithOutOfBoundIndex()
void testRemoveByIndexWithNegativeIndex()
static OUString getCellText(const css::uno::Reference< css::table::XCell > &r_xCell)