LCOV - code coverage report
Current view: top level - testtools/source/bridgetest - currentcontextchecker.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 23 25 92.0 %
Date: 2014-11-03 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          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           8 : CurrentContext::CurrentContext() {}
      60             : 
      61          16 : CurrentContext::~CurrentContext() {}
      62             : 
      63           8 : css::uno::Any CurrentContext::getValueByName(OUString const & Name)
      64             :     throw (css::uno::RuntimeException, std::exception)
      65             : {
      66           8 :     return Name == KEY
      67             :         ? css::uno::makeAny(OUString::createFromAscii(VALUE))
      68           8 :         : css::uno::Any();
      69             : }
      70             : 
      71             : }
      72             : 
      73          16 : testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
      74             : 
      75          32 : testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
      76             : 
      77          24 : sal_Bool testtools::bridgetest::CurrentContextChecker::perform(
      78             :     css::uno::Reference<
      79             :         ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
      80             :     ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
      81             :     throw (css::uno::RuntimeException, std::exception)
      82             : {
      83          24 :     if (setSteps == 0) {
      84           8 :         css::uno::ContextLayer layer(new CurrentContext);
      85           8 :         return performCheck(other, setSteps, checkSteps);
      86             :     } else {
      87          16 :         return performCheck(other, setSteps, checkSteps);
      88             :     }
      89             : }
      90             : 
      91          24 : bool testtools::bridgetest::CurrentContextChecker::performCheck(
      92             :     css::uno::Reference<
      93             :         ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
      94             :     ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
      95             : {
      96             :     OSL_ASSERT(other.is() && checkSteps >= 0);
      97          24 :     if (checkSteps == 0) {
      98             :         css::uno::Reference< css::uno::XCurrentContext > context(
      99           8 :             css::uno::getCurrentContext());
     100           8 :         if (!context.is()) {
     101           0 :             return false;
     102             :         }
     103             :         css::uno::Any a(
     104          16 :             context->getValueByName(OUString::createFromAscii(KEY)));
     105           8 :         if (a.getValueType() != ::cppu::UnoType< OUString >::get()) {
     106           0 :             return false;
     107             :         }
     108          16 :         OUString s;
     109           8 :         OSL_VERIFY(a >>= s);
     110          16 :         return s == VALUE;
     111             :     } else {
     112          16 :         return other->perform(
     113          16 :             this, setSteps >= 0 ? setSteps - 1 : -1, checkSteps - 1);
     114             :     }
     115             : }
     116             : 
     117             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10