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