LibreOffice Module test (master)  1
xsimpletext.cxx
Go to the documentation of this file.
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 
11 #include <com/sun/star/text/XTextCursor.hpp>
12 #include <com/sun/star/text/ControlCharacter.hpp>
13 #include <com/sun/star/lang/IllegalArgumentException.hpp>
14 #include <cppunit/TestAssert.h>
15 
16 using namespace css;
17 using namespace css::uno;
18 
19 namespace apitest
20 {
21 void XSimpleText::testCreateTextCursor()
22 {
23  uno::Reference<text::XSimpleText> xSimpleText(init(), UNO_QUERY_THROW);
24 
25  CPPUNIT_ASSERT(xSimpleText->createTextCursor());
26 }
27 
28 void XSimpleText::testCreateTextCursorByRange()
29 {
30  uno::Reference<text::XSimpleText> xSimpleText(init(), UNO_QUERY_THROW);
31  uno::Reference<text::XTextCursor> xCursor(xSimpleText->createTextCursor(), UNO_SET_THROW);
32 
33  xCursor->gotoStart(false);
34 
35  CPPUNIT_ASSERT(xSimpleText->createTextCursorByRange(xCursor));
36 }
37 
38 void XSimpleText::testInsertString()
39 {
40  uno::Reference<text::XSimpleText> xSimpleText(init(), UNO_QUERY_THROW);
41  uno::Reference<text::XTextRange> xCursor(xSimpleText->createTextCursor(), UNO_QUERY_THROW);
42  ::rtl::OUString sString = "TestString";
43 
44  xSimpleText->insertString(xCursor, sString, false);
45  ::rtl::OUString gString = xSimpleText->getText()->getString();
46 
47  CPPUNIT_ASSERT(!gString.isEmpty());
48  CPPUNIT_ASSERT(gString.indexOf(sString) >= 0);
49 }
50 
51 void XSimpleText::testInsertControlCharacter()
52 {
53  bool bOK = true;
54 
55  uno::Reference<text::XSimpleText> xSimpleText(init(), UNO_QUERY_THROW);
56  uno::Reference<text::XTextRange> xCursor(xSimpleText->createTextCursor(), UNO_QUERY_THROW);
57 
58  try
59  {
60  xSimpleText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK,
61  false);
62  xSimpleText->insertControlCharacter(xCursor, text::ControlCharacter::LINE_BREAK, false);
63  xSimpleText->insertString(xSimpleText->createTextCursor(), "newLine", false);
64  }
65  catch (const lang::IllegalArgumentException&)
66  {
67  bOK = false;
68  }
69 
70  OUString gString = xSimpleText->getString();
71  CPPUNIT_ASSERT(bOK);
72  CPPUNIT_ASSERT(gString.indexOf("\n") > -1);
73 }
74 }
75 
76 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FILE * init(int, char **)