Update git submodules
[LibreOffice.git] / desktop / qa / desktop_app / test_desktop_app.cxx
blob7112b22deb97d4345f0d6d5511ce2ce10ea0c64f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
22 #include <cppunit/TestAssert.h>
23 #include <cppunit/TestFixture.h>
24 #include <cppunit/extensions/HelperMacros.h>
25 #include <cppunit/plugin/TestPlugIn.h>
26 #include <rtl/ustring.hxx>
27 #include <cppuhelper/bootstrap.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <comphelper/processfactory.hxx>
33 #include "../../source/app/cmdlineargs.hxx"
35 namespace {
37 class Test: public ::CppUnit::TestFixture {
38 public:
39 void testTdf100837();
41 CPPUNIT_TEST_SUITE(Test);
42 CPPUNIT_TEST(testTdf100837);
43 CPPUNIT_TEST_SUITE_END();
46 class TestSupplier : public desktop::CommandLineArgs::Supplier {
47 public:
48 explicit TestSupplier(const std::initializer_list<OUString>& args) : m_args(args) {}
50 virtual std::optional< OUString > getCwdUrl() override { return std::optional< OUString >(); }
51 virtual bool next(OUString& argument) override {
52 if (m_index < m_args.size()) {
53 argument = m_args[m_index++];
54 return true;
56 else {
57 return false;
60 private:
61 std::vector< OUString > m_args;
62 std::vector< OUString >::size_type m_index = 0;
65 // Test Office URI Schemes support
66 void Test::testTdf100837() {
67 auto xContext = ::cppu::defaultBootstrap_InitialComponentContext();
68 ::css::uno::Reference<::css::lang::XMultiComponentFactory> xFactory(xContext->getServiceManager());
69 ::css::uno::Reference<::css::lang::XMultiServiceFactory> xSM(xFactory, ::css::uno::UNO_QUERY_THROW);
70 // Without this we're crashing because callees are using getProcessServiceFactory
71 ::comphelper::setProcessServiceFactory(xSM);
74 // 1. Test default behaviour: Office URIs define open mode
75 TestSupplier supplier{ u"foo"_ustr, u"ms-word:ofe|u|bar1"_ustr, u"ms-word:ofv|u|bar2"_ustr, u"ms-word:nft|u|bar3"_ustr, u"baz"_ustr };
76 desktop::CommandLineArgs args(supplier);
77 auto vOpenList = args.GetOpenList();
78 auto vForceOpenList = args.GetForceOpenList();
79 auto vViewList = args.GetViewList();
80 auto vForceNewList = args.GetForceNewList();
81 // 2 documents go to Open list: foo; baz
82 CPPUNIT_ASSERT_EQUAL(decltype(vOpenList.size())(2), vOpenList.size());
83 CPPUNIT_ASSERT_EQUAL(u"foo"_ustr, vOpenList[0]);
84 CPPUNIT_ASSERT_EQUAL(u"baz"_ustr, vOpenList[1]);
85 // 1 document goes to ForceOpen list: bar1
86 CPPUNIT_ASSERT_EQUAL(decltype(vForceOpenList.size())(1), vForceOpenList.size());
87 CPPUNIT_ASSERT_EQUAL(u"bar1"_ustr, vForceOpenList[0]);
88 // 1 document goes to View list: bar2
89 CPPUNIT_ASSERT_EQUAL(decltype(vViewList.size())(1), vViewList.size());
90 CPPUNIT_ASSERT_EQUAL(u"bar2"_ustr, vViewList[0]);
91 // 1 document goes to ForceNew list: bar3
92 CPPUNIT_ASSERT_EQUAL(decltype(vForceNewList.size())(1), vForceNewList.size());
93 CPPUNIT_ASSERT_EQUAL(u"bar3"_ustr, vForceNewList[0]);
97 // 2. Test explicit open mode arguments. Office URI commands should have no effect
98 TestSupplier supplier{ u"--view"_ustr, u"ms-word:ofe|u|foo"_ustr, u"-o"_ustr, u"ms-word:ofv|u|bar"_ustr, u"ms-word:nft|u|baz"_ustr };
99 desktop::CommandLineArgs args(supplier);
100 auto vViewList = args.GetViewList();
101 auto vForceOpenList = args.GetForceOpenList();
102 // 1 document goes to View list: foo
103 CPPUNIT_ASSERT_EQUAL(decltype(vViewList.size())(1), vViewList.size());
104 CPPUNIT_ASSERT_EQUAL(u"foo"_ustr, vViewList[0]);
105 // 2 documents go to ForceOpen list: bar, baz
106 CPPUNIT_ASSERT_EQUAL(decltype(vForceOpenList.size())(2), vForceOpenList.size());
107 CPPUNIT_ASSERT_EQUAL(u"bar"_ustr, vForceOpenList[0]);
108 CPPUNIT_ASSERT_EQUAL(u"baz"_ustr, vForceOpenList[1]);
112 // 3. Test encoded URLs
113 TestSupplier supplier{ u"foo"_ustr, u"ms-word:ofe%7Cu%7cbar1"_ustr, u"ms-word:ofv%7cu%7Cbar2"_ustr, u"ms-word:nft%7Cu%7cbar3"_ustr, u"baz"_ustr };
114 desktop::CommandLineArgs args(supplier);
115 auto vOpenList = args.GetOpenList();
116 auto vForceOpenList = args.GetForceOpenList();
117 auto vViewList = args.GetViewList();
118 auto vForceNewList = args.GetForceNewList();
119 // 2 documents go to Open list: foo; baz
120 CPPUNIT_ASSERT_EQUAL(decltype(vOpenList.size())(2), vOpenList.size());
121 CPPUNIT_ASSERT_EQUAL(u"foo"_ustr, vOpenList[0]);
122 CPPUNIT_ASSERT_EQUAL(u"baz"_ustr, vOpenList[1]);
123 // 1 document goes to ForceOpen list: bar1
124 CPPUNIT_ASSERT_EQUAL(decltype(vForceOpenList.size())(1), vForceOpenList.size());
125 CPPUNIT_ASSERT_EQUAL(u"bar1"_ustr, vForceOpenList[0]);
126 // 1 document goes to View list: bar2
127 CPPUNIT_ASSERT_EQUAL(decltype(vViewList.size())(1), vViewList.size());
128 CPPUNIT_ASSERT_EQUAL(u"bar2"_ustr, vViewList[0]);
129 // 1 document goes to ForceNew list: bar3
130 CPPUNIT_ASSERT_EQUAL(decltype(vForceNewList.size())(1), vForceNewList.size());
131 CPPUNIT_ASSERT_EQUAL(u"bar3"_ustr, vForceNewList[0]);
135 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
139 CPPUNIT_PLUGIN_IMPLEMENT();
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */