|
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 #include <memory> |
|
19 |
|
20 #include "TestHarness.h" |
|
21 |
|
22 #include "../../inc.s60/mapnsettings.h" |
|
23 |
|
24 #include "javastorage.h" |
|
25 #include "javastorageexception.h" |
|
26 #include "javastoragenames.h" |
|
27 #include "javauid.h" |
|
28 #include "javasymbianoslayer.h" |
|
29 #include "logger.h" |
|
30 |
|
31 using namespace CENREP; |
|
32 using namespace java::storage; |
|
33 |
|
34 TEST_GROUP(TestAPNSettings) |
|
35 { |
|
36 MAPNSettings* iApnSettings; |
|
37 |
|
38 TEST_SETUP() |
|
39 { |
|
40 iApnSettings = GetAPNSettingsLC(KAPNSettingsVersion); |
|
41 CleanupStack::Pop(); |
|
42 } |
|
43 TEST_TEARDOWN() |
|
44 { |
|
45 delete iApnSettings; |
|
46 iApnSettings = NULL; |
|
47 } |
|
48 }; |
|
49 |
|
50 /** |
|
51 * Test Set and Get APN |
|
52 * |
|
53 * 1. Test set with non-existing UID. |
|
54 * 2. Test set with non-existing APN ID. |
|
55 * 3. Test set with non-existing UID and APN ID. |
|
56 * 4. Test set with existing UID and APN ID. |
|
57 */ |
|
58 TEST(TestAPNSettings, TestGetSetAPN) |
|
59 { |
|
60 java::util::Uid javaUid(L"[ec0c0c0c]"); |
|
61 TUid appUid; |
|
62 uidToTUid(javaUid, appUid); |
|
63 |
|
64 JavaStorageApplicationEntry_t packageEntry; |
|
65 JavaStorageEntry attr; |
|
66 |
|
67 attr.setEntry(PACKAGE_NAME, L"TestiApnSettings"); |
|
68 packageEntry.insert(attr); |
|
69 |
|
70 attr.setEntry(ID, javaUid.toString()); |
|
71 packageEntry.insert(attr); |
|
72 |
|
73 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
74 packageEntry.insert(attr); |
|
75 |
|
76 std::auto_ptr<JavaStorage> js(JavaStorage::createInstance()); |
|
77 |
|
78 try |
|
79 { |
|
80 js->open(); |
|
81 js->startTransaction(); |
|
82 js->write(APPLICATION_PACKAGE_TABLE, packageEntry); |
|
83 js->commitTransaction(); |
|
84 } |
|
85 catch (JavaStorageException& aJse) |
|
86 { |
|
87 std::string errorStr = "Failed to write: "; |
|
88 errorStr.append(aJse.toString()); |
|
89 FAIL(errorStr.c_str()); |
|
90 } |
|
91 |
|
92 // 1. Test set with non-existing UID. |
|
93 iApnSettings->SetAPNL(0, 1); |
|
94 TUint32 apn = iApnSettings->GetAPNIdL(0); |
|
95 CHECK(apn == KMIDletSuiteAPNNotSpecified); |
|
96 |
|
97 |
|
98 // 2. Test set with non-existing APN ID. |
|
99 iApnSettings->SetAPNL(appUid.iUid, 10101); |
|
100 apn = iApnSettings->GetAPNIdL(appUid.iUid); |
|
101 CHECK(apn == 10101); |
|
102 |
|
103 // 3. Test set with non-existing UID and APN ID. |
|
104 iApnSettings->SetAPNL(12345, 10101); |
|
105 apn = iApnSettings->GetAPNIdL(12345); |
|
106 CHECK(apn == KMIDletSuiteAPNNotSpecified); |
|
107 |
|
108 // 4. Test set with existing UID and APN ID. |
|
109 iApnSettings->SetAPNL(appUid.iUid, 1); |
|
110 apn = iApnSettings->GetAPNIdL(appUid.iUid); |
|
111 CHECK(apn == 1); |
|
112 |
|
113 try |
|
114 { |
|
115 js->remove(APPLICATION_PACKAGE_TABLE, packageEntry); |
|
116 js->close(); |
|
117 } |
|
118 catch (JavaStorageException& aJse) |
|
119 { |
|
120 std::string errorStr = "Failed to remove: "; |
|
121 errorStr.append(aJse.toString()); |
|
122 FAIL(errorStr.c_str()); |
|
123 } |
|
124 } |
|
125 |
|
126 /** |
|
127 * Test Remove APN. |
|
128 * |
|
129 * 1. Test remove not set. |
|
130 * 2. Test remove. |
|
131 * 3. Test remove non-existing. |
|
132 * 4. Test get default Java APN. |
|
133 */ |
|
134 TEST(TestAPNSettings, TestRemoveAPN) |
|
135 { |
|
136 java::util::Uid javaUid(L"[ed0d0d0d]"); |
|
137 TUid appUid; |
|
138 uidToTUid(javaUid, appUid); |
|
139 |
|
140 JavaStorageApplicationEntry_t packageEntry; |
|
141 JavaStorageEntry attr; |
|
142 |
|
143 attr.setEntry(PACKAGE_NAME, L"TestiApnSettings"); |
|
144 packageEntry.insert(attr); |
|
145 |
|
146 attr.setEntry(ID, javaUid.toString()); |
|
147 packageEntry.insert(attr); |
|
148 |
|
149 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
150 packageEntry.insert(attr); |
|
151 |
|
152 std::auto_ptr<JavaStorage> js(JavaStorage::createInstance()); |
|
153 |
|
154 try |
|
155 { |
|
156 js->open(); |
|
157 js->startTransaction(); |
|
158 js->write(APPLICATION_PACKAGE_TABLE, packageEntry); |
|
159 js->commitTransaction(); |
|
160 } |
|
161 catch (JavaStorageException& aJse) |
|
162 { |
|
163 std::string errorStr = "Failed to write: "; |
|
164 errorStr.append(aJse.toString()); |
|
165 FAIL(errorStr.c_str()); |
|
166 } |
|
167 |
|
168 // 1. Test set with non-existing UID. |
|
169 iApnSettings->RemoveL(appUid.iUid); |
|
170 TUint32 apn = iApnSettings->GetAPNIdL(appUid.iUid); |
|
171 CHECK(apn == KErrNotFound); |
|
172 |
|
173 // 2. Test remove. |
|
174 iApnSettings->SetAPNL(appUid.iUid, 1); |
|
175 apn = iApnSettings->GetAPNIdL(appUid.iUid); |
|
176 CHECK(apn == 1); |
|
177 |
|
178 iApnSettings->RemoveL(appUid.iUid); |
|
179 apn = iApnSettings->GetAPNIdL(appUid.iUid); |
|
180 CHECK(apn == KErrNotFound); |
|
181 |
|
182 // 3. Test remove non-existing. |
|
183 iApnSettings->RemoveL(1); |
|
184 |
|
185 // 4. Test get default Java APN. |
|
186 CHECK(iApnSettings->GetJavaDefaultAPNL() == KMIDletSuiteAPNNotSpecified); |
|
187 |
|
188 try |
|
189 { |
|
190 js->remove(APPLICATION_PACKAGE_TABLE, packageEntry); |
|
191 js->close(); |
|
192 } |
|
193 catch (JavaStorageException& aJse) |
|
194 { |
|
195 std::string errorStr = "Failed to remove: "; |
|
196 errorStr.append(aJse.toString()); |
|
197 FAIL(errorStr.c_str()); |
|
198 } |
|
199 } |
|
200 |