Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "ucalc.hxx"
11 : #include <editutil.hxx>
12 : #include <cellvalue.hxx>
13 : #include <svl/languageoptions.hxx>
14 :
15 2 : void Test::testColumnFindEditCells()
16 : {
17 2 : m_pDoc->InsertTab(0, "Test");
18 :
19 : // Test the basics with real edit cells, using Column A.
20 :
21 2 : SCROW nResRow = m_pDoc->GetFirstEditTextRow(ScRange(0,0,0,0,MAXROW,0));
22 2 : CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", nResRow == -1);
23 2 : nResRow = m_pDoc->GetFirstEditTextRow(ScRange(0,0,0,0,0,0));
24 2 : CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", nResRow == -1);
25 2 : nResRow = m_pDoc->GetFirstEditTextRow(ScRange(0,0,0,0,10,0));
26 2 : CPPUNIT_ASSERT_MESSAGE("There should be no edit cells.", nResRow == -1);
27 :
28 2 : ScFieldEditEngine& rEE = m_pDoc->GetEditEngine();
29 2 : rEE.SetText("Test");
30 2 : m_pDoc->SetEditText(ScAddress(0,0,0), rEE.CreateTextObject());
31 2 : const EditTextObject* pObj = m_pDoc->GetEditText(ScAddress(0,0,0));
32 2 : CPPUNIT_ASSERT_MESSAGE("There should be an edit cell here.", pObj);
33 :
34 2 : ScRange aRange(0,0,0,0,0,0);
35 2 : nResRow = m_pDoc->GetFirstEditTextRow(aRange);
36 2 : CPPUNIT_ASSERT_MESSAGE("There is an edit cell here.", nResRow == 0);
37 :
38 2 : aRange.aStart.SetRow(1);
39 2 : aRange.aEnd.SetRow(1);
40 2 : nResRow = m_pDoc->GetFirstEditTextRow(aRange);
41 2 : CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", nResRow == -1);
42 :
43 2 : aRange.aStart.SetRow(2);
44 2 : aRange.aEnd.SetRow(4);
45 2 : nResRow = m_pDoc->GetFirstEditTextRow(aRange);
46 2 : CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", nResRow == -1);
47 :
48 2 : aRange.aStart.SetRow(0);
49 2 : aRange.aEnd.SetRow(MAXROW);
50 2 : nResRow = m_pDoc->GetFirstEditTextRow(aRange);
51 2 : CPPUNIT_ASSERT_MESSAGE("There should be an edit cell in specified range.", nResRow == 0);
52 :
53 2 : m_pDoc->SetString(ScAddress(0,0,0), "Test");
54 2 : m_pDoc->SetValue(ScAddress(0,2,0), 1.0);
55 2 : ScRefCellValue aCell;
56 2 : aCell.assign(*m_pDoc, ScAddress(0,0,0));
57 2 : CPPUNIT_ASSERT_MESSAGE("This should be a string cell.", aCell.meType == CELLTYPE_STRING);
58 2 : aCell.assign(*m_pDoc, ScAddress(0,1,0));
59 2 : CPPUNIT_ASSERT_MESSAGE("This should be an empty cell.", aCell.meType == CELLTYPE_NONE);
60 2 : aCell.assign(*m_pDoc, ScAddress(0,2,0));
61 2 : CPPUNIT_ASSERT_MESSAGE("This should be a numeric cell.", aCell.meType == CELLTYPE_VALUE);
62 2 : aCell.assign(*m_pDoc, ScAddress(0,3,0));
63 2 : CPPUNIT_ASSERT_MESSAGE("This should be an empty cell.", aCell.meType == CELLTYPE_NONE);
64 :
65 2 : aRange.aStart.SetRow(1);
66 2 : aRange.aEnd.SetRow(1);
67 2 : nResRow = m_pDoc->GetFirstEditTextRow(aRange);
68 2 : CPPUNIT_ASSERT_MESSAGE("There shouldn't be an edit cell in specified range.", nResRow == -1);
69 :
70 : // Test with non-edit cell but with ambiguous script type.
71 :
72 2 : m_pDoc->SetString(ScAddress(1,11,0), "Some text");
73 2 : m_pDoc->SetString(ScAddress(1,12,0), "Some text");
74 2 : m_pDoc->SetString(ScAddress(1,13,0), "Other text");
75 :
76 2 : m_pDoc->SetScriptType(ScAddress(1,11,0), (SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN));
77 2 : m_pDoc->SetScriptType(ScAddress(1,12,0), (SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN));
78 2 : m_pDoc->SetScriptType(ScAddress(1,13,0), (SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN));
79 :
80 2 : nResRow = m_pDoc->GetFirstEditTextRow(ScAddress(1,11,0));
81 2 : CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(11), nResRow);
82 2 : nResRow = m_pDoc->GetFirstEditTextRow(ScAddress(1,12,0));
83 2 : CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(12), nResRow);
84 :
85 14 : for (SCROW i = 0; i <= 5; ++i)
86 12 : m_pDoc->SetString(ScAddress(2,i,0), "Text");
87 :
88 2 : m_pDoc->SetScriptType(ScAddress(2,5,0), (SCRIPTTYPE_LATIN | SCRIPTTYPE_ASIAN));
89 :
90 2 : nResRow = m_pDoc->GetFirstEditTextRow(ScAddress(2,1,0));
91 2 : CPPUNIT_ASSERT_EQUAL(static_cast<SCROW>(-1), nResRow);
92 :
93 2 : m_pDoc->DeleteTab(0);
94 8 : }
95 :
96 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|