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