merge the formfield patch from ooo-build
[ooovba.git] / testtools / source / bridgetest / currentcontextchecker.cxx
blob6fb459963b006df245847de6dea8b8ee494c9620
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: currentcontextchecker.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_testtools.hxx"
34 #include "sal/config.h"
36 #include "currentcontextchecker.hxx"
38 #include "com/sun/star/uno/Any.hxx"
39 #include "com/sun/star/uno/Reference.hxx"
40 #include "com/sun/star/uno/RuntimeException.hpp"
41 #include "com/sun/star/uno/XCurrentContext.hpp"
42 #include "cppu/unotype.hxx"
43 #include "cppuhelper/implbase1.hxx"
44 #include "osl/diagnose.h"
45 #include "osl/diagnose.hxx"
46 #include "rtl/string.h"
47 #include "rtl/ustring.hxx"
48 #include "sal/types.h"
49 #include "test/testtools/bridgetest/XCurrentContextChecker.hpp"
50 #include "uno/current_context.hxx"
52 namespace {
54 namespace css = ::com::sun::star;
56 static char const key[] = "testtools.bridgetest.Key";
57 static char const value[] = "good";
59 class CurrentContext:
60 public ::osl::DebugBase< CurrentContext >,
61 public ::cppu::WeakImplHelper1< css::uno::XCurrentContext >
63 public:
64 CurrentContext();
66 virtual ~CurrentContext();
68 virtual css::uno::Any SAL_CALL getValueByName(::rtl::OUString const & Name)
69 throw (css::uno::RuntimeException);
71 private:
72 CurrentContext(CurrentContext &); // not defined
73 void operator =(CurrentContext &); // not defined
76 CurrentContext::CurrentContext() {}
78 CurrentContext::~CurrentContext() {}
80 css::uno::Any CurrentContext::getValueByName(::rtl::OUString const & Name)
81 throw (css::uno::RuntimeException)
83 return Name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(key))
84 ? css::uno::makeAny(::rtl::OUString::createFromAscii(value))
85 : css::uno::Any();
90 testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
92 testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
94 ::sal_Bool testtools::bridgetest::CurrentContextChecker::perform(
95 css::uno::Reference<
96 ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
97 ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
98 throw (css::uno::RuntimeException)
100 if (setSteps == 0) {
101 css::uno::ContextLayer layer(new CurrentContext);
102 return performCheck(other, setSteps, checkSteps);
103 } else {
104 return performCheck(other, setSteps, checkSteps);
108 bool testtools::bridgetest::CurrentContextChecker::performCheck(
109 css::uno::Reference<
110 ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
111 ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
113 OSL_ASSERT(other.is() && checkSteps >= 0);
114 if (checkSteps == 0) {
115 css::uno::Reference< css::uno::XCurrentContext > context(
116 css::uno::getCurrentContext());
117 if (!context.is()) {
118 return false;
120 css::uno::Any a(
121 context->getValueByName(::rtl::OUString::createFromAscii(key)));
122 if (a.getValueType() != ::cppu::UnoType< ::rtl::OUString >::get()) {
123 return false;
125 ::rtl::OUString s;
126 OSL_VERIFY(a >>= s);
127 return s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(value));
128 } else {
129 return other->perform(
130 this, setSteps >= 0 ? setSteps - 1 : -1, checkSteps - 1);