Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / qa / cppunit / test_classification.cxx
blobb824ca219efe5d9068b9f0c7e811193a944f0ed5
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/.
8 */
10 #include <test/bootstrapfixture.hxx>
11 #include <unotest/macros_test.hxx>
13 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
14 #include <com/sun/star/frame/Desktop.hpp>
15 #include <com/sun/star/frame/DispatchHelper.hpp>
16 #include <com/sun/star/beans/XPropertySet.hpp>
18 #include <comphelper/processfactory.hxx>
19 #include <comphelper/propertysequence.hxx>
21 using namespace ::com::sun::star;
23 namespace
26 /// Tests the handling of the .uno:ClassificationApply command in various applications.
27 class ClassificationTest : public test::BootstrapFixture, public unotest::MacrosTest
29 uno::Reference<lang::XComponent> mxComponent;
30 void dispatchCommand(const uno::Reference<lang::XComponent>& xComponent, const OUString& rCommand, const uno::Sequence<beans::PropertyValue>& rPropertyValues);
31 void testClassification();
33 public:
34 virtual void setUp() override;
35 virtual void tearDown() override;
36 void testWriter();
37 void testCalc();
38 void testImpress();
40 CPPUNIT_TEST_SUITE(ClassificationTest);
41 CPPUNIT_TEST(testWriter);
42 CPPUNIT_TEST(testCalc);
43 CPPUNIT_TEST(testImpress);
44 CPPUNIT_TEST_SUITE_END();
47 void ClassificationTest::setUp()
49 test::BootstrapFixture::setUp();
51 mxDesktop.set(frame::Desktop::create(mxComponentContext));
54 void ClassificationTest::tearDown()
56 if (mxComponent.is())
57 mxComponent->dispose();
59 test::BootstrapFixture::tearDown();
62 void ClassificationTest::dispatchCommand(const uno::Reference<lang::XComponent>& xComponent, const OUString& rCommand, const uno::Sequence<beans::PropertyValue>& rPropertyValues)
64 uno::Reference<frame::XController> xController = uno::Reference<frame::XModel>(xComponent, uno::UNO_QUERY_THROW)->getCurrentController();
65 CPPUNIT_ASSERT(xController.is());
66 uno::Reference<frame::XDispatchProvider> xFrame(xController->getFrame(), uno::UNO_QUERY);
67 CPPUNIT_ASSERT(xFrame.is());
69 uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
70 uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext));
71 CPPUNIT_ASSERT(xDispatchHelper.is());
73 xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues);
76 void ClassificationTest::testClassification()
78 uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
80 {"Name", uno::makeAny(OUString("Non-Business"))},
81 {"Type", uno::makeAny(OUString("urn:bails:ExportControl:"))},
82 }));
83 dispatchCommand(mxComponent, ".uno:ClassificationApply", aPropertyValues);
85 uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(mxComponent, uno::UNO_QUERY);
86 CPPUNIT_ASSERT(xDocumentPropertiesSupplier.is());
87 uno::Reference<document::XDocumentProperties> xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties();
88 uno::Reference<beans::XPropertySet> xPropertySet(xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY);
89 uno::Any aAny = xPropertySet->getPropertyValue("urn:bails:ExportControl:BusinessAuthorizationCategory:Identifier");
90 CPPUNIT_ASSERT_EQUAL(OUString("urn:example:tscp:1:non-business"), aAny.get<OUString>());
92 aPropertyValues = comphelper::InitPropertySequence(
94 {"Name", uno::makeAny(OUString("Confidential"))},
95 {"Type", uno::makeAny(OUString("urn:bails:NationalSecurity:"))},
96 });
97 dispatchCommand(mxComponent, ".uno:ClassificationApply", aPropertyValues);
98 aAny = xPropertySet->getPropertyValue("urn:bails:NationalSecurity:BusinessAuthorizationCategory:Identifier");
99 CPPUNIT_ASSERT_EQUAL(OUString("urn:example:tscp:1:confidential"), aAny.get<OUString>());
101 aPropertyValues = comphelper::InitPropertySequence(
103 {"Name", uno::makeAny(OUString("Internal Only"))},
104 {"Type", uno::makeAny(OUString("urn:bails:IntellectualProperty:"))},
106 dispatchCommand(mxComponent, ".uno:ClassificationApply", aPropertyValues);
107 aAny = xPropertySet->getPropertyValue("urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Identifier");
108 CPPUNIT_ASSERT_EQUAL(OUString("urn:example:tscp:1:internal-only"), aAny.get<OUString>());
111 void ClassificationTest::testWriter()
113 // Test SID_CLASSIFICATION_APPLY handling in SwDocShell::Execute().
114 mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
115 CPPUNIT_ASSERT(mxComponent.is());
116 // This resulted in a beans::UnknownPropertyException when the request wasn't handled.
117 testClassification();
120 void ClassificationTest::testCalc()
122 // Test SID_CLASSIFICATION_APPLY handling in ScFormatShell::ExecuteStyle().
123 mxComponent = loadFromDesktop("private:factory/scalc", "com.sun.star.sheet.SpreadsheetDocument");
124 CPPUNIT_ASSERT(mxComponent.is());
125 // This resulted in a beans::UnknownPropertyException when the request wasn't handled.
126 testClassification();
129 void ClassificationTest::testImpress()
131 // Test SID_CLASSIFICATION_APPLY handling in sd::DrawViewShell::FuTemporary().
132 mxComponent = loadFromDesktop("private:factory/simpress", "com.sun.star.presentation.PresentationDocument");
133 CPPUNIT_ASSERT(mxComponent.is());
134 // This resulted in a beans::UnknownPropertyException when the request wasn't handled.
135 testClassification();
138 CPPUNIT_TEST_SUITE_REGISTRATION(ClassificationTest);
142 CPPUNIT_PLUGIN_IMPLEMENT();
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */