Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <test/unoapi_test.hxx>
11 :
12 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
13 : #include <com/sun/star/beans/XPropertySet.hpp>
14 :
15 : #include <rtl/ustring.hxx>
16 :
17 : using namespace ::com::sun::star;
18 : using namespace ::com::sun::star::uno;
19 :
20 : /* Implementation of calc Record Changes test */
21 :
22 4 : class ScRecordChangesTest : public UnoApiTest
23 : {
24 : public:
25 : ScRecordChangesTest();
26 :
27 : void testSetRecordChanges();
28 : void testCheckRecordChangesProtection();
29 :
30 2 : CPPUNIT_TEST_SUITE(ScRecordChangesTest);
31 1 : CPPUNIT_TEST(testSetRecordChanges);
32 1 : CPPUNIT_TEST(testCheckRecordChangesProtection);
33 5 : CPPUNIT_TEST_SUITE_END();
34 :
35 : };
36 :
37 1 : void ScRecordChangesTest::testSetRecordChanges()
38 : {
39 :
40 1 : uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop("private:factory/scalc");
41 :
42 2 : uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW);
43 2 : uno::Reference< beans::XPropertySet > xDocSettingsPropSet (xDoc, UNO_QUERY_THROW);
44 :
45 1 : bool recordChangesValue = true;
46 1 : bool protectionValue = true;
47 :
48 1 : CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue);
49 1 : CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") >>= protectionValue);
50 :
51 1 : CPPUNIT_ASSERT_MESSAGE("a new document does not record changes", !recordChangesValue);
52 1 : CPPUNIT_ASSERT_MESSAGE("a new document does not protect record changes", !protectionValue);
53 :
54 : // now activate recording
55 2 : uno::Any xValue;
56 1 : xValue <<= true;
57 1 : xDocSettingsPropSet->setPropertyValue("RecordChanges", xValue);
58 :
59 1 : CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue);
60 1 : CPPUNIT_ASSERT_MESSAGE("the document should record changes", recordChangesValue);
61 :
62 2 : closeDocument(xComponent);
63 1 : }
64 :
65 1 : void ScRecordChangesTest::testCheckRecordChangesProtection()
66 : {
67 : // test with protected changes
68 1 : OUString aFileName;
69 1 : createFileURL( "RecordChangesProtected.ods", aFileName);
70 2 : uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop(aFileName);
71 :
72 2 : uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW);
73 2 : uno::Reference< beans::XPropertySet > xDocSettingsPropSet (xDoc, UNO_QUERY_THROW);
74 :
75 1 : bool recordChangesValue = false;
76 1 : bool protectionValue = false;
77 :
78 1 : CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue);
79 1 : CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") >>= protectionValue);
80 :
81 1 : CPPUNIT_ASSERT_MESSAGE("the document should be recording changes", recordChangesValue);
82 1 : CPPUNIT_ASSERT_MESSAGE("the protection should be active", protectionValue);
83 :
84 : // try to de-activate recording
85 2 : uno::Any xValue;
86 1 : xValue <<= false;
87 1 : xDocSettingsPropSet->setPropertyValue("RecordChanges", xValue);
88 :
89 1 : CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("RecordChanges") >>= recordChangesValue);
90 1 : CPPUNIT_ASSERT(xDocSettingsPropSet->getPropertyValue("IsRecordChangesProtected") >>= protectionValue);
91 :
92 : // this document should still record changes as protection is set
93 1 : CPPUNIT_ASSERT_MESSAGE("the document should still be recording changes", recordChangesValue);
94 1 : CPPUNIT_ASSERT_MESSAGE("the protection should still be active", protectionValue);
95 :
96 2 : closeDocument(xComponent);
97 1 : }
98 :
99 2 : ScRecordChangesTest::ScRecordChangesTest()
100 2 : : UnoApiTest("/sc/qa/extras/testdocuments")
101 : {
102 2 : }
103 :
104 1 : CPPUNIT_TEST_SUITE_REGISTRATION(ScRecordChangesTest);
105 :
106 4 : CPPUNIT_PLUGIN_IMPLEMENT();
107 :
108 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|