|
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: Main test class for hspluginmodel library. |
|
15 * |
|
16 */ |
|
17 #include "t_caclient.h" |
|
18 #include "caservice.h" |
|
19 #include "castorageproxy.h" |
|
20 #include "caquery.h" |
|
21 #include "calocalizationentry.h" |
|
22 #include "cainnerentry.h" |
|
23 |
|
24 #ifdef Q_OS_SYMBIAN |
|
25 //s60 |
|
26 #include <e32base.h> |
|
27 //#include <> |
|
28 #include <W32STD.H> |
|
29 #include <APGTASK.H> |
|
30 |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 void TestCaClient::TestLocalizationEntryGetters() |
|
36 { |
|
37 CCaLocalizationEntry *entry(0); |
|
38 _LIT(AttributeName,"AttributeName"); |
|
39 _LIT(StringId,"StringId"); |
|
40 _LIT(TableName,"TableName"); |
|
41 _LIT(LocalizedString,"LocalizedString"); |
|
42 |
|
43 QT_TRAP_THROWING(entry = CCaLocalizationEntry::NewL()); |
|
44 |
|
45 entry->SetRowId(1); |
|
46 entry->SetTextId(2); |
|
47 |
|
48 TRAPD(err, |
|
49 entry->SetAttributeNameL(AttributeName); |
|
50 entry->SetStringIdL(StringId); |
|
51 entry->SetTableNameL(TableName); |
|
52 entry->SetLocalizedStringL(LocalizedString); |
|
53 ); |
|
54 |
|
55 QCOMPARE(err, KErrNone); |
|
56 QCOMPARE(entry->GetRowId(), 1); |
|
57 QCOMPARE(entry->GetTextId(), 2); |
|
58 QCOMPARE(entry->GetAttributeName().Compare(AttributeName), 0); |
|
59 QCOMPARE(entry->GetTableName().Compare(TableName), 0); |
|
60 QCOMPARE(entry->GetStringId().Compare(StringId), 0); |
|
61 QCOMPARE(entry->GetLocalizedString().Compare(LocalizedString), 0); |
|
62 |
|
63 delete entry; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 void TestCaClient::TestLocalizationTApp() |
|
70 { |
|
71 _LIT( KTestDbSource, "C:\\testing\\data\\t_caclient\\castorage.db" ); // normal db |
|
72 _LIT( KTestDbDest, "C:\\castorage.db" ); |
|
73 |
|
74 RFs fs; |
|
75 User::LeaveIfError( fs.Connect() ); |
|
76 CFileMan* fileManager = CFileMan::NewL( fs ); |
|
77 |
|
78 fileManager->Copy( KTestDbSource, KTestDbDest ); |
|
79 |
|
80 |
|
81 CCaStorageProxy* proxy = CCaStorageProxy::NewL(); |
|
82 |
|
83 |
|
84 _LIT(BadLocTxt,"loc://emailTest_/haha"); |
|
85 _LIT(BadQmTxt,"loc://haha/haha"); |
|
86 |
|
87 _LIT(GoodLocTxt,"loc://emailTest_/txt_applib_dblist_games"); |
|
88 _LIT(GoodLocKey,"txt_applib_dblist_games"); |
|
89 _LIT(GoodLocResult,"Games"); |
|
90 |
|
91 |
|
92 |
|
93 CCaInnerEntry* entry = CCaInnerEntry::NewL(); |
|
94 |
|
95 entry->SetTextL( GoodLocTxt ); |
|
96 CCaLocalizationEntry* locEntry = proxy->LocalizeTextL( entry ); |
|
97 QVERIFY( !locEntry->GetStringId().Compare( GoodLocKey ) ); |
|
98 QVERIFY( !entry->GetText().Compare( GoodLocResult ) ); |
|
99 delete locEntry; |
|
100 |
|
101 entry->SetDescriptionL( BadLocTxt ); |
|
102 CCaLocalizationEntry* locEntry2 = proxy->LocalizeDescriptionL( entry ); |
|
103 QVERIFY( locEntry2 == NULL ); |
|
104 QVERIFY( !entry->GetDescription().Compare( BadLocTxt ) ); |
|
105 delete locEntry2; |
|
106 |
|
107 entry->SetDescriptionL( GoodLocTxt ); |
|
108 CCaLocalizationEntry* locEntry3 = proxy->LocalizeDescriptionL( entry ); |
|
109 QVERIFY( !locEntry3->GetStringId().Compare( GoodLocKey ) ); |
|
110 QVERIFY( !entry->GetDescription().Compare( GoodLocResult ) ); |
|
111 delete locEntry3; |
|
112 |
|
113 delete fileManager; |
|
114 fs.Close(); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void TestCaClient::TestCreateLocalizedItem() |
|
121 { |
|
122 { |
|
123 const CaEntry constItem; |
|
124 QCOMPARE(constItem.role(), ItemEntryRole); |
|
125 |
|
126 //create item |
|
127 //check if proper entry returned |
|
128 CaEntry item; |
|
129 item.setText("testName",true); |
|
130 item.setAttribute("attrName1", "attrVal1"); |
|
131 item.setEntryTypeName("test"); |
|
132 item.setFlags(RemovableEntryFlag); |
|
133 item.setDescription("description",true); |
|
134 CaIconDescription iconDescription; |
|
135 iconDescription.setFilename("iconFileName"); |
|
136 iconDescription.setSkinId("iconSkinId"); |
|
137 iconDescription.setApplicationId("268458321"); |
|
138 |
|
139 item.setIconDescription(iconDescription); |
|
140 |
|
141 QSharedPointer<CaService> service = CaService::instance(); |
|
142 QSharedPointer<CaEntry> resultItem = service->createEntry(item); |
|
143 QCOMPARE(service->lastError(), NoErrorCode); |
|
144 QVERIFY(!resultItem.isNull()); |
|
145 QCOMPARE(resultItem->role(), ItemEntryRole); |
|
146 QCOMPARE(item.text(),resultItem->text()); |
|
147 QCOMPARE(item.description(),resultItem->description()); |
|
148 QCOMPARE(item.entryTypeName(),resultItem->entryTypeName()); |
|
149 QCOMPARE(QString("attrVal1"),resultItem->attribute("attrName1")); |
|
150 QCOMPARE(item.flags(),resultItem->flags()); |
|
151 int itId =item.id(); |
|
152 int resItId =resultItem->id(); |
|
153 QVERIFY(itId != resItId); |
|
154 QCOMPARE(iconDescription.filename(),resultItem->iconDescription().filename()); |
|
155 QCOMPARE(iconDescription.skinId(),resultItem->iconDescription().skinId()); |
|
156 QCOMPARE(iconDescription.applicationId(),resultItem->iconDescription().applicationId()); |
|
157 |
|
158 // entry from storage |
|
159 QSharedPointer<CaEntry> storageItem1 = service->getEntry(resultItem->id()); |
|
160 QVERIFY(storageItem1); |
|
161 QCOMPARE(QString("testName"),storageItem1->text()); |
|
162 QCOMPARE(QString("description"),storageItem1->description()); |
|
163 QCOMPARE(QString("test"),storageItem1->entryTypeName()); |
|
164 QCOMPARE(QString("attrVal1"),storageItem1->attribute("attrName1")); |
|
165 EntryFlags flags = item.flags(); |
|
166 EntryFlags storageFlags = storageItem1->flags(); |
|
167 QCOMPARE(iconDescription.filename(),storageItem1->iconDescription().filename()); |
|
168 QCOMPARE(iconDescription.skinId(),storageItem1->iconDescription().skinId()); |
|
169 QCOMPARE(iconDescription.applicationId(),storageItem1->iconDescription().applicationId()); |
|
170 QVERIFY(storageItem1->iconDescription().id() > 0); |
|
171 |
|
172 QCOMPARE(flags ,storageFlags); |
|
173 |
|
174 //Cleanup |
|
175 service->removeEntry(*resultItem); |
|
176 } |
|
177 } |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 #endif //Q_OS_SYMBIAN |