LCOV - code coverage report
Current view: top level - salhelper/qa - test_api.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 117 128 91.4 %
Date: 2014-11-03 Functions: 32 34 94.1 %
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             : #include "sal/config.h"
      21             : 
      22             : #include <typeinfo>
      23             : 
      24             : namespace salhelper {
      25             :     class Condition;
      26             :     class ConditionModifier;
      27             :     class ConditionWaiter;
      28             :     class ORealDynamicLoader;
      29             :     class SimpleReferenceObject;
      30             : }
      31             : 
      32             : namespace {
      33             : 
      34           2 : std::type_info const & getConditionTypeInfo()
      35           2 : { return typeid (salhelper::Condition *); }
      36             : 
      37           2 : std::type_info const & getConditionModifierTypeInfo()
      38           2 : { return typeid (salhelper::ConditionModifier *); }
      39             : 
      40           2 : std::type_info const & getConditionWaiterTypeInfo()
      41           2 : { return typeid (salhelper::ConditionWaiter *); }
      42             : 
      43           2 : std::type_info const & getORealDynamicLoaderTypeInfo()
      44           2 : { return typeid (salhelper::ORealDynamicLoader *); }
      45             : 
      46           2 : std::type_info const & getSimpleReferenceObjectTypeInfo()
      47           2 : { return typeid (salhelper::SimpleReferenceObject *); }
      48             : 
      49             : }
      50             : 
      51             : #include "osl/mutex.hxx"
      52             : #include "salhelper/condition.hxx"
      53             : #include "salhelper/dynload.hxx"
      54             : #include "salhelper/simplereferenceobject.hxx"
      55             : #include <cppunit/TestFixture.h>
      56             : #include <cppunit/extensions/HelperMacros.h>
      57             : #include <cppunit/plugin/TestPlugIn.h>
      58             : #include <boost/scoped_ptr.hpp>
      59             : 
      60             : namespace {
      61             : 
      62           8 : class DerivedCondition: public salhelper::Condition {
      63             : public:
      64           4 :     explicit DerivedCondition(osl::Mutex & mutex): Condition(mutex) {}
      65             : 
      66             : protected:
      67           0 :     virtual bool applies() const SAL_OVERRIDE { return false; }
      68             : };
      69             : 
      70          10 : class DerivedConditionWaiterTimedout:
      71             :     public salhelper::ConditionWaiter::timedout
      72             : {};
      73             : 
      74          12 : class DerivedSimpleReferenceObject: public salhelper::SimpleReferenceObject {};
      75             : 
      76          54 : class Test: public CppUnit::TestFixture {
      77             : public:
      78             :     void testCondition();
      79             : 
      80             :     void testConditionModifier();
      81             : 
      82             :     void testConditionWaiter();
      83             : 
      84             :     void testConditionWaiterTimedout();
      85             : 
      86             :     void testORealDynamicLoader();
      87             : 
      88             :     void testSimpleReferenceObject();
      89             : 
      90             :     void testDerivedCondition();
      91             : 
      92             :     void testDerivedConditionWaiterTimedout();
      93             : 
      94             :     void testDerivedSimpleReferenceObject();
      95             : 
      96           4 :     CPPUNIT_TEST_SUITE(Test);
      97           2 :     CPPUNIT_TEST(testCondition);
      98           2 :     CPPUNIT_TEST(testConditionModifier);
      99           2 :     CPPUNIT_TEST(testConditionWaiter);
     100           2 :     CPPUNIT_TEST(testConditionWaiterTimedout);
     101           2 :     CPPUNIT_TEST(testORealDynamicLoader);
     102           2 :     CPPUNIT_TEST(testSimpleReferenceObject);
     103           2 :     CPPUNIT_TEST(testDerivedCondition);
     104           2 :     CPPUNIT_TEST(testDerivedConditionWaiterTimedout);
     105           2 :     CPPUNIT_TEST(testDerivedSimpleReferenceObject);
     106           4 :     CPPUNIT_TEST_SUITE_END();
     107             : };
     108             : 
     109           2 : void Test::testCondition() {
     110           2 :     osl::Mutex mutex;
     111           4 :     boost::scoped_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
     112           2 :     CPPUNIT_ASSERT(typeid (*p.get()) != typeid (salhelper::Condition));
     113           2 :     CPPUNIT_ASSERT(typeid (p.get()) == typeid (salhelper::Condition *));
     114           4 :     CPPUNIT_ASSERT(
     115             :         typeid (const_cast< salhelper::Condition const * >(p.get()))
     116           2 :         == typeid (salhelper::Condition const *));
     117           4 :     CPPUNIT_ASSERT(
     118             :         typeid (const_cast< salhelper::Condition volatile * >(p.get()))
     119           2 :         == typeid (salhelper::Condition volatile *));
     120           4 :     CPPUNIT_ASSERT(typeid (salhelper::Condition *) == getConditionTypeInfo());
     121           2 : }
     122             : 
     123             : #ifdef _MSC_VER
     124             : // MSVC 2012 warns about the "p" being unused
     125             : #pragma warning (push, 1)
     126             : #pragma warning (disable: 4189)
     127             : #endif
     128             : 
     129             : 
     130           2 : void Test::testConditionModifier() {
     131           2 :     salhelper::ConditionModifier * p = 0;
     132           2 :     CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionModifier));
     133           2 :     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionModifier *));
     134           4 :     CPPUNIT_ASSERT(
     135             :         typeid (const_cast< salhelper::ConditionModifier const * >(p))
     136           2 :         == typeid (salhelper::ConditionModifier const *));
     137           4 :     CPPUNIT_ASSERT(
     138             :         typeid (const_cast< salhelper::ConditionModifier volatile * >(p))
     139           2 :         == typeid (salhelper::ConditionModifier volatile *));
     140           4 :     CPPUNIT_ASSERT(
     141             :         typeid (salhelper::ConditionModifier *)
     142           2 :         == getConditionModifierTypeInfo());
     143           2 : }
     144             : 
     145           2 : void Test::testConditionWaiter() {
     146           2 :     salhelper::ConditionWaiter * p = 0;
     147           2 :     CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionWaiter));
     148           2 :     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionWaiter *));
     149           4 :     CPPUNIT_ASSERT(
     150             :         typeid (const_cast< salhelper::ConditionWaiter const * >(p))
     151           2 :         == typeid (salhelper::ConditionWaiter const *));
     152           4 :     CPPUNIT_ASSERT(
     153             :         typeid (const_cast< salhelper::ConditionWaiter volatile * >(p))
     154           2 :         == typeid (salhelper::ConditionWaiter volatile *));
     155           4 :     CPPUNIT_ASSERT(
     156           2 :         typeid (salhelper::ConditionWaiter *) == getConditionWaiterTypeInfo());
     157           2 : }
     158             : 
     159           2 : void Test::testConditionWaiterTimedout() {
     160           2 :     salhelper::ConditionWaiter::timedout x;
     161           2 :     CPPUNIT_ASSERT(typeid (x) == typeid (salhelper::ConditionWaiter::timedout));
     162           4 :     CPPUNIT_ASSERT(
     163           2 :         typeid (&x) == typeid (salhelper::ConditionWaiter::timedout *));
     164           4 :     CPPUNIT_ASSERT(
     165             :         typeid (const_cast< salhelper::ConditionWaiter::timedout const * >(&x))
     166           2 :         == typeid (salhelper::ConditionWaiter::timedout const *));
     167           4 :     CPPUNIT_ASSERT(
     168             :         (typeid
     169             :          (const_cast< salhelper::ConditionWaiter::timedout volatile * >(&x)))
     170           2 :         == typeid (salhelper::ConditionWaiter::timedout volatile *));
     171             :     try {
     172           2 :         throw salhelper::ConditionWaiter::timedout();
     173           2 :     } catch (salhelper::ConditionWaiter::timedout &) {
     174           0 :     } catch (...) {
     175           0 :         CPPUNIT_FAIL("not caught");
     176           2 :     }
     177           2 : }
     178             : 
     179           2 : void Test::testORealDynamicLoader() {
     180           2 :     salhelper::ORealDynamicLoader * p = 0;
     181           2 :     CPPUNIT_ASSERT(typeid (p) != typeid (salhelper::ORealDynamicLoader));
     182           2 :     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ORealDynamicLoader *));
     183           4 :     CPPUNIT_ASSERT(
     184             :         typeid (const_cast< salhelper::ORealDynamicLoader const * >(p))
     185           2 :         == typeid (salhelper::ORealDynamicLoader const *));
     186           4 :     CPPUNIT_ASSERT(
     187             :         typeid (const_cast< salhelper::ORealDynamicLoader volatile * >(p))
     188           2 :         == typeid (salhelper::ORealDynamicLoader volatile *));
     189           4 :     CPPUNIT_ASSERT(
     190             :         typeid (salhelper::ORealDynamicLoader *)
     191           2 :         == getORealDynamicLoaderTypeInfo());
     192           2 : }
     193             : 
     194             : #ifdef _MSC_VER
     195             : #pragma warning (pop)
     196             : #endif
     197             : 
     198           2 : void Test::testSimpleReferenceObject() {
     199           2 :     salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
     200             :     try {
     201           4 :         CPPUNIT_ASSERT(
     202           2 :             typeid (*p) != typeid (salhelper::SimpleReferenceObject));
     203           4 :         CPPUNIT_ASSERT(
     204           2 :             typeid (p) == typeid (salhelper::SimpleReferenceObject *));
     205           4 :         CPPUNIT_ASSERT(
     206             :             typeid (const_cast< salhelper::SimpleReferenceObject const * >(p))
     207           2 :             == typeid (salhelper::SimpleReferenceObject const *));
     208           4 :         CPPUNIT_ASSERT(
     209             :             (typeid
     210             :              (const_cast< salhelper::SimpleReferenceObject volatile * >(p)))
     211           2 :             == typeid (salhelper::SimpleReferenceObject volatile *));
     212           4 :         CPPUNIT_ASSERT(
     213             :             typeid (salhelper::SimpleReferenceObject *)
     214           2 :             == getSimpleReferenceObjectTypeInfo());
     215           0 :     } catch (...) {
     216           0 :         delete static_cast< DerivedSimpleReferenceObject * >(p);
     217           0 :         throw;
     218             :     }
     219           2 :     delete static_cast< DerivedSimpleReferenceObject * >(p);
     220           2 : }
     221             : 
     222           2 : void Test::testDerivedCondition() {
     223           2 :     osl::Mutex mutex;
     224           4 :     boost::scoped_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
     225           4 :     CPPUNIT_ASSERT(dynamic_cast< DerivedCondition * >(p.get()) != 0);
     226           2 : }
     227             : 
     228           2 : void Test::testDerivedConditionWaiterTimedout() {
     229             :     boost::scoped_ptr< salhelper::ConditionWaiter::timedout > p(
     230           2 :         new DerivedConditionWaiterTimedout);
     231           4 :     CPPUNIT_ASSERT(
     232           2 :         dynamic_cast< DerivedConditionWaiterTimedout * >(p.get()) != 0);
     233             :     try {
     234           2 :         throw DerivedConditionWaiterTimedout();
     235           2 :     } catch (salhelper::ConditionWaiter::timedout &) {
     236           0 :     } catch (...) {
     237           0 :         CPPUNIT_FAIL("not caught");
     238           2 :     }
     239           2 : }
     240             : 
     241           2 : void Test::testDerivedSimpleReferenceObject() {
     242           2 :     salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
     243             :     try {
     244           2 :         CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject * >(p) != 0);
     245           0 :     } catch (...) {
     246           0 :         delete static_cast< DerivedSimpleReferenceObject * >(p);
     247           0 :         throw;
     248             :     }
     249           2 :     delete static_cast< DerivedSimpleReferenceObject * >(p);
     250           2 : }
     251             : 
     252           2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     253             : 
     254             : }
     255             : 
     256           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10