summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/cntplsql/src/t_ckoreankeymap.cpp
blob: 32d4dcfae9233729318e22126754c8fe550964f0 (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
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* 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_ckoreankeymap.h"
#include "ckoreankeymap.h"
#include <QString>

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


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

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

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

// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::UT_CKoreanKeyMap
// -----------------------------------------------------------------------------
//
UT_CKoreanKeyMap::UT_CKoreanKeyMap()
    {
    }

// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::ConstructL
// -----------------------------------------------------------------------------
//
void UT_CKoreanKeyMap::ConstructL()
    {
    // The ConstructL from the base class CEUnitTestSuiteClass must be called.
    // It generates the test case table.
    CEUnitTestSuiteClass::ConstructL();

    iKeyMap = CKoreanKeyMap::NewL();
    
    
    // Doing this here removes a resource leak from test case that uses Korean text
    QChar koreanChar[] = {0x3131};
    QString koreanText(koreanChar, sizeof(koreanChar) / sizeof(QChar));
    iKeyMap->IsLanguageSupported(koreanText);
    }

// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::SetupL
// -----------------------------------------------------------------------------
//
void UT_CKoreanKeyMap::SetupL()
    {
    }
    
// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::Teardown
// -----------------------------------------------------------------------------
//
void UT_CKoreanKeyMap::Teardown()
    {
    }


// TEST CASES

// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::UT_GetMappedString_JamoL
// -----------------------------------------------------------------------------
//
void UT_CKoreanKeyMap::UT_GetMappedString_JamoL()
	{
	QString koreanInput;
	koreanInput += QChar(0x1100); // key-1
	koreanInput += QChar(0x1101); // key-1 key-#
	koreanInput += QChar(0x1102); // key-2

	QString result = iKeyMap->GetMappedString(koreanInput);

	EUNIT_ASSERT(result == "11b2");
	}

// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::UT_GetMappedString_HangulL
// -----------------------------------------------------------------------------
//
void UT_CKoreanKeyMap::UT_GetMappedString_HangulL()
    {
    QString koreanInput;
    koreanInput += QChar(0xAC00); // cho:key-1  jung:key-3  jong:none
    koreanInput += QChar(0xAC50); // cho:key-1  jung:key-3 key-*  jong:key-1 key-*

    QString result = iKeyMap->GetMappedString(koreanInput);

    EUNIT_ASSERT(result == "13 13a1a ");
    
    
    
    
    QString koreanInput2;
    koreanInput2 += QChar(0xD604);

    QString result2 = iKeyMap->GetMappedString(koreanInput2);

    EUNIT_ASSERT(result2 == "8a33a2 ");
    }

// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::UT_GetMappedString_MixedL
// -----------------------------------------------------------------------------
//
void UT_CKoreanKeyMap::UT_GetMappedString_MixedL()
    {
    QString koreanInput;
    koreanInput += QChar(0xAC00); // cho:key-1  jung:key-3  jong:none
    koreanInput += QChar(0x1101); // key-1 key-#
    koreanInput += QChar(0x3161); // key-0
    koreanInput += QChar(0xAC50); // cho:key-1  jung:key-3 key-*  jong:key-1 key-*
    koreanInput += QChar(0x1168); // key-3 key-3 key-* key-9
    koreanInput += QChar(0x3138); // key-2 key-* key-#

    QString result = iKeyMap->GetMappedString(koreanInput);

    EUNIT_ASSERT(result == "13 1b013a1a 33a92ab");
    }

// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::UT_GetMappedString_TokenizeHangulL
// -----------------------------------------------------------------------------
//
void UT_CKoreanKeyMap::UT_GetMappedString_TokenizeHangulL()
    {
    QString koreanInput;
    koreanInput += QChar(0xAC50); // cho:key-1  jung:key-3 key-*  jong:key-1 key-*
    koreanInput += QChar(0xB070); // cho:key-1 key-#  jung:key-0 key-9  jong:key-5
    koreanInput += QChar(0xB204); // cho:key-2  jung:key-6 key-6  jong:none

    QString result = iKeyMap->GetMappedString(koreanInput);

    EUNIT_ASSERT(result == "13a1a 1b095 266 ");
    }

// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::UT_IsLanguageSupported_LatinTextL
// -----------------------------------------------------------------------------
//
void UT_CKoreanKeyMap::UT_IsLanguageSupported_LatinTextL()
    {
    EUNIT_ASSERT_EQUALS(EFalse, iKeyMap->IsLanguageSupported("abcdef ghijk"));
    EUNIT_ASSERT_EQUALS(EFalse, iKeyMap->IsLanguageSupported("123"));
    EUNIT_ASSERT_EQUALS(EFalse, iKeyMap->IsLanguageSupported("-a (h % *"));
    
    // Default behaviour is latin
    EUNIT_ASSERT_EQUALS(EFalse, iKeyMap->IsLanguageSupported(""));
    }

// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::UT_IsLanguageSupported_KoreanTextL
// -----------------------------------------------------------------------------
//
void UT_CKoreanKeyMap::UT_IsLanguageSupported_KoreanTextL()
    {
    // Note: korean text codec does not recognize Hangul Jamo characters (U1100+)
    
    QChar someKoreanChars[] = {0x3131, 0x315a, 0x315b, 0x3155, 0x3155, 0x3155};
    QString koreanText(someKoreanChars, sizeof(someKoreanChars) / sizeof(QChar));
    
    EUNIT_ASSERT_EQUALS(ETrue, iKeyMap->IsLanguageSupported(koreanText));
    
    QChar someKoreanChars2[] = {0xac00, 0xb500, 0x3157, 0xd102, 0xc14f, 0x3163,
            0xd10a, 0xbbcc, 0xac00, 0x314d, 0x3150, 0xd7a3, 0xc995 }; 
    QString koreanText2(someKoreanChars2, sizeof(someKoreanChars2) / sizeof(QChar));
    
    EUNIT_ASSERT_EQUALS(ETrue, iKeyMap->IsLanguageSupported(koreanText2));
    }

// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::UT_IsLanguageSupported_MixedTextL
// Both Korean and Latin characters. Looks like korean text codec understands
// also latin characters.
// -----------------------------------------------------------------------------
//
void UT_CKoreanKeyMap::UT_IsLanguageSupported_MixedTextL()
    {
    QChar mixedText[] =
        {0xac00, 0xb500, 'a', 0xd102, 0xc14f, 'H', 0xd10a, 0xbbcc, 0xac00,
         0xd7a3, 0xc995, 'B', 'n'};
    QString mixed(mixedText, sizeof(mixedText) / sizeof(QChar));
    
    EUNIT_ASSERT_EQUALS(ETrue, iKeyMap->IsLanguageSupported(mixed));
    
    
    QChar mixedText2[] = {'n', 0xacdf};
    QString mixed2(mixedText2, sizeof(mixedText2) / sizeof(QChar));
    
    EUNIT_ASSERT_EQUALS(ETrue, iKeyMap->IsLanguageSupported(mixed2));
    }


// -----------------------------------------------------------------------------
// UT_CKoreanKeyMap::UT_IsLanguageSupported_TextWithJamoL
// Text includes Jamo characters.
// -----------------------------------------------------------------------------
//
void UT_CKoreanKeyMap::UT_IsLanguageSupported_TextWithJamoL()
    {
    QChar textWithJamo[] = {0xac00, 0x1100, 0x11ff, 0xc14f, 0x1170};
    QString jamoText(textWithJamo, sizeof(textWithJamo) / sizeof(QChar));
    
    EUNIT_ASSERT_EQUALS(ETrue, iKeyMap->IsLanguageSupported(jamoText));
    }

//  TEST TABLE

EUNIT_BEGIN_TEST_TABLE(
    UT_CKoreanKeyMap,
    "UT_CKoreanKeyMap",
    "UNIT" )

EUNIT_TEST(
    "GetMappedString - test Jamo chars",
    "UT_CKoreanKeyMap",
    "GetMappedStringL",
    "FUNCTIONALITY",
    SetupL, UT_GetMappedString_JamoL, Teardown )

EUNIT_TEST(
    "GetMappedString - test Hangul chars",
    "UT_CKoreanKeyMap",
    "GetMappedStringL",
    "FUNCTIONALITY",
    SetupL, UT_GetMappedString_HangulL, Teardown )

EUNIT_TEST(
    "GetMappedString - test mixed chars",
    "UT_CKoreanKeyMap",
    "GetMappedStringL",
    "FUNCTIONALITY",
    SetupL, UT_GetMappedString_MixedL, Teardown )

EUNIT_TEST(
    "GetMappedString - test tokenizing Hangul",
    "UT_CKoreanKeyMap",
    "GetMappedStringL",
    "FUNCTIONALITY",
    SetupL, UT_GetMappedString_TokenizeHangulL, Teardown )
    
EUNIT_TEST(
    "IsLanguageSupported - test latin text",
    "UT_CKoreanKeyMap",
    "IsLanguageSupported",
    "FUNCTIONALITY",
    SetupL, UT_IsLanguageSupported_LatinTextL, Teardown )

EUNIT_TEST(
    "IsLanguageSupported - test korean text",
    "UT_CKoreanKeyMap",
    "IsLanguageSupported",
    "FUNCTIONALITY",
    SetupL, UT_IsLanguageSupported_KoreanTextL, Teardown )

EUNIT_TEST(
    "IsLanguageSupported - test mixed text",
    "UT_CKoreanKeyMap",
    "IsLanguageSupported",
    "FUNCTIONALITY",
    SetupL, UT_IsLanguageSupported_MixedTextL, Teardown )

EUNIT_TEST(
    "IsLanguageSupported - test Jamo chars",
    "UT_CKoreanKeyMap",
    "IsLanguageSupported",
    "FUNCTIONALITY",
    SetupL, UT_IsLanguageSupported_TextWithJamoL, Teardown )
    
EUNIT_END_TEST_TABLE

//  END OF FILE