android: Update app-specific/MIME type icons
[LibreOffice.git] / desktop / qa / desktop_app / test_desktop_app.cxx
blob0e86368e63783d08fc5511e19104773edc7505b5
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 CPPUNIT_ASSERT(argument != nullptr);
53 if (m_index < m_args.size()) {
54 *argument = m_args[m_index++];
55 return true;
57 else {
58 return false;
61 private:
62 std::vector< OUString > m_args;
63 std::vector< OUString >::size_type m_index = 0;
66 // Test Office URI Schemes support
67 void Test::testTdf100837() {
68 auto xContext = ::cppu::defaultBootstrap_InitialComponentContext();
69 ::css::uno::Reference<::css::lang::XMultiComponentFactory> xFactory(xContext->getServiceManager());
70 ::css::uno::Reference<::css::lang::XMultiServiceFactory> xSM(xFactory, ::css::uno::UNO_QUERY_THROW);
71 // Without this we're crashing because callees are using getProcessServiceFactory
72 ::comphelper::setProcessServiceFactory(xSM);
75 // 1. Test default behaviour: Office URIs define open mode
76 TestSupplier supplier{ "foo", "ms-word:ofe|u|bar1", "ms-word:ofv|u|bar2", "ms-word:nft|u|bar3", "baz" };
77 desktop::CommandLineArgs args(supplier);
78 auto vOpenList = args.GetOpenList();
79 auto vForceOpenList = args.GetForceOpenList();
80 auto vViewList = args.GetViewList();
81 auto vForceNewList = args.GetForceNewList();
82 // 2 documents go to Open list: foo; baz
83 CPPUNIT_ASSERT_EQUAL(decltype(vOpenList.size())(2), vOpenList.size());
84 CPPUNIT_ASSERT_EQUAL(OUString("foo"), vOpenList[0]);
85 CPPUNIT_ASSERT_EQUAL(OUString("baz"), vOpenList[1]);
86 // 1 document goes to ForceOpen list: bar1
87 CPPUNIT_ASSERT_EQUAL(decltype(vForceOpenList.size())(1), vForceOpenList.size());
88 CPPUNIT_ASSERT_EQUAL(OUString("bar1"), vForceOpenList[0]);
89 // 1 document goes to View list: bar2
90 CPPUNIT_ASSERT_EQUAL(decltype(vViewList.size())(1), vViewList.size());
91 CPPUNIT_ASSERT_EQUAL(OUString("bar2"), vViewList[0]);
92 // 1 document goes to ForceNew list: bar3
93 CPPUNIT_ASSERT_EQUAL(decltype(vForceNewList.size())(1), vForceNewList.size());
94 CPPUNIT_ASSERT_EQUAL(OUString("bar3"), vForceNewList[0]);
98 // 2. Test explicit open mode arguments. Office URI commands should have no effect
99 TestSupplier supplier{ "--view", "ms-word:ofe|u|foo", "-o", "ms-word:ofv|u|bar", "ms-word:nft|u|baz" };
100 desktop::CommandLineArgs args(supplier);
101 auto vViewList = args.GetViewList();
102 auto vForceOpenList = args.GetForceOpenList();
103 // 1 document goes to View list: foo
104 CPPUNIT_ASSERT_EQUAL(decltype(vViewList.size())(1), vViewList.size());
105 CPPUNIT_ASSERT_EQUAL(OUString("foo"), vViewList[0]);
106 // 2 documents go to ForceOpen list: bar, baz
107 CPPUNIT_ASSERT_EQUAL(decltype(vForceOpenList.size())(2), vForceOpenList.size());
108 CPPUNIT_ASSERT_EQUAL(OUString("bar"), vForceOpenList[0]);
109 CPPUNIT_ASSERT_EQUAL(OUString("baz"), vForceOpenList[1]);
113 // 3. Test encoded URLs
114 TestSupplier supplier{ "foo", "ms-word:ofe%7Cu%7cbar1", "ms-word:ofv%7cu%7Cbar2", "ms-word:nft%7Cu%7cbar3", "baz" };
115 desktop::CommandLineArgs args(supplier);
116 auto vOpenList = args.GetOpenList();
117 auto vForceOpenList = args.GetForceOpenList();
118 auto vViewList = args.GetViewList();
119 auto vForceNewList = args.GetForceNewList();
120 // 2 documents go to Open list: foo; baz
121 CPPUNIT_ASSERT_EQUAL(decltype(vOpenList.size())(2), vOpenList.size());
122 CPPUNIT_ASSERT_EQUAL(OUString("foo"), vOpenList[0]);
123 CPPUNIT_ASSERT_EQUAL(OUString("baz"), vOpenList[1]);
124 // 1 document goes to ForceOpen list: bar1
125 CPPUNIT_ASSERT_EQUAL(decltype(vForceOpenList.size())(1), vForceOpenList.size());
126 CPPUNIT_ASSERT_EQUAL(OUString("bar1"), vForceOpenList[0]);
127 // 1 document goes to View list: bar2
128 CPPUNIT_ASSERT_EQUAL(decltype(vViewList.size())(1), vViewList.size());
129 CPPUNIT_ASSERT_EQUAL(OUString("bar2"), vViewList[0]);
130 // 1 document goes to ForceNew list: bar3
131 CPPUNIT_ASSERT_EQUAL(decltype(vForceNewList.size())(1), vForceNewList.size());
132 CPPUNIT_ASSERT_EQUAL(OUString("bar3"), vForceNewList[0]);
136 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
140 CPPUNIT_PLUGIN_IMPLEMENT();
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */