LCOV - code coverage report
Current view: top level - templates/scriptabletags - scriptablesafestring.cpp (source / functions) Hit Total Coverage
Test: test_all.info Lines: 17 29 58.6 %
Date: 2011-06-24 Functions: 5 7 71.4 %
Branches: 16 50 32.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :   This file is part of the Grantlee template system.
       3                 :            : 
       4                 :            :   Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
       5                 :            : 
       6                 :            :   This library is free software; you can redistribute it and/or
       7                 :            :   modify it under the terms of the GNU Lesser General Public
       8                 :            :   License as published by the Free Software Foundation; either version
       9                 :            :   2.1 of the Licence, or (at your option) any later version.
      10                 :            : 
      11                 :            :   This library is distributed in the hope that it will be useful,
      12                 :            :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14                 :            :   Lesser General Public License for more details.
      15                 :            : 
      16                 :            :   You should have received a copy of the GNU Lesser General Public
      17                 :            :   License along with this library.  If not, see <http://www.gnu.org/licenses/>.
      18                 :            : 
      19                 :            : */
      20                 :            : 
      21                 :            : #include "scriptablesafestring.h"
      22                 :            : 
      23                 :            : #include <QtScript/QScriptEngine>
      24                 :            : 
      25                 :            : #include "util.h"
      26                 :            : 
      27                 :          4 : QScriptValue markSafeFunction( QScriptContext *context,
      28                 :            :                                QScriptEngine *engine )
      29                 :            : {
      30                 :          8 :   QScriptValue inputValue = context->argument( 0 );
      31 [ +  - ][ -  + ]:          4 :   if ( inputValue.isQObject() ) {
      32         [ #  # ]:          0 :     QObject *obj = inputValue.toQObject();
      33         [ #  # ]:          0 :     ScriptableSafeString *ssObj = qobject_cast<ScriptableSafeString*>( obj );
      34         [ #  # ]:          0 :     if ( !ssObj )
      35         [ #  # ]:          0 :       return engine->nullValue();
      36                 :            : 
      37         [ #  # ]:          0 :     ssObj->setSafety( true );
      38 [ #  # ][ #  # ]:          0 :     return engine->newQObject( ssObj );
      39                 :            : 
      40 [ +  - ][ +  - ]:          4 :   } else if ( inputValue.isString() ) {
      41 [ +  - ][ +  - ]:          8 :     QString str = inputValue.toString();
      42 [ +  - ][ +  - ]:          4 :     ScriptableSafeString *ssObj = new ScriptableSafeString( engine );
      43 [ +  - ][ +  - ]:          4 :     ssObj->setContent( markSafe( str ) );
         [ +  - ][ +  - ]
                 [ +  - ]
      44 [ +  - ][ +  - ]:          4 :     return engine->newQObject( ssObj );
      45                 :            : 
      46                 :            :   }
      47         [ #  # ]:          0 :   return engine->nullValue();
      48                 :            : 
      49                 :            : }
      50                 :            : 
      51         [ +  - ]:          9 : ScriptableSafeString::ScriptableSafeString( QObject* parent ): QObject( parent )
      52                 :            : {
      53                 :            : 
      54                 :          9 : }
      55                 :            : 
      56                 :          9 : void ScriptableSafeString::setContent( const Grantlee::SafeString& content )
      57                 :            : {
      58                 :          9 :   m_safeString = content;
      59                 :          9 : }
      60                 :            : 
      61                 :          4 : SafeString ScriptableSafeString::wrappedString() const
      62                 :            : {
      63                 :          4 :   return m_safeString;
      64                 :            : }
      65                 :            : 
      66                 :          0 : bool ScriptableSafeString::isSafe() const
      67                 :            : {
      68                 :          0 :   return m_safeString.isSafe();
      69                 :            : }
      70                 :            : 
      71                 :          0 : void ScriptableSafeString::setSafety( bool safeness )
      72                 :            : {
      73         [ #  # ]:          0 :   m_safeString.setSafety( safeness ? Grantlee::SafeString::IsSafe : Grantlee::SafeString::IsNotSafe );
      74                 :          0 : }
      75                 :            : 
      76                 :          5 : QString ScriptableSafeString::rawString()
      77                 :            : {
      78                 :          5 :   return m_safeString;
      79                 :            : }
      80                 :            : 
      81                 :            : #include "scriptablesafestring.moc"
      82                 :            : 

Generated by: LCOV version 1.9