From d60157196f34a4b08f64aa869fb104998041b688 Mon Sep 17 00:00:00 2001 From: Laurent Godard Date: Tue, 24 Feb 2015 09:41:44 +0100 Subject: calc : add UNO properties for "Record changes" with unit testing Change-Id: I2a0e09f699c8489f61453b4144dd6181bd9b47fd Reviewed-on: https://gerrit.libreoffice.org/14603 Reviewed-by: Eike Rathke Tested-by: Eike Rathke --- sc/qa/extras/recordchanges-test.cxx | 108 +++++++++++++++++++++ .../testdocuments/RecordChangesProtected.ods | Bin 0 -> 14217 bytes 2 files changed, 108 insertions(+) create mode 100644 sc/qa/extras/recordchanges-test.cxx create mode 100644 sc/qa/extras/testdocuments/RecordChangesProtected.ods (limited to 'sc/qa/extras') diff --git a/sc/qa/extras/recordchanges-test.cxx b/sc/qa/extras/recordchanges-test.cxx new file mode 100644 index 000000000000..67e84e335c26 --- /dev/null +++ b/sc/qa/extras/recordchanges-test.cxx @@ -0,0 +1,108 @@ +/* -*- 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 + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +/* Implementation of calc Record Changes test */ + +class ScRecordChangesTest : public UnoApiTest +{ +public: + ScRecordChangesTest(); + + void testSetRecordChanges(); + void testCheckRecordChangesProtection(); + + CPPUNIT_TEST_SUITE(ScRecordChangesTest); + CPPUNIT_TEST(testSetRecordChanges); + CPPUNIT_TEST(testCheckRecordChangesProtection); + CPPUNIT_TEST_SUITE_END(); + +}; + +void ScRecordChangesTest::testSetRecordChanges() +{ + + uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop("private:factory/scalc"); + + uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW); + uno::Reference< beans::XPropertySet > xDocSettingsPropSet (xDoc, UNO_QUERY_THROW); + + bool recordChangesValue; + bool protectionValue; + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") >>= protectionValue); + + CPPUNIT_ASSERT_MESSAGE("a new document does not record changes", !recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("a new document does not protect record changes", !protectionValue); + + // now activate recording + uno::Any xValue;; + xValue <<= true; + xDocSettingsPropSet->setPropertyValue("RecordChanges", xValue); + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("the document should record changes", recordChangesValue); + + closeDocument(xComponent); +} + +void ScRecordChangesTest::testCheckRecordChangesProtection() +{ + // test with protected changes + OUString aFileName; + createFileURL( "RecordChangesProtected.ods", aFileName); + uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop(aFileName); + + uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW); + uno::Reference< beans::XPropertySet > xDocSettingsPropSet (xDoc, UNO_QUERY_THROW); + + bool recordChangesValue; + bool protectionValue; + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") >>= protectionValue); + + CPPUNIT_ASSERT_MESSAGE("the document should be recording changes", recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("the protection should be active", protectionValue); + + // try to de-activate recording + uno::Any xValue;; + xValue <<= false; + xDocSettingsPropSet->setPropertyValue("RecordChanges", xValue); + + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue); + CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") >>= protectionValue); + + // this document should still record changes as protection is set + CPPUNIT_ASSERT_MESSAGE("the document should still be recording changes", recordChangesValue); + CPPUNIT_ASSERT_MESSAGE("the protection should still be active", protectionValue); + + closeDocument(xComponent); +} + +ScRecordChangesTest::ScRecordChangesTest() + : UnoApiTest("/sc/qa/extras/testdocuments") +{ +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScRecordChangesTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/testdocuments/RecordChangesProtected.ods b/sc/qa/extras/testdocuments/RecordChangesProtected.ods new file mode 100644 index 000000000000..fac012d84c2a Binary files /dev/null and b/sc/qa/extras/testdocuments/RecordChangesProtected.ods differ -- cgit