nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / extras / recordchanges-test.cxx
blob709a80238af6e9b34194c9e419eca553d7464a6b
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/unoapi_test.hxx>
12 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
13 #include <com/sun/star/beans/XPropertySet.hpp>
15 #include <rtl/ustring.hxx>
17 using namespace ::com::sun::star;
18 using namespace ::com::sun::star::uno;
20 /* Implementation of calc Record Changes test */
22 class ScRecordChangesTest : public UnoApiTest
24 public:
25 ScRecordChangesTest();
27 void testSetRecordChanges();
28 void testCheckRecordChangesProtection();
30 CPPUNIT_TEST_SUITE(ScRecordChangesTest);
31 CPPUNIT_TEST(testSetRecordChanges);
32 CPPUNIT_TEST(testCheckRecordChangesProtection);
33 CPPUNIT_TEST_SUITE_END();
36 void ScRecordChangesTest::testSetRecordChanges()
38 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop("private:factory/scalc");
40 uno::Reference<sheet::XSpreadsheetDocument> xDoc(xComponent, UNO_QUERY_THROW);
41 uno::Reference<beans::XPropertySet> xDocSettingsPropSet(xDoc, UNO_QUERY_THROW);
43 bool recordChangesValue = true;
44 bool protectionValue = true;
46 CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue);
47 CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected")
48 >>= protectionValue);
50 CPPUNIT_ASSERT_MESSAGE("a new document does not record changes", !recordChangesValue);
51 CPPUNIT_ASSERT_MESSAGE("a new document does not protect record changes", !protectionValue);
53 // now activate recording
54 uno::Any aValue;
55 aValue <<= true;
56 xDocSettingsPropSet->setPropertyValue("RecordChanges", aValue);
58 CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue);
59 CPPUNIT_ASSERT_MESSAGE("the document should record changes", recordChangesValue);
61 closeDocument(xComponent);
64 void ScRecordChangesTest::testCheckRecordChangesProtection()
66 // test with protected changes
67 OUString aFileName;
68 createFileURL("RecordChangesProtected.ods", aFileName);
69 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileName);
71 uno::Reference<sheet::XSpreadsheetDocument> xDoc(xComponent, UNO_QUERY_THROW);
72 uno::Reference<beans::XPropertySet> xDocSettingsPropSet(xDoc, UNO_QUERY_THROW);
74 bool recordChangesValue = false;
75 bool protectionValue = false;
77 CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue);
78 CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected")
79 >>= protectionValue);
81 CPPUNIT_ASSERT_MESSAGE("the document should be recording changes", recordChangesValue);
82 CPPUNIT_ASSERT_MESSAGE("the protection should be active", protectionValue);
84 // try to de-activate recording
85 uno::Any aValue;
86 aValue <<= false;
87 xDocSettingsPropSet->setPropertyValue("RecordChanges", aValue);
89 CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue);
90 CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected")
91 >>= protectionValue);
93 // this document should still record changes as protection is set
94 CPPUNIT_ASSERT_MESSAGE("the document should still be recording changes", recordChangesValue);
95 CPPUNIT_ASSERT_MESSAGE("the protection should still be active", protectionValue);
97 closeDocument(xComponent);
100 ScRecordChangesTest::ScRecordChangesTest()
101 : UnoApiTest("/sc/qa/extras/testdocuments")
105 CPPUNIT_TEST_SUITE_REGISTRATION(ScRecordChangesTest);
107 CPPUNIT_PLUGIN_IMPLEMENT();
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */