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 "boost/noncopyable.hpp"
26 #include "com/sun/star/uno/Any.hxx"
27 #include "com/sun/star/uno/Reference.hxx"
28 #include "com/sun/star/uno/RuntimeException.hpp"
29 #include "com/sun/star/uno/XCurrentContext.hpp"
30 #include "cppu/unotype.hxx"
31 #include "cppuhelper/implbase1.hxx"
32 #include "osl/diagnose.h"
33 #include "osl/diagnose.hxx"
34 #include "rtl/string.h"
35 #include "rtl/ustring.hxx"
36 #include "sal/types.h"
37 #include "test/testtools/bridgetest/XCurrentContextChecker.hpp"
38 #include "uno/current_context.hxx"
42 static char const KEY
[] = "testtools.bridgetest.Key";
43 static char const VALUE
[] = "good";
46 public ::osl::DebugBase
< CurrentContext
>,
47 public ::cppu::WeakImplHelper1
< css::uno::XCurrentContext
>,
48 private boost::noncopyable
53 virtual ~CurrentContext();
55 virtual css::uno::Any SAL_CALL
getValueByName(OUString
const & Name
)
56 throw (css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
59 CurrentContext::CurrentContext() {}
61 CurrentContext::~CurrentContext() {}
63 css::uno::Any
CurrentContext::getValueByName(OUString
const & Name
)
64 throw (css::uno::RuntimeException
, std::exception
)
66 return Name
== KEY
? css::uno::makeAny(OUString(VALUE
)) : css::uno::Any();
71 testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
73 testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
75 sal_Bool
testtools::bridgetest::CurrentContextChecker::perform(
77 ::test::testtools::bridgetest::XCurrentContextChecker
> const & other
,
78 ::sal_Int32 setSteps
, ::sal_Int32 checkSteps
)
79 throw (css::uno::RuntimeException
, std::exception
)
82 css::uno::ContextLayer
layer(new CurrentContext
);
83 return performCheck(other
, setSteps
, checkSteps
);
85 return performCheck(other
, setSteps
, checkSteps
);
89 bool testtools::bridgetest::CurrentContextChecker::performCheck(
91 ::test::testtools::bridgetest::XCurrentContextChecker
> const & other
,
92 ::sal_Int32 setSteps
, ::sal_Int32 checkSteps
)
94 OSL_ASSERT(other
.is() && checkSteps
>= 0);
95 if (checkSteps
== 0) {
96 css::uno::Reference
< css::uno::XCurrentContext
> context(
97 css::uno::getCurrentContext());
101 css::uno::Any
a(context
->getValueByName(KEY
));
102 if (a
.getValueType() != ::cppu::UnoType
< OUString
>::get()) {
109 return other
->perform(
110 this, setSteps
>= 0 ? setSteps
- 1 : -1, checkSteps
- 1);
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */