convergedcallengine/spsettings/tsrc/public/basic/spsettingsUT/src/T_CSPProperty.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Implementation of T_CSPProperty class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "T_CSPProperty.h"
       
    19 #include <EUnitMacros.h>
       
    20 #include <EUnitDecorators.h>
       
    21 
       
    22 
       
    23 
       
    24 // - Construction -----------------------------------------------------------
       
    25 
       
    26 T_CSPProperty* T_CSPProperty::NewL()
       
    27     {
       
    28     T_CSPProperty* self = T_CSPProperty::NewLC();
       
    29     CleanupStack::Pop();
       
    30     return self;
       
    31     }
       
    32 
       
    33 T_CSPProperty* T_CSPProperty::NewLC()
       
    34     {
       
    35     T_CSPProperty* self = new( ELeave ) T_CSPProperty();
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL();
       
    38     return self;
       
    39     }
       
    40 
       
    41 T_CSPProperty::~T_CSPProperty()
       
    42     {
       
    43     }
       
    44 
       
    45 T_CSPProperty::T_CSPProperty()
       
    46     {
       
    47     }
       
    48 
       
    49 void T_CSPProperty::ConstructL()
       
    50     {
       
    51     CEUnitTestSuiteClass::ConstructL();
       
    52     }
       
    53 
       
    54 // - Test methods -----------------------------------------------------------
       
    55 
       
    56 
       
    57 
       
    58 void T_CSPProperty::SetupL(  )
       
    59     {
       
    60     iCSPProperty = CSPProperty::NewL();
       
    61     }
       
    62     
       
    63 
       
    64 void T_CSPProperty::Teardown(  )
       
    65     {
       
    66     delete iCSPProperty;
       
    67     iCSPProperty = NULL;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // T_CSPProperty::PropertyDatatypeTIntSetGetTestL
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 void T_CSPProperty::PropertyDatatypeTIntSetGetTestL(  )
       
    75     {
       
    76     TInt profIdSet( 15 );
       
    77     EUNIT_ASSERT( KErrArgument == iCSPProperty->SetValue( profIdSet ) );
       
    78     
       
    79     iCSPProperty->SetName( EPropertyVoIPSubServicePluginId );
       
    80     EUNIT_ASSERT( EPropertyVoIPSubServicePluginId == iCSPProperty->GetName() );
       
    81     User::LeaveIfError( iCSPProperty->SetValue( profIdSet ));
       
    82     EUNIT_ASSERT( EDataTypeInt == iCSPProperty->GetDataType() );
       
    83     
       
    84     TInt profIdGet( 0 );
       
    85     TInt error = iCSPProperty->GetValue( profIdGet );
       
    86     EUNIT_ASSERT( error == KErrNone );
       
    87     EUNIT_ASSERT( profIdSet == profIdGet );
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // T_CSPProperty::PropertyDatatypeOnOffSetGetTestL
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 void T_CSPProperty::PropertyDatatypeOnOffSetGetTestL(  )
       
    95     {
       
    96     TOnOff onOffSet( EOn );
       
    97     EUNIT_ASSERT( KErrArgument == iCSPProperty->SetValue( onOffSet ) );
       
    98     
       
    99     iCSPProperty->SetName( ESubPropertyPresenceEnabled );
       
   100     EUNIT_ASSERT( ESubPropertyPresenceEnabled == iCSPProperty->GetName() );
       
   101     User::LeaveIfError( iCSPProperty->SetValue( onOffSet ) );
       
   102     EUNIT_ASSERT( EDataTypeOnOff == iCSPProperty->GetDataType() );
       
   103     
       
   104     TOnOff onOffGet( EOONotSet );
       
   105     TInt error = iCSPProperty->GetValue( onOffGet );
       
   106     EUNIT_ASSERT( error == KErrNone );
       
   107     EUNIT_ASSERT( onOffSet == onOffGet );
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // T_CSPProperty::PropertyDatatypeTDesCSetGetTestL
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void T_CSPProperty::PropertyDatatypeTDesCSetGetTestL(  )
       
   115     {
       
   116     iCSPProperty->SetName( EPropertyBrandId );
       
   117     EUNIT_ASSERT( EPropertyBrandId == iCSPProperty->GetName() );
       
   118     
       
   119     TBuf<514> overflower;
       
   120     overflower.FillZ( 514 );
       
   121     EUNIT_ASSERT( KErrOverflow == iCSPProperty->SetValue( overflower ) );
       
   122     
       
   123     RBuf brandIdSet;
       
   124     brandIdSet.CreateL( _L( "SomeBrandId" ) );
       
   125     CleanupClosePushL( brandIdSet);
       
   126     User::LeaveIfError( iCSPProperty->SetValue( brandIdSet ) );
       
   127     EUNIT_ASSERT( iCSPProperty->GetDataType() == EDataTypeDes );
       
   128     
       
   129     RBuf brandIdGet;    
       
   130     brandIdGet.CreateL( 9 );
       
   131     CleanupClosePushL( brandIdGet );
       
   132     brandIdGet.FillZ( 9 );
       
   133     EUNIT_ASSERT( KErrOverflow == iCSPProperty->GetValue( brandIdGet ) );
       
   134     CleanupStack::PopAndDestroy( &brandIdGet);
       
   135     
       
   136     brandIdGet.CreateL( KSPMaxDesLength );
       
   137     CleanupClosePushL( brandIdGet);
       
   138     TInt error = iCSPProperty->GetValue( brandIdGet );
       
   139     EUNIT_ASSERT( error == KErrNone );
       
   140     EUNIT_ASSERT( brandIdSet.Compare( brandIdGet ) == 0 );
       
   141 
       
   142     CleanupStack::PopAndDestroy( &brandIdGet);
       
   143     CleanupStack::PopAndDestroy( &brandIdSet);
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CopyLL
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 void T_CSPProperty::CopyLL(  )
       
   151     {
       
   152     iCSPProperty->CopyL( *iCSPProperty );
       
   153     
       
   154     CSPProperty* property = CSPProperty::NewLC();
       
   155     RBuf brandIdSet;
       
   156     brandIdSet.CreateL( _L( "SomeBrandId" ) );
       
   157     CleanupClosePushL( brandIdSet);
       
   158     User::LeaveIfError( property->SetValue( brandIdSet ) );
       
   159     
       
   160     iCSPProperty->CopyL( *property );
       
   161     
       
   162     RBuf brandIdGet;
       
   163     brandIdGet.CreateL( KSPMaxDesLength );
       
   164     CleanupClosePushL( brandIdGet);
       
   165     TInt error = iCSPProperty->GetValue( brandIdGet );
       
   166     EUNIT_ASSERT( error == KErrNone );
       
   167     EUNIT_ASSERT( brandIdSet.Compare( brandIdGet ) == 0 );
       
   168     
       
   169     CleanupStack::PopAndDestroy( &brandIdGet );
       
   170     CleanupStack::PopAndDestroy( &brandIdSet );
       
   171     CleanupStack::PopAndDestroy( property );
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // CopyLL
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 void T_CSPProperty::SetValueNoDataTypeCheckL(  )
       
   179     {
       
   180     RBuf bufToSet;
       
   181     bufToSet.CreateL( KSPMaxDesLength + 1 );
       
   182     CleanupClosePushL( bufToSet );
       
   183     bufToSet.FillZ( KSPMaxDesLength + 1 );
       
   184     EUNIT_ASSERT( KErrOverflow == iCSPProperty->SetValueNoDataTypeCheck( bufToSet ) );    
       
   185     CleanupStack::PopAndDestroy( &bufToSet );
       
   186     
       
   187     bufToSet.CreateL( _L( "SomeBrandId" ) );
       
   188     CleanupClosePushL( bufToSet );
       
   189     TInt error = iCSPProperty->SetValueNoDataTypeCheck( bufToSet );
       
   190     EUNIT_ASSERT( KErrNone == error );
       
   191     
       
   192     CleanupStack::PopAndDestroy( &bufToSet );
       
   193     }
       
   194 
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // PropertyTypeL
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void T_CSPProperty::PropertyTypeL(  )
       
   201     {
       
   202     EUNIT_ASSERT( EItemTypeNotDefined == iCSPProperty->PropertyType( EPropertyUnknown ) );
       
   203     EUNIT_ASSERT( EItemTypeVoIPSubProperty == iCSPProperty->PropertyType( ESubPropertyVoIPPreferredSNAPId ) );
       
   204     EUNIT_ASSERT( EItemTypePresenceSubProperty == iCSPProperty->PropertyType( ESubPropertyPresencePreferredSNAPId  ) );
       
   205     EUNIT_ASSERT( EItemTypeIMSubProperty == iCSPProperty->PropertyType( ESubPropertyIMPreferredSNAPId ) );
       
   206     EUNIT_ASSERT( EItemTypeVMBXSubProperty  == iCSPProperty->PropertyType( ESubPropertyVMBXPreferredSNAPId ) );
       
   207     EUNIT_ASSERT( EItemTypeProperty  == iCSPProperty->PropertyType( EPropertyCTIPluginId ) );
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // PropertyTypeL
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 void T_CSPProperty::EqualToOperatorOverloadL(  )
       
   215     {
       
   216     CSPProperty* property = CSPProperty::NewLC();
       
   217     TBool objectsEqual = *iCSPProperty == *iCSPProperty;
       
   218     EUNIT_ASSERT( objectsEqual );
       
   219     
       
   220     property->SetName( EPropertyBrandId );
       
   221     objectsEqual = *iCSPProperty == *property;
       
   222     EUNIT_ASSERT( !objectsEqual );
       
   223     
       
   224     CleanupStack::PopAndDestroy( property );
       
   225     }
       
   226     
       
   227 
       
   228 // - EUnit test table -------------------------------------------------------
       
   229 
       
   230 EUNIT_BEGIN_TEST_TABLE(
       
   231     T_CSPProperty,
       
   232     "Add test suite description here.",
       
   233     "UNIT" )
       
   234     
       
   235 EUNIT_TEST(
       
   236     "PropertyDatatypeTIntSetGetTest - Test",
       
   237     "CSPProperty",
       
   238     "PropertyDatatypeTIntSetGetTest - Test",
       
   239     "FUNCTIONALITY",
       
   240     SetupL, PropertyDatatypeTIntSetGetTestL, Teardown)
       
   241     
       
   242 EUNIT_TEST(
       
   243     "PropertyDatatypeTIntSetGetTest - Test",
       
   244     "CSPProperty",
       
   245     "PropertyDatatypeTIntSetGetTest - Test",
       
   246     "FUNCTIONALITY",
       
   247     SetupL, PropertyDatatypeOnOffSetGetTestL, Teardown)
       
   248     
       
   249 EUNIT_TEST(
       
   250     "PropertyDatatypeTIntSetGetTest - Test",
       
   251     "CSPProperty",
       
   252     "PropertyDatatypeTIntSetGetTest - Test",
       
   253     "FUNCTIONALITY",
       
   254     SetupL, PropertyDatatypeTDesCSetGetTestL, Teardown)
       
   255 
       
   256 EUNIT_TEST(
       
   257     "CopyL - Test",
       
   258     "CSPProperty",
       
   259     "CopyL - Test",
       
   260     "FUNCTIONALITY",
       
   261     SetupL, CopyLL, Teardown)
       
   262 
       
   263 EUNIT_TEST(
       
   264     "SetValueNoDataTypeCheck - Test",
       
   265     "CSPProperty",
       
   266     "SetValueNoDataTypeCheck - Test",
       
   267     "FUNCTIONALITY",
       
   268     SetupL, SetValueNoDataTypeCheckL, Teardown)
       
   269     
       
   270 EUNIT_TEST(
       
   271     "PropertyType - Test",
       
   272     "CSPProperty",
       
   273     "PropertyType - Test",
       
   274     "FUNCTIONALITY",
       
   275     SetupL, PropertyTypeL, Teardown)
       
   276 
       
   277 EUNIT_TEST(
       
   278     "EqualToOperatorRedefinition - Test",
       
   279     "CSPProperty",
       
   280     "EqualToOperatorRedefinition - Test",
       
   281     "FUNCTIONALITY",
       
   282     SetupL, EqualToOperatorOverloadL, Teardown)
       
   283 
       
   284 EUNIT_END_TEST_TABLE