LCOV - code coverage report
Current view: top level - desktop/source/deployment/misc - dp_dependencies.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 54 38.9 %
Date: 2012-08-25 Functions: 3 7 42.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 260 9.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "sal/config.h"
      30                 :            : 
      31                 :            : #include "com/sun/star/uno/Reference.hxx"
      32                 :            : #include "com/sun/star/uno/Sequence.hxx"
      33                 :            : #include "com/sun/star/xml/dom/XElement.hpp"
      34                 :            : #include "com/sun/star/xml/dom/XNodeList.hpp"
      35                 :            : #include "rtl/bootstrap.hxx"
      36                 :            : #include "rtl/string.h"
      37                 :            : #include "rtl/ustring.h"
      38                 :            : #include "rtl/ustring.hxx"
      39                 :            : #include "sal/types.h"
      40                 :            : #include "tools/resid.hxx"
      41                 :            : #include "unotools/configmgr.hxx"
      42                 :            : 
      43                 :            : #include "deployment.hrc"
      44                 :            : #include "dp_resource.h"
      45                 :            : 
      46                 :            : #include "dp_dependencies.hxx"
      47                 :            : #include "dp_descriptioninfoset.hxx"
      48                 :            : #include "dp_version.hxx"
      49                 :            : 
      50                 :            : namespace {
      51                 :            : 
      52                 :            : namespace css = com::sun::star;
      53                 :            : 
      54                 :            : static char const namespaceLibreOffice[] =
      55                 :            :     "http://libreoffice.org/extensions/description/2011";
      56                 :            : 
      57                 :            : static char const namespaceOpenOfficeOrg[] =
      58                 :            :     "http://openoffice.org/extensions/description/2006";
      59                 :            : 
      60                 :            : static char const minimalVersionLibreOffice[] = "LibreOffice-minimal-version";
      61                 :            : 
      62                 :            : static char const minimalVersionOpenOfficeOrg[] =
      63                 :            :     "OpenOffice.org-minimal-version";
      64                 :            : 
      65                 :            : static char const maximalVersionOpenOfficeOrg[] =
      66                 :            :     "OpenOffice.org-maximal-version";
      67                 :            : 
      68                 :          0 : rtl::OUString getLibreOfficeMajorMinorMicro() {
      69                 :          0 :     return utl::ConfigManager::getAboutBoxProductVersion();
      70                 :            : }
      71                 :            : 
      72                 :        496 : rtl::OUString getReferenceOpenOfficeOrgMajorMinor() {
      73                 :            :     rtl::OUString v(
      74                 :            :         RTL_CONSTASCII_USTRINGPARAM(
      75                 :            :             "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE("version")
      76                 :        496 :             ":Version:ReferenceOOoMajorMinor}"));
      77                 :        496 :     rtl::Bootstrap::expandMacros(v); //TODO: check for failure
      78                 :        496 :     return v;
      79                 :            : }
      80                 :            : 
      81                 :        496 : bool satisfiesMinimalVersion(
      82                 :            :     rtl::OUString const & actual, rtl::OUString const & specified)
      83                 :            : {
      84                 :        496 :     return dp_misc::compareVersions(actual, specified) != dp_misc::LESS;
      85                 :            : }
      86                 :            : 
      87                 :          0 : bool satisfiesMaximalVersion(
      88                 :            :     rtl::OUString const & actual, rtl::OUString const & specified)
      89                 :            : {
      90                 :          0 :     return dp_misc::compareVersions(actual, specified) != dp_misc::GREATER;
      91                 :            : }
      92                 :            : 
      93                 :          0 : rtl::OUString produceErrorText(
      94                 :            :     rtl::OUString const & reason, rtl::OUString const & version)
      95                 :            : {
      96                 :            :     return reason.replaceFirst("%VERSION",
      97                 :          0 :         (version.isEmpty()
      98                 :            :          ?  dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString()
      99 [ #  # ][ #  # ]:          0 :          : version));
         [ #  # ][ #  # ]
                 [ #  # ]
     100                 :            : }
     101                 :            : 
     102                 :            : }
     103                 :            : 
     104                 :            : namespace dp_misc {
     105                 :            : 
     106                 :            : namespace Dependencies {
     107                 :            : 
     108                 :            : css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
     109                 :        496 : check(dp_misc::DescriptionInfoset const & infoset) {
     110                 :            :     css::uno::Reference< css::xml::dom::XNodeList > deps(
     111         [ +  - ]:        496 :         infoset.getDependencies());
     112 [ +  - ][ +  - ]:        496 :     sal_Int32 n = deps->getLength();
     113                 :            :     css::uno::Sequence< css::uno::Reference< css::xml::dom::XElement > >
     114         [ +  - ]:        496 :         unsatisfied(n);
     115                 :        496 :     sal_Int32 unsat = 0;
     116         [ +  + ]:        992 :     for (sal_Int32 i = 0; i < n; ++i) {
     117                 :            :         css::uno::Reference< css::xml::dom::XElement > e(
     118 [ +  - ][ +  - ]:        496 :             deps->item(i), css::uno::UNO_QUERY_THROW);
                 [ +  - ]
     119                 :        496 :         bool sat = false;
     120 [ +  - ][ +  - ]:        496 :         if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == minimalVersionOpenOfficeOrg )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  -  
             #  #  #  # ]
                 [ +  - ]
     121                 :            :         {
     122                 :            :             sat = satisfiesMinimalVersion(
     123                 :            :                 getReferenceOpenOfficeOrgMajorMinor(),
     124         [ +  - ]:        496 :                 e->getAttribute(
     125 [ +  - ][ +  - ]:        496 :                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
         [ +  - ][ +  - ]
     126 [ #  # ][ #  # ]:          0 :         } else if ( e->getNamespaceURI() == namespaceOpenOfficeOrg && e->getTagName() == maximalVersionOpenOfficeOrg )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
                   #  # ]
     127                 :            :         {
     128                 :            :             sat = satisfiesMaximalVersion(
     129                 :            :                 getReferenceOpenOfficeOrgMajorMinor(),
     130         [ #  # ]:          0 :                 e->getAttribute(
     131 [ #  # ][ #  # ]:          0 :                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
         [ #  # ][ #  # ]
     132 [ #  # ][ #  # ]:          0 :         } else if (e->getNamespaceURI() == namespaceLibreOffice && e->getTagName() == minimalVersionLibreOffice )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
                   #  # ]
     133                 :            :         {
     134                 :            :             sat = satisfiesMinimalVersion(
     135                 :            :                 getLibreOfficeMajorMinorMicro(),
     136         [ #  # ]:          0 :                 e->getAttribute(
     137 [ #  # ][ #  # ]:          0 :                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
         [ #  # ][ #  # ]
     138   [ #  #  #  # ]:          0 :         } else if (e->hasAttributeNS(
     139                 :            :                        rtl::OUString(
     140                 :            :                            RTL_CONSTASCII_USTRINGPARAM(namespaceOpenOfficeOrg)),
     141                 :            :                        rtl::OUString(
     142                 :            :                            RTL_CONSTASCII_USTRINGPARAM(
     143 [ #  # ][ #  # ]:          0 :                                minimalVersionOpenOfficeOrg))))
                 [ #  # ]
     144                 :            :         {
     145                 :            :             sat = satisfiesMinimalVersion(
     146                 :            :                 getReferenceOpenOfficeOrgMajorMinor(),
     147         [ #  # ]:          0 :                 e->getAttributeNS(
     148                 :            :                     rtl::OUString(
     149                 :            :                         RTL_CONSTASCII_USTRINGPARAM(namespaceOpenOfficeOrg)),
     150                 :            :                     rtl::OUString(
     151                 :            :                         RTL_CONSTASCII_USTRINGPARAM(
     152 [ #  # ][ #  # ]:          0 :                             minimalVersionOpenOfficeOrg))));
         [ #  # ][ #  # ]
                 [ #  # ]
     153                 :            :         }
     154         [ -  + ]:        496 :         if (!sat) {
     155 [ #  # ][ #  # ]:          0 :             unsatisfied[unsat++] = e;
     156                 :            :         }
     157                 :        496 :     }
     158         [ +  - ]:        496 :     unsatisfied.realloc(unsat);
     159                 :        496 :     return unsatisfied;
     160                 :            : }
     161                 :            : 
     162                 :          0 : rtl::OUString getErrorText(
     163                 :            :     css::uno::Reference< css::xml::dom::XElement > const & dependency)
     164                 :            : {
     165                 :            :     OSL_ASSERT(dependency.is());
     166 [ #  # ][ #  # ]:          0 :     if ( dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == minimalVersionOpenOfficeOrg )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
                   #  # ]
     167                 :            :     {
     168                 :            :         return produceErrorText(
     169                 :            :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
     170                 :          0 :             dependency->getAttribute(
     171 [ #  # ][ #  # ]:          0 :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
         [ #  # ][ #  # ]
     172 [ #  # ][ #  # ]:          0 :     } else if (dependency->getNamespaceURI() == namespaceOpenOfficeOrg && dependency->getTagName() == maximalVersionOpenOfficeOrg )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
                   #  # ]
     173                 :            :     {
     174                 :            :         return produceErrorText(
     175                 :            :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MAX).toString(),
     176                 :          0 :             dependency->getAttribute(
     177 [ #  # ][ #  # ]:          0 :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
         [ #  # ][ #  # ]
     178 [ #  # ][ #  # ]:          0 :     } else if (dependency->getNamespaceURI() == namespaceLibreOffice && dependency->getTagName() == minimalVersionLibreOffice )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
                   #  # ]
     179                 :            :     {
     180                 :            :         return produceErrorText(
     181                 :            :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_LO_MIN).toString(),
     182                 :          0 :             dependency->getAttribute(
     183 [ #  # ][ #  # ]:          0 :                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("value"))));
         [ #  # ][ #  # ]
     184         [ #  # ]:          0 :     } else if (dependency->hasAttributeNS(
     185                 :            :                    rtl::OUString(
     186                 :            :                        RTL_CONSTASCII_USTRINGPARAM(namespaceOpenOfficeOrg)),
     187                 :            :                    rtl::OUString(
     188                 :            :                        RTL_CONSTASCII_USTRINGPARAM(
     189 [ #  # ][ #  # ]:          0 :                            minimalVersionOpenOfficeOrg))))
     190                 :            :     {
     191                 :            :         return produceErrorText(
     192                 :            :                 dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_OOO_MIN).toString(),
     193                 :          0 :             dependency->getAttributeNS(
     194                 :            :                 rtl::OUString(
     195                 :            :                     RTL_CONSTASCII_USTRINGPARAM(namespaceOpenOfficeOrg)),
     196                 :            :                 rtl::OUString(
     197 [ #  # ][ #  # ]:          0 :                     RTL_CONSTASCII_USTRINGPARAM(minimalVersionOpenOfficeOrg))));
         [ #  # ][ #  # ]
                 [ #  # ]
     198                 :            :     } else {
     199         [ #  # ]:          0 :         return dp_misc::getResId(RID_DEPLOYMENT_DEPENDENCIES_UNKNOWN).toString();
     200                 :            :     }
     201                 :            : }
     202                 :            : 
     203                 :            : }
     204                 :            : 
     205                 :            : }
     206                 :            : 
     207                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10