summaryrefslogtreecommitdiffstats
path: root/starmath/qa/cppunit/test_cursor.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /starmath/qa/cppunit/test_cursor.cxx
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'starmath/qa/cppunit/test_cursor.cxx')
-rw-r--r--starmath/qa/cppunit/test_cursor.cxx169
1 files changed, 169 insertions, 0 deletions
diff --git a/starmath/qa/cppunit/test_cursor.cxx b/starmath/qa/cppunit/test_cursor.cxx
new file mode 100644
index 000000000..56c673c1b
--- /dev/null
+++ b/starmath/qa/cppunit/test_cursor.cxx
@@ -0,0 +1,169 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+#include <test/bootstrapfixture.hxx>
+
+#include <vcl/virdev.hxx>
+#include <sfx2/sfxmodelfactory.hxx>
+#include <smdll.hxx>
+
+#include <document.hxx>
+#include <node.hxx>
+#include <cursor.hxx>
+#include <parse5.hxx>
+
+#include <memory>
+
+typedef tools::SvRef<SmDocShell> SmDocShellRef;
+
+using namespace ::com::sun::star;
+
+namespace
+{
+class Test : public test::BootstrapFixture
+{
+public:
+ // init
+ virtual void setUp() override;
+ virtual void tearDown() override;
+
+ // tests
+ void testCopyPaste();
+ void testCopySelectPaste();
+ void testCutPaste();
+ void testCutSelectPaste();
+
+ CPPUNIT_TEST_SUITE(Test);
+ CPPUNIT_TEST(testCopyPaste);
+ CPPUNIT_TEST(testCopySelectPaste);
+ CPPUNIT_TEST(testCutPaste);
+ CPPUNIT_TEST(testCutSelectPaste);
+ CPPUNIT_TEST_SUITE_END();
+
+private:
+ SmDocShellRef xDocShRef;
+};
+
+void Test::setUp()
+{
+ BootstrapFixture::setUp();
+
+ SmGlobals::ensure();
+
+ xDocShRef = new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT);
+}
+
+void Test::tearDown()
+{
+ xDocShRef->DoClose();
+ xDocShRef.clear();
+ BootstrapFixture::tearDown();
+}
+
+void Test::testCopyPaste()
+{
+ auto xTree = SmParser5().Parse("a * b + c");
+ xTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
+
+ SmCursor aCursor(xTree.get(), xDocShRef.get());
+ ScopedVclPtrInstance<VirtualDevice> pOutputDevice;
+
+ // go to the position at "*"
+ aCursor.Move(pOutputDevice, MoveRight);
+ // select "* b" and then copy
+ aCursor.Move(pOutputDevice, MoveRight, false);
+ aCursor.Move(pOutputDevice, MoveRight, false);
+ aCursor.Copy();
+ // go to the right end and then paste
+ aCursor.Move(pOutputDevice, MoveRight);
+ aCursor.Move(pOutputDevice, MoveRight);
+ aCursor.Paste();
+
+ CPPUNIT_ASSERT_EQUAL(OUString("{ a * b + c * b }"), xDocShRef->GetText());
+}
+
+void Test::testCopySelectPaste()
+{
+ auto xTree = SmParser5().Parse("a * b + c");
+ xTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
+
+ SmCursor aCursor(xTree.get(), xDocShRef.get());
+ ScopedVclPtrInstance<VirtualDevice> pOutputDevice;
+
+ // go to the right end
+ for (int i = 0; i < 5; i++)
+ aCursor.Move(pOutputDevice, MoveRight);
+ // select "b + c" and then copy
+ aCursor.Move(pOutputDevice, MoveLeft, false);
+ aCursor.Move(pOutputDevice, MoveLeft, false);
+ aCursor.Move(pOutputDevice, MoveLeft, false);
+ aCursor.Copy();
+ // go to the left end
+ aCursor.Move(pOutputDevice, MoveLeft);
+ aCursor.Move(pOutputDevice, MoveLeft);
+ // select "a" and then paste
+ aCursor.Move(pOutputDevice, MoveRight, false);
+ aCursor.Paste();
+
+ CPPUNIT_ASSERT_EQUAL(OUString("{ b + c * b + c }"), xDocShRef->GetText());
+}
+
+void Test::testCutPaste()
+{
+ auto xTree = SmParser5().Parse("a * b + c");
+ xTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
+
+ SmCursor aCursor(xTree.get(), xDocShRef.get());
+ ScopedVclPtrInstance<VirtualDevice> pOutputDevice;
+
+ // go to the position at "*"
+ aCursor.Move(pOutputDevice, MoveRight);
+ // select "* b" and then cut
+ aCursor.Move(pOutputDevice, MoveRight, false);
+ aCursor.Move(pOutputDevice, MoveRight, false);
+ aCursor.Cut();
+ // go to the left end and then paste
+ aCursor.Move(pOutputDevice, MoveRight);
+ aCursor.Move(pOutputDevice, MoveRight);
+ aCursor.Paste();
+
+ CPPUNIT_ASSERT_EQUAL(OUString("{ a + c * b }"), xDocShRef->GetText());
+}
+
+void Test::testCutSelectPaste()
+{
+ auto xTree = SmParser5().Parse("a * b + c");
+ xTree->Prepare(xDocShRef->GetFormat(), *xDocShRef, 0);
+
+ SmCursor aCursor(xTree.get(), xDocShRef.get());
+ ScopedVclPtrInstance<VirtualDevice> pOutputDevice;
+
+ // go to the right end
+ for (int i = 0; i < 5; i++)
+ aCursor.Move(pOutputDevice, MoveRight);
+ // select "b + c" and then cut
+ aCursor.Move(pOutputDevice, MoveLeft, false);
+ aCursor.Move(pOutputDevice, MoveLeft, false);
+ aCursor.Move(pOutputDevice, MoveLeft, false);
+ aCursor.Cut();
+ // go to the left end
+ aCursor.Move(pOutputDevice, MoveLeft);
+ aCursor.Move(pOutputDevice, MoveLeft);
+ // select "a" and then paste
+ aCursor.Move(pOutputDevice, MoveRight, false);
+ aCursor.Paste();
+
+ CPPUNIT_ASSERT_EQUAL(OUString("{ b + c * }"), xDocShRef->GetText());
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */