summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/cntplsql/src/t_cqwertykeymap.cpp
blob: b3afeb201076850e94b64037fd3cb403e44015f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/*
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Unit test class for testing CQwertyKeyMap
*
*/

// INTERNAL INCLUDES
#include "t_cqwertykeymap.h"
#include "cqwertykeymap.h"
#include <QString>

// SYSTEM INCLUDES
#include <digia/eunit/eunitmacros.h>
#include <hbinputkeymapfactory.h>

    
// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::NewL
// -----------------------------------------------------------------------------
//
UT_CQwertyKeyMap* UT_CQwertyKeyMap::NewL()
    {
    UT_CQwertyKeyMap* self = UT_CQwertyKeyMap::NewLC();
    CleanupStack::Pop(self);
    return self;
    }

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::NewLC
// -----------------------------------------------------------------------------
//
UT_CQwertyKeyMap* UT_CQwertyKeyMap::NewLC()
    {
    UT_CQwertyKeyMap* self = new (ELeave) UT_CQwertyKeyMap();
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::~UT_CQwertyKeyMap
// -----------------------------------------------------------------------------
//
UT_CQwertyKeyMap::~UT_CQwertyKeyMap()
    {
    delete iKeyMap;
    iKeyMap = NULL;
    }

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::UT_CQwertyKeyMap
// -----------------------------------------------------------------------------
//
UT_CQwertyKeyMap::UT_CQwertyKeyMap()
    {
    }

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::ConstructL
// -----------------------------------------------------------------------------
//
void UT_CQwertyKeyMap::ConstructL()
    {
    // The ConstructL from the base class CEUnitTestSuiteClass must be called.
    // It generates the test case table.
    CEUnitTestSuiteClass::ConstructL();
    
    
    // When instantiating keymap was moved to here, it removed a resource leak.
    iKeyMap = CQwertyKeyMap::NewL();
    }

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::SetupL
// -----------------------------------------------------------------------------
//
void UT_CQwertyKeyMap::SetupL()
    {
    // Create singleton outside actual test cases so that it is not treated as
    // resource leak, since it can't be deleted.
    HbKeymapFactory::instance();
    }
    
// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::Teardown
// -----------------------------------------------------------------------------
//
void UT_CQwertyKeyMap::Teardown()
    {
    }


// TEST CASES

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::UT_NewLL
// -----------------------------------------------------------------------------
//
void UT_CQwertyKeyMap::UT_NewLL()
    {
    // Note: depending on the language, the keymaps have variable amount of keys.
    // Check that at least minimum amount of keys has been mapped.
    const TInt KMinimumAmountOfKeysInUse = 32;
    
    EUNIT_ASSERT(iKeyMap->iAmountOfKeys >= KMinimumAmountOfKeysInUse);

    TInt keys = iKeyMap->iKeyMapping.count();
	EUNIT_ASSERT(keys >= KMinimumAmountOfKeysInUse);
	
    for (TInt i = 0; i < KMinimumAmountOfKeysInUse; ++i)
        {
        EUNIT_ASSERT(iKeyMap->iKeyMapping.at(i).length() > 0);
        }
    }

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::UT_GetMappedStringL
// -----------------------------------------------------------------------------
//
void UT_CQwertyKeyMap::UT_GetMappedStringL()
	{
	_LIT(KAlpha, "AbCQWe");
	_LIT(KNumeric, "abcqwe");
	HBufC* numericBuf = iKeyMap->GetMappedStringL( KAlpha );
	CleanupStack::PushL( numericBuf );
	EUNIT_ASSERT_EQUALS( *numericBuf, KNumeric );
	CleanupStack::PopAndDestroy( numericBuf );
	numericBuf = NULL;
	}

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::UT_GetNumericLimitsL
// -----------------------------------------------------------------------------
//
void UT_CQwertyKeyMap::UT_GetNumericLimitsL()
    {
    QString lowerLimit;
    QString upperLimit; 
    TInt err = iKeyMap->GetNumericLimits("we", lowerLimit, upperLimit);
    QString expectedLowerLimit("18577348462903295");
    QString expectedUpperLimit("18858823439613952");
    EUNIT_ASSERT(lowerLimit == expectedLowerLimit);
    EUNIT_ASSERT(upperLimit == expectedUpperLimit);
    }

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::UT_GetNumericLimitsBeginsByFirstKeyL
// Input string begins by the first key (key Q)
// -----------------------------------------------------------------------------
//
void UT_CQwertyKeyMap::UT_GetNumericLimitsBeginsByFirstKeyL()
    {
    QString lowerLimit;
    QString upperLimit;
    TInt err = iKeyMap->GetNumericLimits("qwe", lowerLimit, upperLimit);
    QString expectedLowerLimit("290271069732863");
    QString expectedUpperLimit("294669116243968");
    EUNIT_ASSERT(lowerLimit == expectedLowerLimit);
    EUNIT_ASSERT(upperLimit == expectedUpperLimit);
    }

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::UT_GetNumericLimitsLongValueL
// Input string has more than maximum characters
// -----------------------------------------------------------------------------
//
void UT_CQwertyKeyMap::UT_GetNumericLimitsLongValueL()
    {
    QString lowerLimit;
    QString upperLimit;
    // "aaqqsswwddee" => "ee" is ignored, rest are as binary:
    // 001010 001010 000000 000000 001011 001011 000001 000001 001100 001100
    // =
    // 0010 1000 1010 0000 0000 0000 0010 1100 1011 0000 0100 0001 0011 0000 1100
    // as hex = 28A0002CB04130C, as decimal = 182958746857902860
    TInt err = iKeyMap->GetNumericLimits("aaqqsswwddee", lowerLimit, upperLimit);
    QString expectedLowerLimit("182958746857902859");
    QString expectedUpperLimit("182958746857902861");
    EUNIT_ASSERT(lowerLimit == expectedLowerLimit);
    EUNIT_ASSERT(upperLimit == expectedUpperLimit);
    }

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::UT_CheckDigitsAreMappedL
// Note: this test case works only for languages using 0,1,2..9 as decimal
// numbers.
// -----------------------------------------------------------------------------
//
void UT_CQwertyKeyMap::UT_CheckDigitsAreMappedL()
    {
    TInt keys = iKeyMap->iKeyMapping.count();
    const TInt KAmountOfDecimalDigits = 10;
    TBool hasDigitBeenMapped[ KAmountOfDecimalDigits ] = { 0 };
    
    for (TInt i = 0; i < keys; ++i)
        {
        for (TInt digit = 0; digit < KAmountOfDecimalDigits; ++digit)
            {
            QChar ch(digit + '0');
            if (iKeyMap->iKeyMapping[i].contains(ch))
                {
                hasDigitBeenMapped[digit] = ETrue;
                }
            }
        }
    
    // Check every decimal digit was mapped
    for (TInt digit = 0; digit < KAmountOfDecimalDigits; ++digit)
        {
        QChar ch(digit + '0');
        EUNIT_ASSERT(hasDigitBeenMapped[digit]);
        }
    
    // TODO: handle all languages present
    }

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::UT_CheckAmountOfMappedKeysL
// Check the internal qwerty keymap does not have unnecessary (empty) entries.
// -----------------------------------------------------------------------------
//
void UT_CQwertyKeyMap::UT_CheckAmountOfMappedKeysL()
    {
    TInt amountOfMappedKeys = iKeyMap->iAmountOfKeys;
    
    EUNIT_ASSERT_EQUALS(amountOfMappedKeys, iKeyMap->iKeyNames.count());
    EUNIT_ASSERT_EQUALS(amountOfMappedKeys, iKeyMap->iKeyValues.count());
    //EUNIT_ASSERT_EQUALS(amountOfMappedKeys, iKeyMap->iKeyMapping.count());
    }

// -----------------------------------------------------------------------------
// UT_CQwertyKeyMap::UT_CheckSpecialCharactersL
// Check that the special characters from HbKeyboardSctLandscape are mapped.
// -----------------------------------------------------------------------------
//
void UT_CQwertyKeyMap::UT_CheckSpecialCharactersL()
    {
    // NOTE: these test cases pass in english, but not necesary with other
    // languages, as each language has its own keymap with some differences.

    _LIT(KInputWithSpecialChars, "<A1>C#W*2-($)&");
    _LIT(KMappedResult, "#a1#c#w#2-###&");
    HBufC* mapped = iKeyMap->GetMappedStringL(KInputWithSpecialChars);
    CleanupStack::PushL(mapped);
    EUNIT_ASSERT_EQUALS(*mapped, KMappedResult);
    CleanupStack::PopAndDestroy(mapped);
    mapped = NULL;
    
    
    // Those special characters (e.g '.') that are present in virtual
    // QWERTY keymap, have been mapped to individual keys.
    // That depends on the used language.
    
    _LIT(KInputWithSpecialChars2, ".8Hg %01 kK£");
    _LIT(KMappedResult2, ".8hg #01 kk#");
    mapped = iKeyMap->GetMappedStringL(KInputWithSpecialChars2);
    CleanupStack::PushL(mapped);
    EUNIT_ASSERT_EQUALS(*mapped, KMappedResult2);
    CleanupStack::PopAndDestroy(mapped);
    mapped = NULL;
    }

//  TEST TABLE

EUNIT_BEGIN_TEST_TABLE(
    UT_CQwertyKeyMap,
    "UT_CQwertyKeyMap",
    "UNIT" )

EUNIT_TEST(
    "NewL - test ",
    "UT_CQwertyKeyMap",
    "NewL",
    "FUNCTIONALITY",
    SetupL, UT_NewLL, Teardown )

EUNIT_TEST(
    "GetMappedString - test ",
    "UT_CQwertyKeyMap",
    "GetMappedStringL",
    "FUNCTIONALITY",
    SetupL, UT_GetMappedStringL, Teardown )

EUNIT_TEST(
    "GetNumericLimits",
    "UT_CQwertyKeyMap",
    "GetNumericLimits",
    "FUNCTIONALITY",
    SetupL, UT_GetNumericLimitsL, Teardown )

EUNIT_TEST(
    "GetNumericLimits - begins by first key",
    "UT_CQwertyKeyMap",
    "GetNumericLimits",
    "FUNCTIONALITY",
    SetupL, UT_GetNumericLimitsBeginsByFirstKeyL, Teardown )
    
EUNIT_TEST(
    "GetNumericLimits - long input",
    "UT_CQwertyKeyMap",
    "GetNumericLimits",
    "FUNCTIONALITY",
    SetupL, UT_GetNumericLimitsLongValueL, Teardown )

EUNIT_TEST(
    "Check decimal digits are mapped",
    "UT_CQwertyKeyMap",
    "",
    "FUNCTIONALITY",
    SetupL, UT_CheckDigitsAreMappedL, Teardown )

EUNIT_TEST(
    "Check QWERTY keymap does not contain empty entries",
    "UT_CQwertyKeyMap",
    "",
    "FUNCTIONALITY",
    SetupL, UT_CheckAmountOfMappedKeysL, Teardown )

EUNIT_TEST(
    "Check special characters from SCT keymap have been mapped",
    "UT_CQwertyKeyMap",
    "",
    "FUNCTIONALITY",
    SetupL, UT_CheckSpecialCharactersL, Teardown )

EUNIT_END_TEST_TABLE

//  END OF FILE