jl165 merging heads
[LibreOffice.git] / testtools / source / bridgetest / currentcontextchecker.cxx
blobe7e4ec858b7b9f63710ec44f1a47d15f38b0f635
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"
49 namespace {
51 namespace css = ::com::sun::star;
53 static char const KEY[] = "testtools.bridgetest.Key";
54 static char const VALUE[] = "good";
56 class CurrentContext:
57 public ::osl::DebugBase< CurrentContext >,
58 public ::cppu::WeakImplHelper1< css::uno::XCurrentContext >
60 public:
61 CurrentContext();
63 virtual ~CurrentContext();
65 virtual css::uno::Any SAL_CALL getValueByName(::rtl::OUString const & Name)
66 throw (css::uno::RuntimeException);
68 private:
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))
82 : css::uno::Any();
87 testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
89 testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
91 ::sal_Bool testtools::bridgetest::CurrentContextChecker::perform(
92 css::uno::Reference<
93 ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
94 ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
95 throw (css::uno::RuntimeException)
97 if (setSteps == 0) {
98 css::uno::ContextLayer layer(new CurrentContext);
99 return performCheck(other, setSteps, checkSteps);
100 } else {
101 return performCheck(other, setSteps, checkSteps);
105 bool testtools::bridgetest::CurrentContextChecker::performCheck(
106 css::uno::Reference<
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());
114 if (!context.is()) {
115 return false;
117 css::uno::Any a(
118 context->getValueByName(::rtl::OUString::createFromAscii(KEY)));
119 if (a.getValueType() != ::cppu::UnoType< ::rtl::OUString >::get()) {
120 return false;
122 ::rtl::OUString s;
123 OSL_VERIFY(a >>= s);
124 return s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(VALUE));
125 } else {
126 return other->perform(
127 this, setSteps >= 0 ? setSteps - 1 : -1, checkSteps - 1);