diff options
author | Laurent Godard <lgodard.libre@laposte.net> | 2015-02-24 09:41:44 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-02-25 00:24:18 +0000 |
commit | d60157196f34a4b08f64aa869fb104998041b688 (patch) | |
tree | fe6addf9024ee7e649fb23f51b440479d21ac810 /sc/qa/extras | |
parent | 984445841073f5bf99f0b7f87d1f8f33f07de5e5 (diff) |
calc : add UNO properties for "Record changes"
with unit testing
Change-Id: I2a0e09f699c8489f61453b4144dd6181bd9b47fd
Reviewed-on: https://gerrit.libreoffice.org/14603
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc/qa/extras')
-rw-r--r-- | sc/qa/extras/recordchanges-test.cxx | 108 | ||||
-rw-r--r-- | sc/qa/extras/testdocuments/RecordChangesProtected.ods | bin | 0 -> 14217 bytes |
2 files changed, 108 insertions, 0 deletions
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 <test/unoapi_test.hxx> + +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <rtl/ustring.hxx> + +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 Binary files differnew file mode 100644 index 000000000000..fac012d84c2a --- /dev/null +++ b/sc/qa/extras/testdocuments/RecordChangesProtected.ods |