calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / testtools / source / bridgetest / currentcontextchecker.cxx
blob5852f85b9cbed39d06455dc2f863ad1d7b628c69
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sal/config.h>
23 #include "currentcontextchecker.hxx"
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/uno/XCurrentContext.hpp>
28 #include <cppu/unotype.hxx>
29 #include <cppuhelper/implbase.hxx>
30 #include <osl/diagnose.h>
31 #include <osl/diagnose.hxx>
32 #include <rtl/ustring.hxx>
33 #include <sal/types.h>
34 #include <test/testtools/bridgetest/XCurrentContextChecker.hpp>
35 #include <uno/current_context.hxx>
37 namespace {
39 constexpr OUStringLiteral KEY = u"testtools.bridgetest.Key";
40 constexpr OUStringLiteral VALUE = u"good";
42 class CurrentContext:
43 public ::osl::DebugBase< CurrentContext >,
44 public ::cppu::WeakImplHelper< css::uno::XCurrentContext >
46 public:
47 CurrentContext();
49 CurrentContext(const CurrentContext&) = delete;
50 CurrentContext& operator=(const CurrentContext&) = delete;
52 virtual css::uno::Any SAL_CALL getValueByName(OUString const & Name) override;
55 CurrentContext::CurrentContext() {}
57 css::uno::Any CurrentContext::getValueByName(OUString const & Name)
59 return Name == KEY ? css::uno::Any(OUString(VALUE)) : css::uno::Any();
64 testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
66 testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
68 sal_Bool testtools::bridgetest::CurrentContextChecker::perform(
69 css::uno::Reference<
70 ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
71 ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
73 if (setSteps == 0) {
74 css::uno::ContextLayer layer(new CurrentContext);
75 return performCheck(other, setSteps, checkSteps);
76 } else {
77 return performCheck(other, setSteps, checkSteps);
81 bool testtools::bridgetest::CurrentContextChecker::performCheck(
82 css::uno::Reference<
83 ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
84 ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
86 OSL_ASSERT(other.is() && checkSteps >= 0);
87 if (checkSteps == 0) {
88 css::uno::Reference< css::uno::XCurrentContext > context(
89 css::uno::getCurrentContext());
90 if (!context.is()) {
91 return false;
93 css::uno::Any a(context->getValueByName(KEY));
94 if (a.getValueType() != ::cppu::UnoType< OUString >::get()) {
95 return false;
97 OUString s;
98 OSL_VERIFY(a >>= s);
99 return s == VALUE;
100 } else {
101 return other->perform(
102 this, setSteps >= 0 ? setSteps - 1 : -1, checkSteps - 1);
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */