summaryrefslogtreecommitdiff
path: root/sc/qa/extras/recordchanges-test.cxx
blob: 357023e0d361b6be99ffb915d4bab399b5572dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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< css::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 = true;
    bool protectionValue = true;

    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 aValue;
    aValue <<= true;
    xDocSettingsPropSet->setPropertyValue("RecordChanges", aValue);

    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< css::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 = false;
    bool protectionValue = false;

    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 aValue;
    aValue <<= false;
    xDocSettingsPropSet->setPropertyValue("RecordChanges", aValue);

    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: */