LCOV - code coverage report
Current view: top level - salhelper/qa - test_api.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 117 128 91.4 %
Date: 2015-06-13 12:38:46 Functions: 35 37 94.6 %
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           1 : std::type_info const & getConditionTypeInfo()
      35           1 : { return typeid (salhelper::Condition *); }
      36             : 
      37           1 : std::type_info const & getConditionModifierTypeInfo()
      38           1 : { return typeid (salhelper::ConditionModifier *); }
      39             : 
      40           1 : std::type_info const & getConditionWaiterTypeInfo()
      41           1 : { return typeid (salhelper::ConditionWaiter *); }
      42             : 
      43           1 : std::type_info const & getORealDynamicLoaderTypeInfo()
      44           1 : { return typeid (salhelper::ORealDynamicLoader *); }
      45             : 
      46           1 : std::type_info const & getSimpleReferenceObjectTypeInfo()
      47           1 : { 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           4 : class DerivedCondition: public salhelper::Condition {
      63             : public:
      64           2 :     explicit DerivedCondition(osl::Mutex & mutex): Condition(mutex) {}
      65             : 
      66             : protected:
      67           0 :     virtual bool applies() const SAL_OVERRIDE { return false; }
      68             : };
      69             : 
      70           5 : class DerivedConditionWaiterTimedout:
      71             :     public salhelper::ConditionWaiter::timedout
      72             : {};
      73             : 
      74           6 : class DerivedSimpleReferenceObject: public salhelper::SimpleReferenceObject {};
      75             : 
      76          27 : 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           2 :     CPPUNIT_TEST_SUITE(Test);
      97           1 :     CPPUNIT_TEST(testCondition);
      98           1 :     CPPUNIT_TEST(testConditionModifier);
      99           1 :     CPPUNIT_TEST(testConditionWaiter);
     100           1 :     CPPUNIT_TEST(testConditionWaiterTimedout);
     101           1 :     CPPUNIT_TEST(testORealDynamicLoader);
     102           1 :     CPPUNIT_TEST(testSimpleReferenceObject);
     103           1 :     CPPUNIT_TEST(testDerivedCondition);
     104           1 :     CPPUNIT_TEST(testDerivedConditionWaiterTimedout);
     105           1 :     CPPUNIT_TEST(testDerivedSimpleReferenceObject);
     106           5 :     CPPUNIT_TEST_SUITE_END();
     107             : };
     108             : 
     109           1 : void Test::testCondition() {
     110           1 :     osl::Mutex mutex;
     111           2 :     boost::scoped_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
     112           1 :     CPPUNIT_ASSERT(typeid (*p.get()) != typeid (salhelper::Condition));
     113           1 :     CPPUNIT_ASSERT(typeid (p.get()) == typeid (salhelper::Condition *));
     114           2 :     CPPUNIT_ASSERT(
     115             :         typeid (const_cast< salhelper::Condition const * >(p.get()))
     116           1 :         == typeid (salhelper::Condition const *));
     117           2 :     CPPUNIT_ASSERT(
     118             :         typeid (const_cast< salhelper::Condition volatile * >(p.get()))
     119           1 :         == typeid (salhelper::Condition volatile *));
     120           2 :     CPPUNIT_ASSERT(typeid (salhelper::Condition *) == getConditionTypeInfo());
     121           1 : }
     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           1 : void Test::testConditionModifier() {
     131           1 :     salhelper::ConditionModifier * p = 0;
     132           1 :     CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionModifier));
     133           1 :     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionModifier *));
     134           2 :     CPPUNIT_ASSERT(
     135             :         typeid (const_cast< salhelper::ConditionModifier const * >(p))
     136           1 :         == typeid (salhelper::ConditionModifier const *));
     137           2 :     CPPUNIT_ASSERT(
     138             :         typeid (const_cast< salhelper::ConditionModifier volatile * >(p))
     139           1 :         == typeid (salhelper::ConditionModifier volatile *));
     140           2 :     CPPUNIT_ASSERT(
     141             :         typeid (salhelper::ConditionModifier *)
     142           1 :         == getConditionModifierTypeInfo());
     143           1 : }
     144             : 
     145           1 : void Test::testConditionWaiter() {
     146           1 :     salhelper::ConditionWaiter * p = 0;
     147           1 :     CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionWaiter));
     148           1 :     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionWaiter *));
     149           2 :     CPPUNIT_ASSERT(
     150             :         typeid (const_cast< salhelper::ConditionWaiter const * >(p))
     151           1 :         == typeid (salhelper::ConditionWaiter const *));
     152           2 :     CPPUNIT_ASSERT(
     153             :         typeid (const_cast< salhelper::ConditionWaiter volatile * >(p))
     154           1 :         == typeid (salhelper::ConditionWaiter volatile *));
     155           2 :     CPPUNIT_ASSERT(
     156           1 :         typeid (salhelper::ConditionWaiter *) == getConditionWaiterTypeInfo());
     157           1 : }
     158             : 
     159           1 : void Test::testConditionWaiterTimedout() {
     160           1 :     salhelper::ConditionWaiter::timedout x;
     161           1 :     CPPUNIT_ASSERT(typeid (x) == typeid (salhelper::ConditionWaiter::timedout));
     162           2 :     CPPUNIT_ASSERT(
     163           1 :         typeid (&x) == typeid (salhelper::ConditionWaiter::timedout *));
     164           2 :     CPPUNIT_ASSERT(
     165             :         typeid (const_cast< salhelper::ConditionWaiter::timedout const * >(&x))
     166           1 :         == typeid (salhelper::ConditionWaiter::timedout const *));
     167           2 :     CPPUNIT_ASSERT(
     168             :         (typeid
     169             :          (const_cast< salhelper::ConditionWaiter::timedout volatile * >(&x)))
     170           1 :         == typeid (salhelper::ConditionWaiter::timedout volatile *));
     171             :     try {
     172           1 :         throw salhelper::ConditionWaiter::timedout();
     173           1 :     } catch (salhelper::ConditionWaiter::timedout &) {
     174           0 :     } catch (...) {
     175           0 :         CPPUNIT_FAIL("not caught");
     176           1 :     }
     177           1 : }
     178             : 
     179           1 : void Test::testORealDynamicLoader() {
     180           1 :     salhelper::ORealDynamicLoader * p = 0;
     181           1 :     CPPUNIT_ASSERT(typeid (p) != typeid (salhelper::ORealDynamicLoader));
     182           1 :     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ORealDynamicLoader *));
     183           2 :     CPPUNIT_ASSERT(
     184             :         typeid (const_cast< salhelper::ORealDynamicLoader const * >(p))
     185           1 :         == typeid (salhelper::ORealDynamicLoader const *));
     186           2 :     CPPUNIT_ASSERT(
     187             :         typeid (const_cast< salhelper::ORealDynamicLoader volatile * >(p))
     188           1 :         == typeid (salhelper::ORealDynamicLoader volatile *));
     189           2 :     CPPUNIT_ASSERT(
     190             :         typeid (salhelper::ORealDynamicLoader *)
     191           1 :         == getORealDynamicLoaderTypeInfo());
     192           1 : }
     193             : 
     194             : #ifdef _MSC_VER
     195             : #pragma warning (pop)
     196             : #endif
     197             : 
     198           1 : void Test::testSimpleReferenceObject() {
     199           1 :     salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
     200             :     try {
     201           2 :         CPPUNIT_ASSERT(
     202           1 :             typeid (*p) != typeid (salhelper::SimpleReferenceObject));
     203           2 :         CPPUNIT_ASSERT(
     204           1 :             typeid (p) == typeid (salhelper::SimpleReferenceObject *));
     205           2 :         CPPUNIT_ASSERT(
     206             :             typeid (const_cast< salhelper::SimpleReferenceObject const * >(p))
     207           1 :             == typeid (salhelper::SimpleReferenceObject const *));
     208           2 :         CPPUNIT_ASSERT(
     209             :             (typeid
     210             :              (const_cast< salhelper::SimpleReferenceObject volatile * >(p)))
     211           1 :             == typeid (salhelper::SimpleReferenceObject volatile *));
     212           2 :         CPPUNIT_ASSERT(
     213             :             typeid (salhelper::SimpleReferenceObject *)
     214           1 :             == getSimpleReferenceObjectTypeInfo());
     215           0 :     } catch (...) {
     216           0 :         delete static_cast< DerivedSimpleReferenceObject * >(p);
     217           0 :         throw;
     218             :     }
     219           1 :     delete static_cast< DerivedSimpleReferenceObject * >(p);
     220           1 : }
     221             : 
     222           1 : void Test::testDerivedCondition() {
     223           1 :     osl::Mutex mutex;
     224           2 :     boost::scoped_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
     225           2 :     CPPUNIT_ASSERT(dynamic_cast< DerivedCondition * >(p.get()) != 0);
     226           1 : }
     227             : 
     228           1 : void Test::testDerivedConditionWaiterTimedout() {
     229             :     boost::scoped_ptr< salhelper::ConditionWaiter::timedout > p(
     230           1 :         new DerivedConditionWaiterTimedout);
     231           2 :     CPPUNIT_ASSERT(
     232           1 :         dynamic_cast< DerivedConditionWaiterTimedout * >(p.get()) != 0);
     233             :     try {
     234           1 :         throw DerivedConditionWaiterTimedout();
     235           1 :     } catch (salhelper::ConditionWaiter::timedout &) {
     236           0 :     } catch (...) {
     237           0 :         CPPUNIT_FAIL("not caught");
     238           1 :     }
     239           1 : }
     240             : 
     241           1 : void Test::testDerivedSimpleReferenceObject() {
     242           1 :     salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
     243             :     try {
     244           1 :         CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject * >(p) != 0);
     245           0 :     } catch (...) {
     246           0 :         delete static_cast< DerivedSimpleReferenceObject * >(p);
     247           0 :         throw;
     248             :     }
     249           1 :     delete static_cast< DerivedSimpleReferenceObject * >(p);
     250           1 : }
     251             : 
     252           1 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     253             : 
     254             : }
     255             : 
     256           4 : CPPUNIT_PLUGIN_IMPLEMENT();
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11