From 626f6cd534a3563bf854b32fd5f46cff65357929 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 20 May 2016 12:35:41 +0200 Subject: Add initial CppunitTest_sfx2_classification Change-Id: Id896d10b8e735b4c95e14863428e4061326c3fbc Reviewed-on: https://gerrit.libreoffice.org/25193 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sfx2/qa/cppunit/test_classification.cxx | 146 ++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 sfx2/qa/cppunit/test_classification.cxx (limited to 'sfx2/qa/cppunit') diff --git a/sfx2/qa/cppunit/test_classification.cxx b/sfx2/qa/cppunit/test_classification.cxx new file mode 100644 index 000000000000..3cfc01d99541 --- /dev/null +++ b/sfx2/qa/cppunit/test_classification.cxx @@ -0,0 +1,146 @@ +/* -*- 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 +#include + +#include +#include +#include +#include + +#include +#include + +using namespace ::com::sun::star; + +namespace +{ + +/// Tests the handling of the .uno:ClassificationApply command in various applications. +class ClassificationTest : public test::BootstrapFixture, public unotest::MacrosTest +{ + uno::Reference mxComponentContext; + uno::Reference mxComponent; + void dispatchCommand(const uno::Reference& xComponent, const OUString& rCommand, const uno::Sequence& rPropertyValues); + void testClassification(); + +public: + virtual void setUp() override; + virtual void tearDown() override; + void testWriter(); + void testCalc(); + void testImpress(); + + CPPUNIT_TEST_SUITE(ClassificationTest); + CPPUNIT_TEST(testWriter); + CPPUNIT_TEST(testCalc); + CPPUNIT_TEST(testImpress); + CPPUNIT_TEST_SUITE_END(); +}; + +void ClassificationTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory())); + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void ClassificationTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + +void ClassificationTest::dispatchCommand(const uno::Reference& xComponent, const OUString& rCommand, const uno::Sequence& rPropertyValues) +{ + uno::Reference xController = uno::Reference(xComponent, uno::UNO_QUERY)->getCurrentController(); + CPPUNIT_ASSERT(xController.is()); + uno::Reference xFrame(xController->getFrame(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xFrame.is()); + + uno::Reference xContext = ::comphelper::getProcessComponentContext(); + uno::Reference xDispatchHelper(frame::DispatchHelper::create(xContext)); + CPPUNIT_ASSERT(xDispatchHelper.is()); + + xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues); +} + +void ClassificationTest::testClassification() +{ + uno::Sequence aPropertyValues(comphelper::InitPropertySequence( + { + {"Name", uno::makeAny(OUString("Non-Business"))}, + {"Type", uno::makeAny(OUString("urn:bails:ExportControl:"))}, + })); + dispatchCommand(mxComponent, ".uno:ClassificationApply", aPropertyValues); + + uno::Reference xDocumentPropertiesSupplier(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xDocumentPropertiesSupplier.is()); + uno::Reference xDocumentProperties = xDocumentPropertiesSupplier->getDocumentProperties(); + uno::Reference xPropertySet(xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY); + uno::Any aAny = xPropertySet->getPropertyValue("urn:bails:ExportControl:BusinessAuthorizationCategory:Identifier"); + CPPUNIT_ASSERT_EQUAL(OUString("urn:example:tscp:1:non-business"), aAny.get()); + + aPropertyValues = comphelper::InitPropertySequence( + { + {"Name", uno::makeAny(OUString("Confidential"))}, + {"Type", uno::makeAny(OUString("urn:bails:NationalSecurity:"))}, + }); + dispatchCommand(mxComponent, ".uno:ClassificationApply", aPropertyValues); + aAny = xPropertySet->getPropertyValue("urn:bails:NationalSecurity:BusinessAuthorizationCategory:Identifier"); + CPPUNIT_ASSERT_EQUAL(OUString("urn:example:tscp:1:confidential"), aAny.get()); + + aPropertyValues = comphelper::InitPropertySequence( + { + {"Name", uno::makeAny(OUString("Internal Only"))}, + {"Type", uno::makeAny(OUString("urn:bails:IntellectualProperty:"))}, + }); + dispatchCommand(mxComponent, ".uno:ClassificationApply", aPropertyValues); + aAny = xPropertySet->getPropertyValue("urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Identifier"); + CPPUNIT_ASSERT_EQUAL(OUString("urn:example:tscp:1:internal-only"), aAny.get()); +} + +void ClassificationTest::testWriter() +{ + // Test SID_CLASSIFICATION_APPLY handling in SwDocShell::Execute(). + mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + CPPUNIT_ASSERT(mxComponent.is()); + // This resulted in a beans::UnknownPropertyException when the request wasn't handled. + testClassification(); +} + +void ClassificationTest::testCalc() +{ + // Test SID_CLASSIFICATION_APPLY handling in ScFormatShell::ExecuteStyle(). + mxComponent = loadFromDesktop("private:factory/scalc", "com.sun.star.sheet.SpreadsheetDocument"); + CPPUNIT_ASSERT(mxComponent.is()); + // This resulted in a beans::UnknownPropertyException when the request wasn't handled. + testClassification(); +} + +void ClassificationTest::testImpress() +{ + // Test SID_CLASSIFICATION_APPLY handling in sd::DrawViewShell::FuTemporary(). + mxComponent = loadFromDesktop("private:factory/simpress", "com.sun.star.presentation.PresentationDocument"); + CPPUNIT_ASSERT(mxComponent.is()); + // This resulted in a beans::UnknownPropertyException when the request wasn't handled. + testClassification(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ClassificationTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit