1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_testtools.hxx"
31 #include "sal/config.h"
33 #include "currentcontextchecker.hxx"
35 #include "com/sun/star/uno/Any.hxx"
36 #include "com/sun/star/uno/Reference.hxx"
37 #include "com/sun/star/uno/RuntimeException.hpp"
38 #include "com/sun/star/uno/XCurrentContext.hpp"
39 #include "cppu/unotype.hxx"
40 #include "cppuhelper/implbase1.hxx"
41 #include "osl/diagnose.h"
42 #include "osl/diagnose.hxx"
43 #include "rtl/string.h"
44 #include "rtl/ustring.hxx"
45 #include "sal/types.h"
46 #include "test/testtools/bridgetest/XCurrentContextChecker.hpp"
47 #include "uno/current_context.hxx"
51 namespace css
= ::com::sun::star
;
53 static char const KEY
[] = "testtools.bridgetest.Key";
54 static char const VALUE
[] = "good";
57 public ::osl::DebugBase
< CurrentContext
>,
58 public ::cppu::WeakImplHelper1
< css::uno::XCurrentContext
>
63 virtual ~CurrentContext();
65 virtual css::uno::Any SAL_CALL
getValueByName(::rtl::OUString
const & Name
)
66 throw (css::uno::RuntimeException
);
69 CurrentContext(CurrentContext
&); // not defined
70 void operator =(CurrentContext
&); // not defined
73 CurrentContext::CurrentContext() {}
75 CurrentContext::~CurrentContext() {}
77 css::uno::Any
CurrentContext::getValueByName(::rtl::OUString
const & Name
)
78 throw (css::uno::RuntimeException
)
80 return Name
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(KEY
))
81 ? css::uno::makeAny(::rtl::OUString::createFromAscii(VALUE
))
87 testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
89 testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
91 ::sal_Bool
testtools::bridgetest::CurrentContextChecker::perform(
93 ::test::testtools::bridgetest::XCurrentContextChecker
> const & other
,
94 ::sal_Int32 setSteps
, ::sal_Int32 checkSteps
)
95 throw (css::uno::RuntimeException
)
98 css::uno::ContextLayer
layer(new CurrentContext
);
99 return performCheck(other
, setSteps
, checkSteps
);
101 return performCheck(other
, setSteps
, checkSteps
);
105 bool testtools::bridgetest::CurrentContextChecker::performCheck(
107 ::test::testtools::bridgetest::XCurrentContextChecker
> const & other
,
108 ::sal_Int32 setSteps
, ::sal_Int32 checkSteps
)
110 OSL_ASSERT(other
.is() && checkSteps
>= 0);
111 if (checkSteps
== 0) {
112 css::uno::Reference
< css::uno::XCurrentContext
> context(
113 css::uno::getCurrentContext());
118 context
->getValueByName(::rtl::OUString::createFromAscii(KEY
)));
119 if (a
.getValueType() != ::cppu::UnoType
< ::rtl::OUString
>::get()) {
124 return s
.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(VALUE
));
126 return other
->perform(
127 this, setSteps
>= 0 ? setSteps
- 1 : -1, checkSteps
- 1);