LibreOffice Module test (master)  1
xcell.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 
10 #include <test/table/xcell.hxx>
11 
12 #include <com/sun/star/table/XCell.hpp>
13 #include <com/sun/star/table/CellContentType.hpp>
14 
15 #include <com/sun/star/uno/Reference.hxx>
16 
17 #include <cppunit/TestAssert.h>
18 
19 using namespace com::sun::star;
20 using namespace com::sun::star::uno;
21 
22 namespace apitest
23 {
24 void XCell::testGetError()
25 {
26  uno::Reference<table::XCell> xCell(init(), UNO_QUERY_THROW);
27  const sal_Int32 nCorrectFormula = xCell->getError();
28  xCell->setFormula("=sqrt(-2)");
29  const sal_Int32 nIncorrectFormula = xCell->getError();
30 
31  CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to get Error", sal_Int32(0), nCorrectFormula);
32  CPPUNIT_ASSERT_MESSAGE("Successfully able to get Error", (nIncorrectFormula != 0));
33 }
34 
35 void XCell::testGetType()
36 {
37  uno::Reference<table::XCell> xCell(init(), UNO_QUERY_THROW);
38  bool aResult = true;
39 
40  if (xCell->getType() == table::CellContentType_EMPTY)
41  aResult &= true;
42  else if (xCell->getType() == table::CellContentType_VALUE)
43  aResult &= true;
44  else if (xCell->getType() == table::CellContentType_TEXT)
45  aResult &= true;
46  else if (xCell->getType() == table::CellContentType_FORMULA)
47  aResult &= true;
48  else
49  aResult = false;
50 
51  CPPUNIT_ASSERT_MESSAGE("Successfully able to get Type", aResult);
52 }
53 
54 void XCell::testSetGetFormula()
55 {
56  uno::Reference<table::XCell> xCell(init(), UNO_QUERY_THROW);
57  OUString aFormula = "=2+2";
58 
59  xCell->setFormula(aFormula);
60 
61  OUString aFormula2 = xCell->getFormula();
62 
63  CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to set and get Formula", aFormula, aFormula2);
64 }
65 
66 void XCell::testSetGetValue()
67 {
68  uno::Reference<table::XCell> xCell(init(), UNO_QUERY_THROW);
69  double nInValue = 222.555;
70 
71  xCell->setValue(nInValue);
72 
73  double nCellValue = xCell->getValue();
74 
75  CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to set and get Value", nInValue, nCellValue);
76 }
77 }
78 
79 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
FILE * init(int, char **)