LCOV - code coverage report
Current view: top level - libreoffice/testtools/source/bridgetest - currentcontextchecker.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 23 25 92.0 %
Date: 2012-12-27 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 "com/sun/star/uno/Any.hxx"
      26             : #include "com/sun/star/uno/Reference.hxx"
      27             : #include "com/sun/star/uno/RuntimeException.hpp"
      28             : #include "com/sun/star/uno/XCurrentContext.hpp"
      29             : #include "cppu/unotype.hxx"
      30             : #include "cppuhelper/implbase1.hxx"
      31             : #include "osl/diagnose.h"
      32             : #include "osl/diagnose.hxx"
      33             : #include "rtl/string.h"
      34             : #include "rtl/ustring.hxx"
      35             : #include "sal/types.h"
      36             : #include "test/testtools/bridgetest/XCurrentContextChecker.hpp"
      37             : #include "uno/current_context.hxx"
      38             : 
      39             : namespace {
      40             : 
      41             : static char const KEY[] = "testtools.bridgetest.Key";
      42             : static char const VALUE[] = "good";
      43             : 
      44             : class CurrentContext:
      45             :     public ::osl::DebugBase< CurrentContext >,
      46             :     public ::cppu::WeakImplHelper1< css::uno::XCurrentContext >
      47             : {
      48             : public:
      49             :     CurrentContext();
      50             : 
      51             :     virtual ~CurrentContext();
      52             : 
      53             :     virtual css::uno::Any SAL_CALL getValueByName(::rtl::OUString const & Name)
      54             :         throw (css::uno::RuntimeException);
      55             : 
      56             : private:
      57             :     CurrentContext(CurrentContext &); // not defined
      58             :     void operator =(CurrentContext &); // not defined
      59             : };
      60             : 
      61           4 : CurrentContext::CurrentContext() {}
      62             : 
      63           8 : CurrentContext::~CurrentContext() {}
      64             : 
      65           4 : css::uno::Any CurrentContext::getValueByName(::rtl::OUString const & Name)
      66             :     throw (css::uno::RuntimeException)
      67             : {
      68           4 :     return Name == KEY
      69             :         ? css::uno::makeAny(::rtl::OUString::createFromAscii(VALUE))
      70           4 :         : css::uno::Any();
      71             : }
      72             : 
      73             : }
      74             : 
      75           8 : testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
      76             : 
      77          16 : testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
      78             : 
      79          12 : ::sal_Bool testtools::bridgetest::CurrentContextChecker::perform(
      80             :     css::uno::Reference<
      81             :         ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
      82             :     ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
      83             :     throw (css::uno::RuntimeException)
      84             : {
      85          12 :     if (setSteps == 0) {
      86           4 :         css::uno::ContextLayer layer(new CurrentContext);
      87           4 :         return performCheck(other, setSteps, checkSteps);
      88             :     } else {
      89           8 :         return performCheck(other, setSteps, checkSteps);
      90             :     }
      91             : }
      92             : 
      93          12 : bool testtools::bridgetest::CurrentContextChecker::performCheck(
      94             :     css::uno::Reference<
      95             :         ::test::testtools::bridgetest::XCurrentContextChecker > const & other,
      96             :     ::sal_Int32 setSteps, ::sal_Int32 checkSteps)
      97             : {
      98             :     OSL_ASSERT(other.is() && checkSteps >= 0);
      99          12 :     if (checkSteps == 0) {
     100             :         css::uno::Reference< css::uno::XCurrentContext > context(
     101           4 :             css::uno::getCurrentContext());
     102           4 :         if (!context.is()) {
     103           0 :             return false;
     104             :         }
     105             :         css::uno::Any a(
     106           4 :             context->getValueByName(::rtl::OUString::createFromAscii(KEY)));
     107           4 :         if (a.getValueType() != ::cppu::UnoType< ::rtl::OUString >::get()) {
     108           0 :             return false;
     109             :         }
     110           4 :         ::rtl::OUString s;
     111           4 :         OSL_VERIFY(a >>= s);
     112           4 :         return s == VALUE;
     113             :     } else {
     114           8 :         return other->perform(
     115           8 :             this, setSteps >= 0 ? setSteps - 1 : -1, checkSteps - 1);
     116             :     }
     117             : }
     118             : 
     119             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10