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/implbase1.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::WeakImplHelper1
< css::uno::XCurrentContext
>
51 virtual ~CurrentContext();
53 virtual css::uno::Any SAL_CALL
getValueByName(OUString
const & Name
)
54 throw (css::uno::RuntimeException
);
57 CurrentContext(CurrentContext
&); // not defined
58 void operator =(CurrentContext
&); // not defined
61 CurrentContext::CurrentContext() {}
63 CurrentContext::~CurrentContext() {}
65 css::uno::Any
CurrentContext::getValueByName(OUString
const & Name
)
66 throw (css::uno::RuntimeException
)
69 ? css::uno::makeAny(OUString::createFromAscii(VALUE
))
75 testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
77 testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
79 ::sal_Bool
testtools::bridgetest::CurrentContextChecker::perform(
81 ::test::testtools::bridgetest::XCurrentContextChecker
> const & other
,
82 ::sal_Int32 setSteps
, ::sal_Int32 checkSteps
)
83 throw (css::uno::RuntimeException
)
86 css::uno::ContextLayer
layer(new CurrentContext
);
87 return performCheck(other
, setSteps
, checkSteps
);
89 return performCheck(other
, setSteps
, checkSteps
);
93 bool testtools::bridgetest::CurrentContextChecker::performCheck(
95 ::test::testtools::bridgetest::XCurrentContextChecker
> const & other
,
96 ::sal_Int32 setSteps
, ::sal_Int32 checkSteps
)
98 OSL_ASSERT(other
.is() && checkSteps
>= 0);
99 if (checkSteps
== 0) {
100 css::uno::Reference
< css::uno::XCurrentContext
> context(
101 css::uno::getCurrentContext());
106 context
->getValueByName(OUString::createFromAscii(KEY
)));
107 if (a
.getValueType() != ::cppu::UnoType
< OUString
>::get()) {
114 return other
->perform(
115 this, setSteps
>= 0 ? setSteps
- 1 : -1, checkSteps
- 1);
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */