Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "sal/config.h"
22 :
23 : #include "currentcontextchecker.hxx"
24 :
25 : #include "boost/noncopyable.hpp"
26 : #include "com/sun/star/uno/Any.hxx"
27 : #include "com/sun/star/uno/Reference.hxx"
28 : #include "com/sun/star/uno/RuntimeException.hpp"
29 : #include "com/sun/star/uno/XCurrentContext.hpp"
30 : #include "cppu/unotype.hxx"
31 : #include "cppuhelper/implbase1.hxx"
32 : #include "osl/diagnose.h"
33 : #include "osl/diagnose.hxx"
34 : #include "rtl/string.h"
35 : #include "rtl/ustring.hxx"
36 : #include "sal/types.h"
37 : #include "test/testtools/bridgetest/XCurrentContextChecker.hpp"
38 : #include "uno/current_context.hxx"
39 :
40 : namespace {
41 :
42 : static char const KEY[] = "testtools.bridgetest.Key";
43 : static char const VALUE[] = "good";
44 :
45 : class CurrentContext:
46 : public ::osl::DebugBase< CurrentContext >,
47 : public ::cppu::WeakImplHelper1< css::uno::XCurrentContext >,
48 : private boost::noncopyable
49 : {
50 : public:
51 : CurrentContext();
52 :
53 : virtual ~CurrentContext();
54 :
55 : virtual css::uno::Any SAL_CALL getValueByName(OUString const & Name)
56 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
57 : };
58 :
59 4 : CurrentContext::CurrentContext() {}
60 :
61 8 : CurrentContext::~CurrentContext() {}
62 :
63 4 : css::uno::Any CurrentContext::getValueByName(OUString const & Name)
64 : throw (css::uno::RuntimeException, std::exception)
65 : {
66 4 : return Name == KEY ? css::uno::makeAny(OUString(VALUE)) : css::uno::Any();
67 : }
68 :
69 : }
70 :
71 8 : testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
72 :
73 16 : testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
74 :
75 12 : sal_Bool testtools::bridgetest::CurrentContextChecker::perform(
76 : css::uno::Reference<
77 : ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
78 : ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
79 : throw (css::uno::RuntimeException, std::exception)
80 : {
81 12 : if (setSteps == 0) {
82 4 : css::uno::ContextLayer layer(new CurrentContext);
83 4 : return performCheck(other, setSteps, checkSteps);
84 : } else {
85 8 : return performCheck(other, setSteps, checkSteps);
86 : }
87 : }
88 :
89 12 : bool testtools::bridgetest::CurrentContextChecker::performCheck(
90 : css::uno::Reference<
91 : ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
92 : ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
93 : {
94 : OSL_ASSERT(other.is() && checkSteps >= 0);
95 12 : if (checkSteps == 0) {
96 : css::uno::Reference< css::uno::XCurrentContext > context(
97 4 : css::uno::getCurrentContext());
98 4 : if (!context.is()) {
99 0 : return false;
100 : }
101 8 : css::uno::Any a(context->getValueByName(KEY));
102 4 : if (a.getValueType() != ::cppu::UnoType< OUString >::get()) {
103 0 : return false;
104 : }
105 8 : OUString s;
106 4 : OSL_VERIFY(a >>= s);
107 8 : return s == VALUE;
108 : } else {
109 8 : return other->perform(
110 8 : this, setSteps >= 0 ? setSteps - 1 : -1, checkSteps - 1);
111 : }
112 : }
113 :
114 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|