1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
39 constexpr OUString KEY
= u
"testtools.bridgetest.Key"_ustr
;
40 constexpr OUString VALUE
= u
"good"_ustr
;
43 public ::osl::DebugBase
< CurrentContext
>,
44 public ::cppu::WeakImplHelper
< css::uno::XCurrentContext
>
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(VALUE
) : css::uno::Any();
64 testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
66 testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
68 sal_Bool
testtools::bridgetest::CurrentContextChecker::perform(
70 ::test::testtools::bridgetest::XCurrentContextChecker
> const & other
,
71 ::sal_Int32 setSteps
, ::sal_Int32 checkSteps
)
74 css::uno::ContextLayer
layer(new CurrentContext
);
75 return performCheck(other
, setSteps
, checkSteps
);
77 return performCheck(other
, setSteps
, checkSteps
);
81 bool testtools::bridgetest::CurrentContextChecker::performCheck(
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());
93 css::uno::Any
a(context
->getValueByName(KEY
));
94 if (a
.getValueType() != ::cppu::UnoType
< OUString
>::get()) {
101 return other
->perform(
102 this, setSteps
>= 0 ? setSteps
- 1 : -1, checkSteps
- 1);
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */