LCOV - code coverage report
Current view: top level - unoxml/source/events - testlistener.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 45 0.0 %
Date: 2014-04-11 Functions: 0 10 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             : #include <stdio.h>
      20             : 
      21             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      22             : #include <cppuhelper/supportsservice.hxx>
      23             : 
      24             : #include "testlistener.hxx"
      25             : 
      26             : #define U2S(s) OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()
      27             : 
      28             : 
      29             : using ::com::sun::star::lang::XMultiServiceFactory;
      30             : using ::com::sun::star::lang::IllegalArgumentException;
      31             : 
      32             : 
      33             : namespace DOM { namespace events
      34             : {
      35             : 
      36           0 :     Reference< XInterface > CTestListener::_getInstance(const Reference< XMultiServiceFactory >& rSMgr)
      37             :     {
      38             :         // XXX
      39             :         // return static_cast< XXPathAPI* >(new CTestListener());
      40           0 :         return Reference< XInterface >(static_cast<XEventListener*>(new CTestListener(rSMgr)));
      41             :     }
      42             : 
      43             :     const char* CTestListener::aImplementationName = "com.sun.star.comp.xml.dom.events.TestListener";
      44             :     const char* CTestListener::aSupportedServiceNames[] = {
      45             :         "com.sun.star.comp.xml.dom.events.TestListener",
      46             :         NULL
      47             :     };
      48             : 
      49           0 :     OUString CTestListener::_getImplementationName()
      50             :     {
      51           0 :         return OUString::createFromAscii(aImplementationName);
      52             :     }
      53           0 :     Sequence<OUString> CTestListener::_getSupportedServiceNames()
      54             :     {
      55           0 :         Sequence<OUString> aSequence;
      56           0 :         for (int i=0; aSupportedServiceNames[i]!=NULL; i++) {
      57           0 :             aSequence.realloc(i+1);
      58           0 :             aSequence[i]=(OUString::createFromAscii(aSupportedServiceNames[i]));
      59             :         }
      60           0 :         return aSequence;
      61             :     }
      62             : 
      63           0 :     Sequence< OUString > SAL_CALL CTestListener::getSupportedServiceNames()
      64             :         throw (RuntimeException, std::exception)
      65             :     {
      66           0 :         return CTestListener::_getSupportedServiceNames();
      67             :     }
      68             : 
      69           0 :     OUString SAL_CALL CTestListener::getImplementationName()
      70             :         throw (RuntimeException, std::exception)
      71             :     {
      72           0 :         return CTestListener::_getImplementationName();
      73             :     }
      74             : 
      75           0 :     sal_Bool SAL_CALL CTestListener::supportsService(const OUString& aServiceName)
      76             :         throw (RuntimeException, std::exception)
      77             :     {
      78           0 :         return cppu::supportsService(this, aServiceName);
      79             :     }
      80             : 
      81             :     // --- XInitialize
      82             : 
      83           0 :     void SAL_CALL CTestListener::initialize(const Sequence< Any >& args) throw(RuntimeException, std::exception)
      84             :     {
      85           0 :         if (args.getLength() < 3) throw IllegalArgumentException(
      86           0 :             "Wrong number of arguments", Reference< XInterface >(), 0);
      87             : 
      88           0 :         Reference <XEventTarget> aTarget;
      89           0 :         if(! (args[0] >>= aTarget)) throw IllegalArgumentException(
      90           0 :                 "Illegal argument 1", Reference< XInterface >(), 1);
      91             : 
      92           0 :         OUString aType;
      93           0 :         if (! (args[1] >>= aType))
      94           0 :             throw IllegalArgumentException("Illegal argument 2", Reference< XInterface >(), 2);
      95             : 
      96           0 :         sal_Bool bCapture = sal_False;
      97           0 :         if(! (args[2]  >>=  bCapture)) throw IllegalArgumentException(
      98           0 :             "Illegal argument 3", Reference< XInterface >(), 3);
      99             : 
     100           0 :         if(! (args[3] >>= m_name)) m_name = "<unnamed listener>";
     101             : 
     102           0 :         m_target = aTarget;
     103           0 :         m_type = aType;
     104           0 :         m_capture = bCapture;
     105             : 
     106           0 :         m_target->addEventListener(m_type, Reference< XEventListener >(this), m_capture);
     107             : 
     108             : 
     109           0 :     }
     110             : 
     111           0 :     CTestListener::~CTestListener()
     112             :     {
     113           0 :         fprintf(stderr, "CTestListener::~CTestListener()\n");
     114           0 :         if( m_target.is())
     115           0 :             m_target->removeEventListener(m_type, Reference< XEventListener >(this), m_capture);
     116           0 :     }
     117             : 
     118             :     // --- XEventListener
     119             : 
     120           0 :     void SAL_CALL CTestListener::handleEvent(const Reference< XEvent >& evt) throw (RuntimeException, std::exception)
     121             :     {
     122           0 :         FILE* f = fopen("C:\\listener.out", "a");
     123           0 :         fprintf(f, "CTestListener::handleEvent in %s\n", U2S(m_name));
     124           0 :         fprintf(f, "    type: %s\n\n", OUStringToOString(evt->getType(), RTL_TEXTENCODING_ASCII_US).getStr());
     125           0 :         fclose(f);
     126             : 
     127           0 :     }
     128             : 
     129             : }}
     130             : 
     131             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10