LCOV - code coverage report
Current view: top level - testtools/source/bridgetest - currentcontextchecker.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 25 0.0 %
Date: 2014-04-14 Functions: 0 9 0.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           0 : CurrentContext::CurrentContext() {}
      60             : 
      61           0 : CurrentContext::~CurrentContext() {}
      62             : 
      63           0 : css::uno::Any CurrentContext::getValueByName(OUString const & Name)
      64             :     throw (css::uno::RuntimeException, std::exception)
      65             : {
      66           0 :     return Name == KEY
      67             :         ? css::uno::makeAny(OUString::createFromAscii(VALUE))
      68           0 :         : css::uno::Any();
      69             : }
      70             : 
      71             : }
      72             : 
      73           0 : testtools::bridgetest::CurrentContextChecker::CurrentContextChecker() {}
      74             : 
      75           0 : testtools::bridgetest::CurrentContextChecker::~CurrentContextChecker() {}
      76             : 
      77           0 : 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           0 :     if (setSteps == 0) {
      84           0 :         css::uno::ContextLayer layer(new CurrentContext);
      85           0 :         return performCheck(other, setSteps, checkSteps);
      86             :     } else {
      87           0 :         return performCheck(other, setSteps, checkSteps);
      88             :     }
      89             : }
      90             : 
      91           0 : 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           0 :     if (checkSteps == 0) {
      98             :         css::uno::Reference< css::uno::XCurrentContext > context(
      99           0 :             css::uno::getCurrentContext());
     100           0 :         if (!context.is()) {
     101           0 :             return false;
     102             :         }
     103             :         css::uno::Any a(
     104           0 :             context->getValueByName(OUString::createFromAscii(KEY)));
     105           0 :         if (a.getValueType() != ::cppu::UnoType< OUString >::get()) {
     106           0 :             return false;
     107             :         }
     108           0 :         OUString s;
     109           0 :         OSL_VERIFY(a >>= s);
     110           0 :         return s == VALUE;
     111             :     } else {
     112           0 :         return other->perform(
     113           0 :             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