LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/desktop/source/deployment/misc - dp_platform.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 107 37.4 %
Date: 2013-07-09 Functions: 8 8 100.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 "dp_misc.h"
      22             : #include "dp_platform.hxx"
      23             : #include "rtl/ustring.hxx"
      24             : #include "rtl/ustrbuf.hxx"
      25             : #include "rtl/instance.hxx"
      26             : #include "rtl/bootstrap.hxx"
      27             : 
      28             : #define PLATFORM_ALL                "all"
      29             : #define PLATFORM_WIN_X86            "windows_x86"
      30             : #define PLATFORM_WIN_X86_64         "windows_x86_64"
      31             : #define PLATFORM_LINUX_X86          "linux_x86"
      32             : #define PLATFORM_LINUX_X86_64       "linux_x86_64"
      33             : #define PLATFORM_KFREEBSD_X86       "kfreebsd_x86"
      34             : #define PLATFORM_KFREEBSD_X86_64    "kfreebsd_x86_64"
      35             : #define PLATFORM_LINUX_SPARC        "linux_sparc"
      36             : #define PLATFORM_LINUX_POWERPC      "linux_powerpc"
      37             : #define PLATFORM_LINUX_POWERPC64    "linux_powerpc64"
      38             : #define PLATFORM_LINUX_ARM_EABI     "linux_arm_eabi"
      39             : #define PLATFORM_LINUX_ARM_OABI     "linux_arm_oabi"
      40             : #define PLATFORM_LINUX_MIPS_EL      "linux_mips_el"
      41             : #define PLATFORM_LINUX_MIPS_EB      "linux_mips_eb"
      42             : #define PLATFORM_LINUX_IA64         "linux_ia64"
      43             : #define PLATFORM_LINUX_M68K         "linux_m68k"
      44             : #define PLATFORM_LINUX_S390         "linux_s390"
      45             : #define PLATFORM_LINUX_S390x        "linux_s390x"
      46             : #define PLATFORM_LINUX_HPPA         "linux_hppa"
      47             : #define PLATFORM_LINUX_ALPHA        "linux_alpha"
      48             : 
      49             : 
      50             : 
      51             : #define PLATFORM_SOLARIS_SPARC      "solaris_sparc"
      52             : #define PLATFORM_SOLARIS_SPARC64    "solaris_sparc64"
      53             : #define PLATFORM_SOLARIS_X86        "solaris_x86"
      54             : #define PLATFORM_FREEBSD_X86        "freebsd_x86"
      55             : #define PLATFORM_FREEBSD_X86_64     "freebsd_x86_64"
      56             : #define PLATFORM_NETBSD_X86         "netbsd_x86"
      57             : #define PLATFORM_NETBSD_X86_64      "netbsd_x86_64"
      58             : #define PLATFORM_MACOSX_X86         "macosx_x86"
      59             : #define PLATFORM_OPENBSD_X86        "openbsd_x86"
      60             : #define PLATFORM_OPENBSD_X86_64     "openbsd_x86_64"
      61             : #define PLATFORM_DRAGONFLY_X86      "dragonfly_x86"
      62             : #define PLATFORM_DRAGONFLY_X86_64   "dragonfly_x86_64"
      63             : 
      64             : 
      65             : #define PLATFORM_AIX_POWERPC        "aix_powerpc"
      66             : 
      67             : 
      68             : namespace dp_misc
      69             : {
      70             : namespace
      71             : {
      72             :     struct StrOperatingSystem :
      73             :         public rtl::StaticWithInit<OUString, StrOperatingSystem> {
      74          63 :             const OUString operator () () {
      75          63 :                 OUString os( "$_OS" );
      76          63 :                 ::rtl::Bootstrap::expandMacros( os );
      77          63 :                 return os;
      78             :             }
      79             :     };
      80             : 
      81             :     struct StrCPU :
      82             :         public rtl::StaticWithInit<OUString, StrCPU> {
      83          63 :             const OUString operator () () {
      84          63 :                 OUString arch( "$_ARCH" );
      85          63 :                 ::rtl::Bootstrap::expandMacros( arch );
      86          63 :                 return arch;
      87             :             }
      88             :     };
      89             : 
      90             : 
      91             :     struct StrPlatform : public rtl::StaticWithInit<
      92             :         OUString, StrPlatform> {
      93          63 :             const OUString operator () () {
      94          63 :                 OUStringBuffer buf;
      95          63 :                 buf.append( StrOperatingSystem::get() );
      96          63 :                 buf.append( static_cast<sal_Unicode>('_') );
      97          63 :                 buf.append( StrCPU::get() );
      98          63 :                 return buf.makeStringAndClear();
      99             :             }
     100             :     };
     101             : 
     102          32 :     bool checkOSandCPU(OUString const & os, OUString const & cpu)
     103             :     {
     104          32 :         return (os == StrOperatingSystem::get())
     105          32 :             && (cpu == StrCPU::get());
     106             :     }
     107             : 
     108          34 :     bool isValidPlatform(OUString const &  token )
     109             :     {
     110          34 :         bool ret = false;
     111          34 :         if (token == PLATFORM_ALL)
     112           2 :             ret = true;
     113          32 :         else if (token == PLATFORM_WIN_X86)
     114           0 :             ret = checkOSandCPU("Windows", "x86");
     115          32 :         else if (token == PLATFORM_WIN_X86_64)
     116           0 :             ret = checkOSandCPU("Windows", "x86_64");
     117          32 :         else if (token == PLATFORM_LINUX_X86)
     118          32 :             ret = checkOSandCPU("Linux", "x86");
     119           0 :         else if (token == PLATFORM_LINUX_X86_64)
     120           0 :             ret = checkOSandCPU("Linux", "X86_64");
     121           0 :         else if (token == PLATFORM_KFREEBSD_X86)
     122           0 :             ret = checkOSandCPU("kFreeBSD", "x86");
     123           0 :         else if (token == PLATFORM_KFREEBSD_X86_64)
     124           0 :             ret = checkOSandCPU("kFreeBSD", "X86_64");
     125           0 :         else if (token == PLATFORM_LINUX_SPARC)
     126           0 :             ret = checkOSandCPU("Linux", "SPARC");
     127           0 :         else if (token == PLATFORM_LINUX_POWERPC)
     128           0 :             ret = checkOSandCPU("Linux", "PowerPC");
     129           0 :         else if (token == PLATFORM_LINUX_POWERPC64)
     130           0 :             ret = checkOSandCPU("Linux", "PowerPC_64");
     131           0 :         else if (token == PLATFORM_LINUX_ARM_EABI)
     132           0 :             ret = checkOSandCPU("Linux", "ARM_EABI");
     133           0 :         else if (token == PLATFORM_LINUX_ARM_OABI)
     134           0 :             ret = checkOSandCPU("Linux", "ARM_OABI");
     135           0 :         else if (token == PLATFORM_LINUX_MIPS_EL)
     136           0 :             ret = checkOSandCPU("Linux", "MIPS_EL");
     137           0 :         else if (token == PLATFORM_LINUX_MIPS_EB)
     138           0 :             ret = checkOSandCPU("Linux", "MIPS_EB");
     139           0 :         else if (token == PLATFORM_LINUX_IA64)
     140           0 :             ret = checkOSandCPU("Linux", "IA64");
     141           0 :         else if (token == PLATFORM_LINUX_M68K)
     142           0 :             ret = checkOSandCPU("Linux", "M68K");
     143           0 :         else if (token == PLATFORM_LINUX_S390)
     144           0 :             ret = checkOSandCPU("Linux", "S390");
     145           0 :         else if (token == PLATFORM_LINUX_S390x)
     146           0 :             ret = checkOSandCPU("Linux", "S390x");
     147           0 :         else if (token == PLATFORM_LINUX_HPPA)
     148           0 :             ret = checkOSandCPU("Linux", "HPPA");
     149           0 :         else if (token == PLATFORM_LINUX_ALPHA)
     150           0 :             ret = checkOSandCPU("Linux", "ALPHA");
     151           0 :         else if (token == PLATFORM_SOLARIS_SPARC)
     152           0 :             ret = checkOSandCPU("Solaris", "SPARC");
     153           0 :         else if (token == PLATFORM_SOLARIS_SPARC64)
     154           0 :             ret = checkOSandCPU("Solaris", "SPARC64");
     155           0 :         else if (token == PLATFORM_SOLARIS_X86)
     156           0 :             ret = checkOSandCPU("Solaris", "x86");
     157           0 :         else if (token == PLATFORM_FREEBSD_X86)
     158           0 :             ret = checkOSandCPU("FreeBSD", "x86");
     159           0 :         else if (token == PLATFORM_FREEBSD_X86_64)
     160           0 :             ret = checkOSandCPU("FreeBSD", "X86_64");
     161           0 :         else if (token == PLATFORM_NETBSD_X86)
     162           0 :             ret = checkOSandCPU("NetBSD", "x86");
     163           0 :         else if (token == PLATFORM_NETBSD_X86_64)
     164           0 :             ret = checkOSandCPU("NetBSD", "X86_64");
     165           0 :         else if (token == PLATFORM_MACOSX_X86)
     166           0 :             ret = checkOSandCPU("MacOSX", "x86");
     167           0 :         else if (token == PLATFORM_AIX_POWERPC)
     168           0 :             ret = checkOSandCPU("AIX", "PowerPC");
     169           0 :         else if (token == PLATFORM_OPENBSD_X86)
     170           0 :             ret = checkOSandCPU("OpenBSD", "x86");
     171           0 :         else if (token == PLATFORM_OPENBSD_X86_64)
     172           0 :             ret = checkOSandCPU("OpenBSD", "X86_64");
     173           0 :         else if (token == PLATFORM_DRAGONFLY_X86)
     174           0 :             ret = checkOSandCPU("DragonFly", "x86");
     175           0 :         else if (token == PLATFORM_DRAGONFLY_X86_64)
     176           0 :             ret = checkOSandCPU("DragonFly", "X86_64");
     177             :         else
     178             :         {
     179             :             OSL_FAIL("Extension Manager: The extension supports an unknown platform. "
     180             :             "Check the platform element in the description.xml");
     181           0 :             ret = false;
     182             :         }
     183          34 :         return ret;
     184             :     }
     185             : 
     186             : } // anon namespace
     187             : //=============================================================================
     188             : 
     189         290 : OUString const & getPlatformString()
     190             : {
     191         290 :     return StrPlatform::get();
     192             : }
     193             : 
     194         126 : bool platform_fits( OUString const & platform_string )
     195             : {
     196         126 :     sal_Int32 index = 0;
     197             :     for (;;)
     198             :     {
     199             :         const OUString token(
     200         126 :             platform_string.getToken( 0, ',', index ).trim() );
     201             :         // check if this platform:
     202         252 :         if (token.equalsIgnoreAsciiCase( StrPlatform::get() ) ||
     203           0 :             (token.indexOf( '_' ) < 0 && /* check OS part only */
     204           0 :              token.equalsIgnoreAsciiCase( StrOperatingSystem::get() )))
     205             :         {
     206         126 :             return true;
     207             :         }
     208           0 :         if (index < 0)
     209           0 :             break;
     210           0 :     }
     211           0 :     return false;
     212             : }
     213             : 
     214          34 : bool hasValidPlatform( css::uno::Sequence<OUString> const & platformStrings)
     215             : {
     216          34 :     bool ret = false;
     217          34 :     for (sal_Int32 i  = 0; i < platformStrings.getLength(); i++)
     218             :     {
     219          34 :         if (isValidPlatform(platformStrings[i]))
     220             :         {
     221          34 :             ret = true;
     222          34 :             break;
     223             :         }
     224             :     }
     225          34 :     return ret;
     226             : }
     227             : 
     228             : }
     229             : 
     230             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10