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/RuntimeException.hpp>
28 #include <com/sun/star/uno/XCurrentContext.hpp>
29 #include <cppu/unotype.hxx>
30 #include <cppuhelper/implbase.hxx>
31 #include <osl/diagnose.h>
32 #include <osl/diagnose.hxx>
33 #include <rtl/string.h>
34 #include <rtl/ustring.hxx>
35 #include <sal/types.h>
36 #include <test/testtools/bridgetest/XCurrentContextChecker.hpp>
37 #include <uno/current_context.hxx>
41 static char const KEY
[] = "testtools.bridgetest.Key";
42 static char const VALUE
[] = "good";
45 public ::osl::DebugBase
< CurrentContext
>,
46 public ::cppu::WeakImplHelper
< css::uno::XCurrentContext
>
51 CurrentContext(const CurrentContext
&) = delete;
52 CurrentContext
& operator=(const CurrentContext
&) = delete;
54 virtual css::uno::Any SAL_CALL
getValueByName(OUString
const & Name
) override
;
57 CurrentContext::CurrentContext() {}
59 css::uno::Any
CurrentContext::getValueByName(OUString
const & Name
)
61 return Name
== KEY
? css::uno::makeAny(OUString(VALUE
)) : css::uno::Any();
66 testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
68 testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
70 sal_Bool
testtools::bridgetest::CurrentContextChecker::perform(
72 ::test::testtools::bridgetest::XCurrentContextChecker
> const & other
,
73 ::sal_Int32 setSteps
, ::sal_Int32 checkSteps
)
76 css::uno::ContextLayer
layer(new CurrentContext
);
77 return performCheck(other
, setSteps
, checkSteps
);
79 return performCheck(other
, setSteps
, checkSteps
);
83 bool testtools::bridgetest::CurrentContextChecker::performCheck(
85 ::test::testtools::bridgetest::XCurrentContextChecker
> const & other
,
86 ::sal_Int32 setSteps
, ::sal_Int32 checkSteps
)
88 OSL_ASSERT(other
.is() && checkSteps
>= 0);
89 if (checkSteps
== 0) {
90 css::uno::Reference
< css::uno::XCurrentContext
> context(
91 css::uno::getCurrentContext());
95 css::uno::Any
a(context
->getValueByName(KEY
));
96 if (a
.getValueType() != ::cppu::UnoType
< OUString
>::get()) {
103 return other
->perform(
104 this, setSteps
>= 0 ? setSteps
- 1 : -1, checkSteps
- 1);
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */