Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "sal/config.h"
31 : :
32 : : #include "currentcontextchecker.hxx"
33 : :
34 : : #include "com/sun/star/uno/Any.hxx"
35 : : #include "com/sun/star/uno/Reference.hxx"
36 : : #include "com/sun/star/uno/RuntimeException.hpp"
37 : : #include "com/sun/star/uno/XCurrentContext.hpp"
38 : : #include "cppu/unotype.hxx"
39 : : #include "cppuhelper/implbase1.hxx"
40 : : #include "osl/diagnose.h"
41 : : #include "osl/diagnose.hxx"
42 : : #include "rtl/string.h"
43 : : #include "rtl/ustring.hxx"
44 : : #include "sal/types.h"
45 : : #include "test/testtools/bridgetest/XCurrentContextChecker.hpp"
46 : : #include "uno/current_context.hxx"
47 : :
48 : : namespace {
49 : :
50 : : namespace css = ::com::sun::star;
51 : :
52 : : static char const KEY[] = "testtools.bridgetest.Key";
53 : : static char const VALUE[] = "good";
54 : :
55 : : class CurrentContext:
56 : : public ::osl::DebugBase< CurrentContext >,
57 : : public ::cppu::WeakImplHelper1< css::uno::XCurrentContext >
58 : : {
59 : : public:
60 : : CurrentContext();
61 : :
62 : : virtual ~CurrentContext();
63 : :
64 : : virtual css::uno::Any SAL_CALL getValueByName(::rtl::OUString const & Name)
65 : : throw (css::uno::RuntimeException);
66 : :
67 : : private:
68 : : CurrentContext(CurrentContext &); // not defined
69 : : void operator =(CurrentContext &); // not defined
70 : : };
71 : :
72 : 12 : CurrentContext::CurrentContext() {}
73 : :
74 [ - + ]: 24 : CurrentContext::~CurrentContext() {}
75 : :
76 : 12 : css::uno::Any CurrentContext::getValueByName(::rtl::OUString const & Name)
77 : : throw (css::uno::RuntimeException)
78 : : {
79 : 12 : return Name == KEY
80 : : ? css::uno::makeAny(::rtl::OUString::createFromAscii(VALUE))
81 [ + - ][ + - ]: 12 : : css::uno::Any();
[ # # ][ + - ]
82 : : }
83 : :
84 : : }
85 : :
86 : 24 : testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
87 : :
88 [ - + ]: 48 : testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
89 : :
90 : 36 : ::sal_Bool testtools::bridgetest::CurrentContextChecker::perform(
91 : : css::uno::Reference<
92 : : ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
93 : : ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
94 : : throw (css::uno::RuntimeException)
95 : : {
96 [ + + ]: 36 : if (setSteps == 0) {
97 [ + - ][ + - ]: 12 : css::uno::ContextLayer layer(new CurrentContext);
[ + - ][ + - ]
98 [ + - ][ + - ]: 12 : return performCheck(other, setSteps, checkSteps);
99 : : } else {
100 : 36 : return performCheck(other, setSteps, checkSteps);
101 : : }
102 : : }
103 : :
104 : 36 : bool testtools::bridgetest::CurrentContextChecker::performCheck(
105 : : css::uno::Reference<
106 : : ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
107 : : ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
108 : : {
109 : : OSL_ASSERT(other.is() && checkSteps >= 0);
110 [ + + ]: 36 : if (checkSteps == 0) {
111 : : css::uno::Reference< css::uno::XCurrentContext > context(
112 [ + - ]: 12 : css::uno::getCurrentContext());
113 [ - + ]: 12 : if (!context.is()) {
114 : 0 : return false;
115 : : }
116 : : css::uno::Any a(
117 [ + - ][ + - ]: 12 : context->getValueByName(::rtl::OUString::createFromAscii(KEY)));
118 [ - + ]: 12 : if (a.getValueType() != ::cppu::UnoType< ::rtl::OUString >::get()) {
119 : 0 : return false;
120 : : }
121 : 12 : ::rtl::OUString s;
122 : 12 : OSL_VERIFY(a >>= s);
123 : 12 : return s == VALUE;
124 : : } else {
125 : 24 : return other->perform(
126 [ + - ][ + + ]: 36 : this, setSteps >= 0 ? setSteps - 1 : -1, checkSteps - 1);
127 : : }
128 : : }
129 : :
130 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|