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
16using namespace css;
17using namespace css::uno;
18
19namespace apitest
20{
22{
23 uno::Reference<text::XSimpleText> xSimpleText(init(), UNO_QUERY_THROW);
24
25 CPPUNIT_ASSERT(xSimpleText->createTextCursor());
26}
27
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
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
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: */
void testInsertControlCharacter()
Definition: xsimpletext.cxx:51
void testCreateTextCursorByRange()
Definition: xsimpletext.cxx:28
virtual css::uno::Reference< css::uno::XInterface > init()=0