plugins/contacts/symbian/contactsmodel/tsrc/cntplsql/src/t_cqwertykeymap.cpp
changeset 0 876b1a06bc25
child 5 603d3f8b6302
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /*
       
     2 * Copyright (c) 2010 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:  Unit test class for testing CQwertyKeyMap
       
    15 *
       
    16 */
       
    17 
       
    18 // INTERNAL INCLUDES
       
    19 #include "t_cqwertykeymap.h"
       
    20 #include "cqwertykeymap.h"
       
    21 #include <QString>
       
    22 
       
    23 // SYSTEM INCLUDES
       
    24 #include <digia/eunit/eunitmacros.h>
       
    25 #if defined(USE_ORBIT_KEYMAP)
       
    26 #include <hbinputkeymapfactory.h>
       
    27 #endif
       
    28 
       
    29     
       
    30 // -----------------------------------------------------------------------------
       
    31 // UT_CQwertyKeyMap::NewL
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 UT_CQwertyKeyMap* UT_CQwertyKeyMap::NewL()
       
    35     {
       
    36     UT_CQwertyKeyMap* self = UT_CQwertyKeyMap::NewLC();
       
    37     CleanupStack::Pop(self);
       
    38     return self;
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // UT_CQwertyKeyMap::NewLC
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 UT_CQwertyKeyMap* UT_CQwertyKeyMap::NewLC()
       
    46     {
       
    47     UT_CQwertyKeyMap* self = new (ELeave) UT_CQwertyKeyMap();
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL();
       
    50     return self;
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // UT_CQwertyKeyMap::~UT_CQwertyKeyMap
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 UT_CQwertyKeyMap::~UT_CQwertyKeyMap()
       
    58     {
       
    59     delete iKeyMap;
       
    60     iKeyMap = NULL;
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // UT_CQwertyKeyMap::UT_CQwertyKeyMap
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 UT_CQwertyKeyMap::UT_CQwertyKeyMap()
       
    68     {
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // UT_CQwertyKeyMap::ConstructL
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void UT_CQwertyKeyMap::ConstructL()
       
    76     {
       
    77     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    78     // It generates the test case table.
       
    79     CEUnitTestSuiteClass::ConstructL();
       
    80     
       
    81     
       
    82     // When instantiating keymap was moved to here, it removed a resource leak.
       
    83     iKeyMap = CQwertyKeyMap::NewL();
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // UT_CQwertyKeyMap::SetupL
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void UT_CQwertyKeyMap::SetupL()
       
    91     {
       
    92 #if defined(USE_ORBIT_KEYMAP)
       
    93     // Create singleton outside actual test cases so that it is not treated as
       
    94     // resource leak, since it can't be deleted.
       
    95     HbKeymapFactory::instance();
       
    96 #endif
       
    97     }
       
    98     
       
    99 // -----------------------------------------------------------------------------
       
   100 // UT_CQwertyKeyMap::Teardown
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void UT_CQwertyKeyMap::Teardown()
       
   104     {
       
   105     }
       
   106 
       
   107 
       
   108 // TEST CASES
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // UT_CQwertyKeyMap::UT_NewLL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void UT_CQwertyKeyMap::UT_NewLL()
       
   115     {
       
   116 #if defined(USE_ORBIT_KEYMAP)
       
   117     // Check each key has been mapped
       
   118 	EUNIT_ASSERT_EQUALS(CQwertyKeyMap::EAmountOfKeysInQwertyKeypad,
       
   119 					    iKeyMap->iKeyMapping.count());
       
   120 
       
   121 	const TInt KAmountOfKeysInUse = 32;
       
   122 	// Note: depending on the language, the keymaps have 32..36 keys.
       
   123 	// So far no language has the full 44 keys.
       
   124     for (TInt i = 0; i < KAmountOfKeysInUse; ++i)
       
   125         {
       
   126         EUNIT_ASSERT(iKeyMap->iKeyMapping.at(i).length() > 0);
       
   127         }
       
   128 #endif
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // UT_CQwertyKeyMap::UT_GetMappedStringL
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 void UT_CQwertyKeyMap::UT_GetMappedStringL()
       
   136 	{
       
   137 	_LIT(KAlpha, "AbCQWe");
       
   138 	_LIT(KNumeric, "abcqwe");
       
   139 	HBufC* numericBuf = iKeyMap->GetMappedStringL( KAlpha );
       
   140 	CleanupStack::PushL( numericBuf );
       
   141 	EUNIT_ASSERT_EQUALS( *numericBuf, KNumeric );
       
   142 	CleanupStack::PopAndDestroy( numericBuf );
       
   143 	numericBuf = NULL;
       
   144 	}
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // UT_CQwertyKeyMap::UT_GetNumericLimitsL
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void UT_CQwertyKeyMap::UT_GetNumericLimitsL()
       
   151     {
       
   152     QString lowerLimit;
       
   153     QString upperLimit;
       
   154     TInt err = iKeyMap->GetNumericLimits("we", lowerLimit, upperLimit);
       
   155     QString expectedLowerLimit("18577348462903295");
       
   156     QString expectedUpperLimit("18858823439613952");
       
   157     EUNIT_ASSERT(lowerLimit == expectedLowerLimit);
       
   158     EUNIT_ASSERT(upperLimit == expectedUpperLimit);
       
   159     }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // UT_CQwertyKeyMap::UT_GetNumericLimitsBeginsByFirstKeyL
       
   163 // Input string begins by the first key (key Q)
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 void UT_CQwertyKeyMap::UT_GetNumericLimitsBeginsByFirstKeyL()
       
   167     {
       
   168     QString lowerLimit;
       
   169     QString upperLimit;
       
   170     TInt err = iKeyMap->GetNumericLimits("qwe", lowerLimit, upperLimit);
       
   171     QString expectedLowerLimit("290271069732863");
       
   172     QString expectedUpperLimit("294669116243968");
       
   173     EUNIT_ASSERT(lowerLimit == expectedLowerLimit);
       
   174     EUNIT_ASSERT(upperLimit == expectedUpperLimit);
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // UT_CQwertyKeyMap::UT_GetNumericLimitsLongValueL
       
   179 // Input string has more than maximum characters
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void UT_CQwertyKeyMap::UT_GetNumericLimitsLongValueL()
       
   183     {
       
   184     QString lowerLimit;
       
   185     QString upperLimit;
       
   186     // "aaqqsswwddee" => "ee" is ignored, rest are as binary:
       
   187     // 001010 001010 000000 000000 001011 001011 000001 000001 001100 001100
       
   188     // =
       
   189     // 0010 1000 1010 0000 0000 0000 0010 1100 1011 0000 0100 0001 0011 0000 1100
       
   190     // as hex = 28A0002CB04130C, as decimal = 182958746857902860
       
   191     TInt err = iKeyMap->GetNumericLimits("aaqqsswwddee", lowerLimit, upperLimit);
       
   192     QString expectedLowerLimit("182958746857902859");
       
   193     QString expectedUpperLimit("182958746857902861");
       
   194     EUNIT_ASSERT(lowerLimit == expectedLowerLimit);
       
   195     EUNIT_ASSERT(upperLimit == expectedUpperLimit);
       
   196     }
       
   197     
       
   198 //  TEST TABLE
       
   199 
       
   200 EUNIT_BEGIN_TEST_TABLE(
       
   201     UT_CQwertyKeyMap,
       
   202     "UT_CQwertyKeyMap",
       
   203     "UNIT" )
       
   204 
       
   205 EUNIT_TEST(
       
   206     "NewL - test ",
       
   207     "UT_CQwertyKeyMap",
       
   208     "NewL",
       
   209     "FUNCTIONALITY",
       
   210     SetupL, UT_NewLL, Teardown )
       
   211 
       
   212 EUNIT_TEST(
       
   213     "GetMappedString - test ",
       
   214     "UT_CQwertyKeyMap",
       
   215     "GetMappedStringL",
       
   216     "FUNCTIONALITY",
       
   217     SetupL, UT_GetMappedStringL, Teardown )
       
   218 
       
   219 EUNIT_TEST(
       
   220     "GetNumericLimits",
       
   221     "UT_CQwertyKeyMap",
       
   222     "GetNumericLimits",
       
   223     "FUNCTIONALITY",
       
   224     SetupL, UT_GetNumericLimitsL, Teardown )
       
   225 
       
   226 EUNIT_TEST(
       
   227     "GetNumericLimits - begins by first key",
       
   228     "UT_CQwertyKeyMap",
       
   229     "GetNumericLimits",
       
   230     "FUNCTIONALITY",
       
   231     SetupL, UT_GetNumericLimitsBeginsByFirstKeyL, Teardown )
       
   232     
       
   233 EUNIT_TEST(
       
   234     "GetNumericLimits - long input",
       
   235     "UT_CQwertyKeyMap",
       
   236     "GetNumericLimits",
       
   237     "FUNCTIONALITY",
       
   238     SetupL, UT_GetNumericLimitsLongValueL, Teardown )
       
   239     
       
   240 EUNIT_END_TEST_TABLE
       
   241 
       
   242 //  END OF FILE