phoneuis/easydialing/tsrc/t_easydialingplugin/src/CEasyDialingPlugin_Test.cpp
branchRCL_3
changeset 9 8871b09be73b
equal deleted inserted replaced
4:c84cf270c54f 9:8871b09be73b
       
     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: 
       
    15 *
       
    16 */
       
    17 /*
       
    18 -----------------------------------------------------------------------------
       
    19 This file has been generated with EUnit Pro
       
    20 http://www.digia.com/eunit
       
    21 -----------------------------------------------------------------------------
       
    22 */
       
    23 #include "CEasyDialingPlugin_Test.h"
       
    24 #include <EUnitMacros.h>
       
    25 #include <EUnitDecorators.h>
       
    26 #include <f32file.h> 
       
    27 #include <bautils.h> 
       
    28 
       
    29 #include "easydialingplugin.h"
       
    30 #include "dummyparentcontrol.h"
       
    31 
       
    32 #include <cntdb.h> 
       
    33 #include <cntitem.h> 
       
    34 #include <cntfldst.h> 
       
    35 #include <bautils.h> 
       
    36 
       
    37 
       
    38 // - Construction -----------------------------------------------------------
       
    39 
       
    40 CEasyDialingPlugin_Test* CEasyDialingPlugin_Test::NewL()
       
    41     {
       
    42     CEasyDialingPlugin_Test* self = CEasyDialingPlugin_Test::NewLC();
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 CEasyDialingPlugin_Test* CEasyDialingPlugin_Test::NewLC()
       
    48     {
       
    49     CEasyDialingPlugin_Test* self = new( ELeave ) CEasyDialingPlugin_Test();
       
    50     CleanupStack::PushL( self );
       
    51     self->ConstructL();
       
    52     return self;
       
    53     }
       
    54 
       
    55 CEasyDialingPlugin_Test::~CEasyDialingPlugin_Test()
       
    56     {
       
    57     RDebug::Print(_L("EDTest: enter desctructor"));
       
    58     
       
    59     if (iCEasyDialingPlugin)
       
    60         {
       
    61         iCEasyDialingPlugin->RemoveObserver( this );
       
    62         }
       
    63     delete iWait;
       
    64     delete iCEasyDialingPlugin;
       
    65     delete iDummyParentControl;
       
    66     RDebug::Print(_L("EDTest: exit desctructor"));
       
    67     }
       
    68 
       
    69 CEasyDialingPlugin_Test::CEasyDialingPlugin_Test()
       
    70     {
       
    71     }
       
    72 
       
    73 
       
    74 TInt CreateTestContactDatabaseL();
       
    75 
       
    76 void CEasyDialingPlugin_Test::ConstructL()
       
    77     {
       
    78     CEUnitTestSuiteClass::ConstructL();
       
    79     CreateTestContactDatabaseL();
       
    80     iWait = new( ELeave )CActiveSchedulerWait();
       
    81     iDummyParentControl = CDummyParentControl::NewL();
       
    82     
       
    83     iCEasyDialingPlugin = CEasyDialingPlugin::NewL();
       
    84     iCEasyDialingPlugin->InitializeL( *iDummyParentControl );
       
    85     iCEasyDialingPlugin->AddObserverL( this );
       
    86     
       
    87     
       
    88     RDebug::Print(_L("EDTest:Construct plugin exit"));
       
    89     }
       
    90 
       
    91 
       
    92 void CEasyDialingPlugin_Test::HandleDialingExtensionEvent( MDialingExtensionObserver::TEvent aEvent )
       
    93     {
       
    94     if ( aEvent == MDialingExtensionObserver::ESearchComplete )
       
    95         {
       
    96         iWait->AsyncStop();
       
    97         }
       
    98     }
       
    99 
       
   100 // - Test methods -----------------------------------------------------------
       
   101 
       
   102 
       
   103 
       
   104 void CEasyDialingPlugin_Test::SetupL(  )
       
   105     {
       
   106     }
       
   107     
       
   108 
       
   109 void CEasyDialingPlugin_Test::Teardown(  )
       
   110     {
       
   111     }
       
   112 
       
   113 
       
   114 void CEasyDialingPlugin_Test::T_Global_OfferKeyEventLL(  )
       
   115     {
       
   116     
       
   117     TKeyEvent ke;
       
   118     ke.iCode = 32;
       
   119     ke.iModifiers = 0;
       
   120     ke.iRepeats = 0;
       
   121     ke.iScanCode = 32;
       
   122     
       
   123     iCEasyDialingPlugin->OfferKeyEventL( ke, EEventKey );
       
   124     EUNIT_ASSERT_DESC( iCEasyDialingPlugin, "OfferKeyEventL general assert");
       
   125     
       
   126     }
       
   127     
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // T_Global_Search*
       
   131 // These functions do all kind of searches with easy dialing and check that
       
   132 // the count of matching contacts is right. These tests require that a specific
       
   133 // test contact data base has been created with CreateTestContactDatabaseL().
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CEasyDialingPlugin_Test::T_Global_Search1(  )
       
   137     {
       
   138     TRAP_IGNORE( iCEasyDialingPlugin->SetInputL( _L("A") ));
       
   139     iWait->Start();
       
   140     // Now execution stops here until HandleDialingExtensionEvent has been called. 
       
   141     
       
   142     TInt count = iCEasyDialingPlugin->MatchingContactCount();
       
   143     EUNIT_ASSERT_EQUALS( count, 1 );
       
   144     }
       
   145    
       
   146 void CEasyDialingPlugin_Test::T_Global_Search2()
       
   147 	{
       
   148 	TRAP_IGNORE( iCEasyDialingPlugin->SetInputL( _L("b") ));
       
   149     iWait->Start();
       
   150     // Now execution stops here until HandleDialingExtensionEvent has been called.
       
   151     
       
   152 	TInt count = iCEasyDialingPlugin->MatchingContactCount();
       
   153     EUNIT_ASSERT_EQUALS( count, 1 );
       
   154 	}
       
   155 
       
   156 void CEasyDialingPlugin_Test::T_Global_Search3()
       
   157     {
       
   158     TRAP_IGNORE( iCEasyDialingPlugin->SetInputL( _L("C") ));
       
   159     iWait->Start();
       
   160     // Now execution stops here until HandleDialingExtensionEvent has been called.
       
   161     
       
   162     TInt count = iCEasyDialingPlugin->MatchingContactCount();
       
   163     EUNIT_ASSERT_EQUALS( count, 2 );
       
   164     }
       
   165 
       
   166 void CEasyDialingPlugin_Test::T_Global_Search4()
       
   167     {
       
   168     TRAP_IGNORE( iCEasyDialingPlugin->SetInputL( _L("2") ));
       
   169     iWait->Start();
       
   170     // Now execution stops here until HandleDialingExtensionEvent has been called.
       
   171     
       
   172     TInt count = iCEasyDialingPlugin->MatchingContactCount();
       
   173     EUNIT_ASSERT_EQUALS( count, 4 );
       
   174     }
       
   175 
       
   176 void CEasyDialingPlugin_Test::T_Global_Search5()
       
   177     {
       
   178     TRAP_IGNORE( iCEasyDialingPlugin->SetInputL( _L("3") ));
       
   179     iWait->Start();
       
   180     // Now execution stops here until HandleDialingExtensionEvent has been called.
       
   181     
       
   182     TInt count = iCEasyDialingPlugin->MatchingContactCount();
       
   183     EUNIT_ASSERT_EQUALS( count, 4 );
       
   184     }
       
   185 
       
   186 void CEasyDialingPlugin_Test::T_Global_Search6()
       
   187     {
       
   188     TRAP_IGNORE( iCEasyDialingPlugin->SetInputL( _L("8286607") )); // should match to <Tauno P>alo
       
   189     iWait->Start();
       
   190     // Now execution stops here until HandleDialingExtensionEvent has been called.
       
   191     
       
   192     TInt count = iCEasyDialingPlugin->MatchingContactCount();
       
   193     EUNIT_ASSERT_EQUALS( count, 1 );
       
   194     }
       
   195 
       
   196 void CEasyDialingPlugin_Test::T_Global_Search7()
       
   197     {
       
   198     TRAP_IGNORE( iCEasyDialingPlugin->SetInputL( _L("5569304") )); // should match to <Lloyd H>arold
       
   199     iWait->Start();
       
   200     // Now execution stops here until HandleDialingExtensionEvent has been called.
       
   201     
       
   202     TInt count = iCEasyDialingPlugin->MatchingContactCount();
       
   203     EUNIT_ASSERT_EQUALS( count, 1 );
       
   204     }
       
   205 
       
   206 void CEasyDialingPlugin_Test::T_Global_Search8()
       
   207     {
       
   208     TRAP_IGNORE( iCEasyDialingPlugin->SetInputL( _L("3456407") )); // should match to <Filmi S>uomi
       
   209     iWait->Start();
       
   210     // Now execution stops here until HandleDialingExtensionEvent has been called.
       
   211     
       
   212     TInt count = iCEasyDialingPlugin->MatchingContactCount();
       
   213     EUNIT_ASSERT_EQUALS( count, 2 );
       
   214     }
       
   215 
       
   216 
       
   217     
       
   218 // -----------------------------------------------------------------------------
       
   219 // T_Global__CEasyDialingPluginL
       
   220 // Destructor test 
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 void CEasyDialingPlugin_Test::T_Global__CEasyDialingPluginL(  )
       
   224     {
       
   225     iCEasyDialingPlugin->~CEasyDialingPlugin();
       
   226     iCEasyDialingPlugin = NULL;
       
   227     iCEasyDialingPlugin = CEasyDialingPlugin::NewL();
       
   228     EUNIT_ASSERT_DESC( ETrue, "Generated assert, replace with real");
       
   229     }
       
   230 
       
   231 
       
   232 
       
   233 
       
   234 
       
   235 
       
   236 
       
   237 // - EUnit test table -------------------------------------------------------
       
   238 
       
   239 EUNIT_BEGIN_TEST_TABLE(
       
   240     CEasyDialingPlugin_Test,
       
   241     "Easy dialing plugin test",
       
   242     "UNIT" )
       
   243 
       
   244 EUNIT_TEST(
       
   245     "OfferKeyEventL",
       
   246     "CEasyDialingPlugin",
       
   247     "OfferKeyEventL",
       
   248     "FUNCTIONALITY",
       
   249     SetupL, T_Global_OfferKeyEventLL, Teardown)
       
   250     
       
   251 EUNIT_TEST(
       
   252     "SetInputLL",
       
   253     "CEasyDialingPlugin",
       
   254     "SetInputLL",
       
   255     "FUNCTIONALITY",
       
   256     SetupL, T_Global_Search1, Teardown)
       
   257     
       
   258 EUNIT_TEST(
       
   259 	"Tests matching contact count function.",
       
   260 	"CEasyDialingPlugin_Test",
       
   261 	"MatchingContactCount",
       
   262 	"FUNCTIONALITY",
       
   263 	SetupL, T_Global_Search2, Teardown )
       
   264 
       
   265 EUNIT_TEST(
       
   266     "PCS search test function",
       
   267     "CEasyDialingPlugin_Test",
       
   268     "",
       
   269     "FUNCTIONALITY",
       
   270     SetupL, T_Global_Search3, Teardown )
       
   271     
       
   272 EUNIT_TEST(
       
   273     "PCS search test function",
       
   274     "CEasyDialingPlugin_Test",
       
   275     "",
       
   276     "FUNCTIONALITY",
       
   277     SetupL, T_Global_Search4, Teardown )
       
   278     
       
   279 EUNIT_TEST(
       
   280     "PCS search test function",
       
   281     "CEasyDialingPlugin_Test",
       
   282     "",
       
   283     "FUNCTIONALITY",
       
   284     SetupL, T_Global_Search5, Teardown )
       
   285     
       
   286 EUNIT_TEST(
       
   287     "PCS search test function",
       
   288     "CEasyDialingPlugin_Test",
       
   289     "",
       
   290     "FUNCTIONALITY",
       
   291     SetupL, T_Global_Search6, Teardown )
       
   292     
       
   293 EUNIT_TEST(
       
   294     "PCS search test function",
       
   295     "CEasyDialingPlugin_Test",
       
   296     "",
       
   297     "FUNCTIONALITY",
       
   298     SetupL, T_Global_Search7, Teardown )
       
   299     
       
   300 EUNIT_TEST(
       
   301     "PCS search test function",
       
   302     "CEasyDialingPlugin_Test",
       
   303     "",
       
   304     "FUNCTIONALITY",
       
   305     SetupL, T_Global_Search8, Teardown )
       
   306     
       
   307 EUNIT_TEST(
       
   308     "~CEasyDialingPlugin",
       
   309     "CEasyDialingPlugin",
       
   310     "~CEasyDialingPlugin",
       
   311     "FUNCTIONALITY",
       
   312     SetupL, T_Global__CEasyDialingPluginL, Teardown)
       
   313     
       
   314 EUNIT_END_TEST_TABLE