0
|
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 |
Test the CPF configuration
|
|
19 |
"""
|
|
20 |
import unittest
|
|
21 |
import string
|
|
22 |
import sys,os,shutil
|
|
23 |
|
|
24 |
from cone.public import *
|
|
25 |
from cone.storage import persistentdictionary
|
|
26 |
|
|
27 |
class TestProjectOpen(unittest.TestCase):
|
|
28 |
|
|
29 |
def test_open_project(self):
|
|
30 |
|
|
31 |
p = api.Project(api.Storage(""))
|
|
32 |
self.assertTrue(p)
|
|
33 |
|
|
34 |
def test_open_project_of_non_storage(self):
|
|
35 |
fs = ""
|
|
36 |
try:
|
3
|
37 |
p = api.Project("")
|
0
|
38 |
self.fail("Opening on top of non storage succeeds!!")
|
|
39 |
except exceptions.StorageException:
|
|
40 |
self.assertTrue(True)
|
|
41 |
|
|
42 |
class TestProjectConfigurations(unittest.TestCase):
|
|
43 |
def setUp(self):
|
|
44 |
self.prj = api.Project(api.Storage(""))
|
|
45 |
|
|
46 |
def test_create_configuration(self):
|
|
47 |
self.prj.create_configuration("test.confml")
|
|
48 |
self.assertTrue(self.prj.test_confml)
|
|
49 |
self.assertEquals(self.prj.test_confml.get_path(),"test.confml")
|
3
|
50 |
|
|
51 |
def test_create_configuration_already_existing(self):
|
|
52 |
self.prj.create_configuration("test.confml")
|
|
53 |
try:
|
|
54 |
self.prj.create_configuration("test.confml")
|
|
55 |
self.fail("Succeeded to create already existing configuration")
|
|
56 |
except exceptions.AlreadyExists:
|
|
57 |
pass
|
|
58 |
try:
|
|
59 |
self.prj.add_configuration(api.Configuration("test.confml"))
|
|
60 |
self.fail("Succeeded to create already existing configuration")
|
|
61 |
except exceptions.AlreadyExists:
|
|
62 |
pass
|
|
63 |
|
|
64 |
def test_create_configuration_already_existing_with_overwrite(self):
|
|
65 |
self.prj.create_configuration("test.confml")
|
|
66 |
self.prj.create_configuration("test.confml", True)
|
|
67 |
self.prj.add_configuration(api.Configuration("test.confml"), True)
|
|
68 |
|
0
|
69 |
|
|
70 |
def test_create_and_getconfiguration(self):
|
|
71 |
self.prj.create_configuration("test.confml")
|
|
72 |
self.assertEquals(self.prj.get_configuration("test.confml").get_path(), "test.confml")
|
|
73 |
|
|
74 |
def test_create_multi_and_list(self):
|
|
75 |
self.prj.create_configuration("test1.confml")
|
|
76 |
self.prj.create_configuration("test2.confml")
|
|
77 |
self.prj.create_configuration("test3.confml")
|
|
78 |
self.assertEquals(self.prj.list_configurations(), ["test1.confml",
|
|
79 |
"test2.confml",
|
|
80 |
"test3.confml"])
|
|
81 |
|
|
82 |
def test_create_multi_and_list_with_filters(self):
|
|
83 |
self.prj.create_configuration("test1.confml")
|
|
84 |
self.prj.create_configuration("test2.confml")
|
|
85 |
self.prj.create_configuration("test3.confml")
|
|
86 |
self.prj.create_configuration("test4.confml")
|
|
87 |
self.prj.create_configuration("foo1.confml")
|
|
88 |
self.prj.create_configuration("foo2.confml")
|
|
89 |
self.assertEquals(self.prj.list_configurations(r'test[24]\.confml'),
|
|
90 |
["test2.confml",
|
|
91 |
"test4.confml"])
|
|
92 |
self.assertEquals(self.prj.list_configurations([r'test[24]\.confml', r'foo\d\.confml']),
|
|
93 |
["test2.confml",
|
|
94 |
"test4.confml",
|
|
95 |
"foo1.confml",
|
|
96 |
"foo2.confml"])
|
|
97 |
|
|
98 |
def test_create_multi_and_remove_one(self):
|
|
99 |
self.prj.create_configuration("test1.confml")
|
|
100 |
self.prj.create_configuration("test2.confml")
|
|
101 |
self.prj.create_configuration("test3.confml")
|
|
102 |
self.prj.remove_configuration("test2.confml")
|
|
103 |
self.assertEquals(self.prj.list_configurations(), ["test1.confml",
|
|
104 |
"test3.confml"])
|
|
105 |
|
|
106 |
def test_create_multi_and_remove_all(self):
|
|
107 |
self.prj.create_configuration("test1.confml")
|
|
108 |
self.prj.create_configuration("test2.confml")
|
|
109 |
self.prj.create_configuration("test3.confml")
|
|
110 |
for c in self.prj.list_configurations():
|
|
111 |
self.prj.remove_configuration(c)
|
|
112 |
self.assertEquals(self.prj.list_configurations(), [])
|
|
113 |
|
|
114 |
def test_create_multi_and_add_subconfigurations(self):
|
|
115 |
self.prj.create_configuration("test1.confml")
|
|
116 |
self.prj.create_configuration("test2.confml")
|
|
117 |
self.prj.create_configuration("test3.confml")
|
|
118 |
self.prj.test2_confml.create_configuration("foo/root.confml")
|
|
119 |
conf = self.prj.test2_confml.create_configuration("fii/root.confml")
|
3
|
120 |
conf.add_configuration(api.Configuration("confml/data.confml"))
|
|
121 |
self.assertEquals(conf.get_full_path(),'fii/root.confml')
|
|
122 |
self.assertEquals(conf.get_configuration("confml/data.confml").get_path(),'confml/data.confml')
|
|
123 |
self.assertEquals(conf.get_configuration("confml/data.confml").get_full_path(),'fii/confml/data.confml')
|
0
|
124 |
self.assertTrue(self.prj.is_configuration("test3.confml"))
|
|
125 |
# TODO: this is not working at the moment due to performance problem in
|
|
126 |
# Project.list_all_configurations()
|
|
127 |
# self.assertTrue(self.prj.is_configuration("fii/root.confml"))
|
|
128 |
|
|
129 |
self.assertEquals(self.prj.list_configurations(), ["test1.confml",
|
|
130 |
"test2.confml",
|
|
131 |
"test3.confml"])
|
3
|
132 |
self.assertEquals(self.prj.list_all_configurations(), ['test1.confml',
|
|
133 |
'test2.confml',
|
|
134 |
'foo/root.confml',
|
|
135 |
'fii/root.confml',
|
|
136 |
'fii/confml/data.confml',
|
|
137 |
'test3.confml'])
|
0
|
138 |
self.assertEquals(self.prj.test2_confml.list_configurations(), ["foo/root.confml",
|
|
139 |
"fii/root.confml",])
|
3
|
140 |
self.assertEquals(self.prj.test2_confml.list_all_configurations(), ["foo/root.confml",
|
|
141 |
"fii/root.confml",
|
|
142 |
"fii/confml/data.confml"])
|
0
|
143 |
|
|
144 |
def test_create_multi_and_add_subconfigurations_and_features(self):
|
|
145 |
self.prj.create_configuration("test1.confml")
|
|
146 |
self.prj.create_configuration("test2.confml")
|
|
147 |
self.prj.create_configuration("test3.confml")
|
|
148 |
self.prj.test2_confml.create_configuration("foo/root.confml")
|
|
149 |
self.prj.test2_confml.create_configuration("fii/root.confml")
|
|
150 |
self.prj.test2_confml.foo__root_confml.add_feature(api.Feature("testfea1"))
|
|
151 |
self.prj.test2_confml.foo__root_confml.add_feature(api.Feature("testfea2"))
|
|
152 |
self.prj.test2_confml.foo__root_confml.add_feature(api.Feature("testfea11"),"testfea1")
|
|
153 |
self.prj.test2_confml.fii__root_confml.add_feature(api.Feature("testfea3"))
|
|
154 |
self.prj.test2_confml.fii__root_confml.add_feature(api.Feature("testfea4"))
|
|
155 |
self.prj.test2_confml.fii__root_confml.add_feature(api.Feature("testfea31"),"testfea3")
|
|
156 |
self.assertEquals(self.prj.test2_confml.list_all_features(), ['testfea1',
|
|
157 |
'testfea1.testfea11',
|
|
158 |
'testfea2',
|
|
159 |
'testfea3',
|
|
160 |
'testfea3.testfea31',
|
|
161 |
'testfea4'])
|
|
162 |
|
|
163 |
class TestProjectConfigurationsStorage(unittest.TestCase):
|
|
164 |
def test_create_configuration_and_store_storage(self):
|
|
165 |
prj = api.Project(api.Storage.open("temp/testproject.pk", "w"))
|
|
166 |
prj.create_configuration("test.confml")
|
|
167 |
prj.close()
|
|
168 |
self.assertTrue(os.path.exists("temp/testproject.pk"))
|
|
169 |
shutil.rmtree("temp")
|
|
170 |
|
|
171 |
def test_create_configuration_and_store_storage_and_open(self):
|
|
172 |
prj = api.Project(api.Storage.open("temp/testproject1.pk","w"))
|
|
173 |
config = prj.create_configuration("test.confml")
|
|
174 |
config.desc = "Descriptions"
|
|
175 |
prj.save()
|
|
176 |
prj.close()
|
|
177 |
|
|
178 |
prj2 = api.Project(api.Storage.open("temp/testproject1.pk"))
|
|
179 |
self.assertEquals(prj2.list_configurations(), ['test.confml'])
|
|
180 |
self.assertEquals(prj2.test_confml.desc, "Descriptions")
|
|
181 |
shutil.rmtree("temp")
|
|
182 |
|
|
183 |
def test_create_configuration_hierarchy_and_store_storage_and_open(self):
|
|
184 |
prj = api.Project(api.Storage.open("temp/testproject2.pk","w"))
|
|
185 |
config = prj.create_configuration("test.confml")
|
|
186 |
config.desc = "Descriptions"
|
|
187 |
prj.test_confml.create_configuration("s60/root.confml")
|
|
188 |
prj.test_confml.s60__root_confml.add_feature(api.Feature("feature1"))
|
|
189 |
prj.test_confml.create_configuration("ncp/root.confml")
|
|
190 |
prj.save()
|
|
191 |
prj.close()
|
|
192 |
|
|
193 |
prj2 = api.Project(api.Storage.open("temp/testproject2.pk"))
|
|
194 |
self.assertEquals(prj2.list_configurations(), ['test.confml'])
|
|
195 |
self.assertEquals(prj2.test_confml.desc, "Descriptions")
|
|
196 |
self.assertEquals(prj2.test_confml.list_all_features(),['feature1'])
|
|
197 |
prj2.close()
|
|
198 |
shutil.rmtree("temp")
|
|
199 |
|
|
200 |
def test_dump_configuration_with_include(self):
|
|
201 |
prj = api.Project(api.Storage.open("temp/testprojectinc.pk","w"))
|
|
202 |
config = prj.create_configuration("test.confml")
|
|
203 |
config.include_configuration("foo/foo.confml")
|
|
204 |
dumped = persistentdictionary.DictWriter().dumps(config)
|
|
205 |
children = dumped['Configuration']['children']
|
|
206 |
self.assertEquals(children,[{'ConfigurationProxy': {'dict': {'path': 'foo/foo.confml'}}}])
|
|
207 |
prj.close()
|
|
208 |
shutil.rmtree("temp")
|
|
209 |
|
|
210 |
def test_create_configuration_project_with_includes_and_reopen_storage(self):
|
|
211 |
prj = api.Project(api.Storage.open("temp/testprojectinc2.pk","w"))
|
|
212 |
config = prj.create_configuration("test.confml")
|
|
213 |
config.desc = "Descriptions"
|
|
214 |
config2 = config.create_configuration("foo/foo.confml")
|
|
215 |
config2.add_feature(api.Feature("feature1"))
|
|
216 |
config2.save()
|
|
217 |
config2.close()
|
|
218 |
prj.test_confml.include_configuration("foo/foo.confml")
|
|
219 |
prj.save()
|
|
220 |
prj.close()
|
|
221 |
|
|
222 |
prj2 = api.Project(api.Storage.open("temp/testprojectinc2.pk"))
|
|
223 |
self.assertEquals(prj2.list_configurations(), ['test.confml'])
|
|
224 |
self.assertEquals(prj2.test_confml.list_configurations(), ['foo/foo.confml'])
|
|
225 |
foo = prj2.test_confml.get_configuration('foo/foo.confml')
|
|
226 |
self.assertEquals(prj2.get_configuration('test.confml').list_all_features(), ['feature1'])
|
|
227 |
self.assertEquals(prj2.test_confml.get_default_view().list_features(), ['feature1'])
|
|
228 |
prj2.close()
|
|
229 |
shutil.rmtree("temp")
|
|
230 |
|
|
231 |
def test_create_configuration_project_with_multiincludes_and_reopen_storage(self):
|
|
232 |
prj = api.Project(api.Storage.open("temp/testprojectinc3.pk","w"))
|
|
233 |
config = prj.create_configuration("test.confml")
|
|
234 |
prj.add_configuration(api.Configuration("s60/root.confml", namespace="com.nokia.s60"))
|
|
235 |
prj.create_configuration("foo/foo.confml")
|
|
236 |
prj.test_confml.include_configuration("foo/foo.confml")
|
|
237 |
prj.test_confml.include_configuration("s60/root.confml")
|
|
238 |
foofea = api.Feature("foofea")
|
|
239 |
foofea.add_feature(api.Feature("foofea_setting1"))
|
|
240 |
foofea.add_feature(api.Feature("foofea_setting2"))
|
|
241 |
prj.test_confml.foo__foo_confml.add_feature(foofea)
|
|
242 |
|
|
243 |
s60fea = api.Feature("s60fea")
|
|
244 |
s60fea.add_feature(api.Feature("wlanset1"))
|
|
245 |
s60fea.add_feature(api.Feature("wlan_set2"))
|
|
246 |
prj.test_confml.s60__root_confml.add_feature(s60fea)
|
|
247 |
dview = prj.test_confml.get_default_view()
|
|
248 |
prj.save()
|
|
249 |
|
|
250 |
prj2 = api.Project(api.Storage.open("temp/testprojectinc3.pk"))
|
|
251 |
self.assertEquals(prj2.list_configurations(), ['test.confml'])
|
|
252 |
|
|
253 |
dview2 = prj2.test_confml.get_default_view()
|
|
254 |
self.assertEquals(dview.list_all_features(),
|
|
255 |
dview2.list_all_features())
|
|
256 |
testconf = prj2.get_configuration('test.confml')
|
|
257 |
my_view = testconf.get_default_view()
|
|
258 |
my_view.com.nokia.s60.s60fea.wlanset1.data = 1
|
|
259 |
prj2.close()
|
|
260 |
shutil.rmtree("temp")
|
|
261 |
|
|
262 |
def test_create_configuration_project_with_multiincludes_and_test_layer_actions(self):
|
|
263 |
prj = api.Project(api.Storage.open("temp/testprojectlayers.pk","w"))
|
|
264 |
config = prj.create_configuration("test.confml")
|
|
265 |
prj.add_configuration(api.Configuration("s60/root.confml", namespace="com.nokia.s60"))
|
|
266 |
prj.create_configuration("foo/foo.confml")
|
|
267 |
prj.create_configuration("foo/confml/component.confml").close()
|
|
268 |
prj.test_confml.include_configuration("foo/foo.confml")
|
|
269 |
prj.test_confml.include_configuration("s60/root.confml")
|
|
270 |
prj.test_confml.foo__foo_confml.create_configuration("data.confml")
|
3
|
271 |
prj.test_confml.foo__foo_confml.add_configuration(api.Configuration("confml/test.confml"))
|
0
|
272 |
foofea = api.Feature("foofea")
|
|
273 |
foofea.add_feature(api.Feature("foofea_setting1"))
|
|
274 |
foofea.add_feature(api.Feature("foofea_setting2"))
|
|
275 |
prj.test_confml.foo__foo_confml.add_feature(foofea)
|
|
276 |
prj.save()
|
|
277 |
foo_config = prj.test_confml.get_configuration("foo/foo.confml")
|
|
278 |
layer = foo_config.get_layer()
|
|
279 |
res = layer.open_resource("confml/component1.confml","w")
|
|
280 |
res.write("foo.conf")
|
|
281 |
res.close()
|
|
282 |
res = layer.content_folder().open_resource("foobar.txt","w")
|
|
283 |
res.write("foo bar")
|
|
284 |
res.close()
|
3
|
285 |
self.assertEquals(layer.list_confml(), ['confml/component.confml', 'confml/component1.confml', 'confml/test.confml'])
|
0
|
286 |
self.assertEquals(layer.list_content(), ['content/foobar.txt'])
|
3
|
287 |
self.assertEquals(layer.list_all_resources(), ['confml/component.confml', 'confml/component1.confml', 'confml/test.confml', 'content/foobar.txt'])
|
|
288 |
self.assertEquals(foo_config.list_resources(), ['foo/foo.confml',
|
|
289 |
'foo/data.confml',
|
|
290 |
'foo/confml/test.confml',
|
|
291 |
'foo/confml/component.confml',
|
|
292 |
'foo/confml/component1.confml',
|
|
293 |
'foo/content/foobar.txt'])
|
0
|
294 |
self.assertEquals(prj.test_confml.list_resources(), ['test.confml',
|
|
295 |
'foo/foo.confml',
|
|
296 |
'foo/data.confml',
|
3
|
297 |
'foo/confml/test.confml',
|
0
|
298 |
's60/root.confml',
|
|
299 |
'foo/confml/component.confml',
|
|
300 |
'foo/confml/component1.confml',
|
|
301 |
'foo/content/foobar.txt'])
|
|
302 |
|
|
303 |
|
|
304 |
s60_config = prj.test_confml.get_configuration("s60/root.confml")
|
|
305 |
layer = s60_config.get_layer()
|
|
306 |
res = layer.open_resource("confml/component1.confml","w")
|
|
307 |
res.write("foo.conf")
|
|
308 |
res.close()
|
|
309 |
res = layer.content_folder().open_resource("s60.txt","w")
|
|
310 |
res.write("foo bar")
|
|
311 |
res.close()
|
|
312 |
res = layer.content_folder().open_resource("foobar.txt","w")
|
|
313 |
res.write("foo bar")
|
|
314 |
res.close()
|
|
315 |
self.assertEquals(layer.list_confml(), ['confml/component1.confml'])
|
|
316 |
self.assertEquals(layer.list_content(), ['content/foobar.txt', 'content/s60.txt'])
|
|
317 |
self.assertEquals(prj.test_confml.layered_content().list_keys(), ['foobar.txt', 's60.txt'])
|
|
318 |
self.assertEquals(prj.test_confml.layered_content().get_values('foobar.txt'), ['foo/content/foobar.txt', 's60/content/foobar.txt'])
|
|
319 |
prj.close()
|
|
320 |
shutil.rmtree("temp")
|
|
321 |
|
|
322 |
|
|
323 |
if __name__ == '__main__':
|
|
324 |
unittest.main()
|
|
325 |
|